Backend Development 8 min read

Introduction to RocketMQ and Building a Cross‑Language Tool for Simulating Message Production

This article introduces RocketMQ, explains its architecture and core components, and guides readers through creating and sending test messages using Java code and a Python‑JPype approach, ultimately proposing a simple web‑based tool for cross‑language message simulation.

转转QA
转转QA
转转QA
Introduction to RocketMQ and Building a Cross‑Language Tool for Simulating Message Production

Author: Zhao Lixin. The article begins with a friendly note encouraging readers to think about problem‑solving approaches in their work.

RocketMQ is an open‑source distributed messaging and streaming platform contributed by Alibaba to the Apache foundation.

As company scale and business volume grow exponentially, traditional synchronous RPC faces performance, robustness, and scalability issues; asynchronous messaging models like RocketMQ become essential, offering advantages such as no message loss, high availability, and high throughput.

The overall architecture is illustrated below:

The system consists of three main modules:

namesrv – a stateless service discovery component that stores broker addresses; producers and consumers query it to locate brokers, and brokers send heartbeats to it.

broker – a high‑performance, low‑latency storage component responsible for persisting all message‑related files.

producer & consumer – the API exposed to developers; producers create messages, consumers retrieve and process them.

Application background : In testing scenarios, downstream consumers often need to receive a specific RocketMQ message (e.g., order status change) before a workflow can be triggered. To avoid creating unrelated test data, a lightweight tool for simulating message production is required.

Thought 1 – What does an MQ message contain? An MQ message includes:

Topic – categorizes the business logic of the message.

Tag – further refines the topic for different uses within the same module.

Body – the payload of the message.

Keys – optional identifiers for storage and lookup.

Thought 2 – How to produce a message? The Java client library is used. A concise code example is shown in the image below.

Thought 3 – Designing a user‑friendly tool suggests providing a simple web interface where users input Topic, Tag, and Body and click a button to send the message. The backend can be implemented in Java, extracting parameters from the request and invoking the same code shown above.

Thought 4 – Can Python produce RocketMQ messages? Yes. By using JPype, Python can start a JVM, import the Java classes from the RocketMQ client JAR, and invoke the same APIs.

Typical steps are:

Start the JVM with startJVM() and include the required JAR paths.

Import Java packages via JPackage , e.g., DefaultMQProducer , Message , SendResult , SendStatus , and MQClientException .

Instantiate and start the producer.

Create a Message instance with the desired Topic, Tag, and Body.

Send the message using producer.send() .

Shutdown the producer with producer.shutdown() and the JVM with shutdownJVM() .

DefaultMQProducer = JPackage('com.alibaba.rocketmq.client.producer').DefaultMQProducer
MQClientException = JPackage('com.alibaba.rocketmq.client.exception').MQClientException
SendResult = JPackage('com.alibaba.rocketmq.client.producer').SendResult
Message = JPackage('com.alibaba.rocketmq.common.message').Message
SendStatus = JPackage('com.alibaba.rocketmq.client.producer').SendStatus
# ... instantiate producer, start, create Message, send, shutdown ...

These steps demonstrate that producing a message in Python follows the same logic as in Java, illustrating how JPype can bridge Python and Java for other similar use cases.

In conclusion, building a simple tool to send RocketMQ messages is straightforward, and developers are encouraged to search for existing solutions and think critically about the next steps.

distributed systemsJavaPythonmessage queueRocketMQJPype
转转QA
Written by

转转QA

In the era of knowledge sharing, discover 转转QA from a new perspective.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.