Linux executes the official example of RocketMQ to test whether the cluster is easy to use

Let's start with the conclusion

Send message: 1000 messages will be sent by default

sh bin/ org.apache.rocketmq.example.quickstart.Producer

Receive message:

sh bin/ org.apache.rocketmq.example.quickstart.Consumer

The above two commands need to be executed in the installation directory of RocketMQ, and the environment variables need to be configured:

export NAMESRV_ADDR='zjj101:9876;zjj102:9876;zjj103:9876'

If you can do it, you don't need to look at the following. If you don't know much about it, look at the following and operate it yourself. If you don't build a cluster, refer to the following blog to build a RocketMQ cluster

Build rocketmq console visualization plug-in

If you have other visual plug-ins, you can skip here

Here's what windows built: look directly Blog, I won't demonstrate. It's very simple

View the cluster status through rocketmq console,

It is found that the cluster has been set up successfully

Execute the official example to test whether the cluster is easy to use


In the RocketMQ installation package, a tool is provided to quickly verify RocketMQ services on the command line. We are
Enter the installation directory of RocketMQ on zjj102:
Send message: 1000 messages will be sent by default

bin/ org.apache.rocketmq.example.quickstart.Producer 

Receive message:

bin/ org.apache.rocketmq.example.quickstart.Consumer 

Note that this is the official Demo, but in the official source code, these two classes do not specify nameServer, so
There will be some problems in operation. To specify the NameServer address, you can configure an environment variable NAMESRV_ADDR, this defaults to
The NameServer address will be read. Can be matched to. Bash_ Or directly and temporarily specified in the profile.

export NAMESRV_ADDR='zjj101:9876;zjj102:9876;zjj103:9876'

Then it can be executed normally.
See the source code for how to read the NameServer address

 public static String getNameServerAddresses() {
    return System.getProperty("rocketmq.namesrv.addr",

This method is the default way to set the NameServer address in DefaultMQProducer. This rokcetmq.namesrv.addr property can be specified in java using System.setproperties or configured in the configuration file in SpringBoot.

This encapsulates a simple environment for running RocketMQ. You can run other examples in the source code and then run them yourself
The example can also be executed in the lib directory of RocketMQ.

Start demonstration

Configure environment variables:

Modify / etc/profile file

export NAMESRV_ADDR='zjj101:9876;zjj102:9876;zjj103:9876'

After configuration, don't forget to execute source /etc/profile to make the environment variables take effect

Execute echo $NAMESRV_ADDR checks whether there is a problem with the configuration of environment variables. It can print "zjj101:9876;zjj102:9876;zjj103:9876", indicating that the configuration is OK

Let's start the demonstration: execute in the RocketMq installation directory: sh bin/ org.apache.rocketmq.example.quickstart.Producer

# Check whether the configured environment variables are effective
[root@zjj102 rocketmq-all-4.7.1-bin-release]# echo $NAMESRV_ADDR
# The instructions are in effect
# Execute official example
[root@zjj102 rocketmq-all-4.7.1-bin-release]# sh bin/ org.apache.rocketmq.example.quickstart.Producer
# Now start printing the log. The description takes effect
12:58:13.013 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
SendResult [sendStatus=SEND_OK, msgId=AC100A665F824DC63996552E3BCD0000, offsetMsgId=AC100A6600002A9F0000000000000000, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=1], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=AC100A665F824DC63996552E3BEB0001, offsetMsgId=AC100A6600002A9F00000000000000CB, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=2], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=AC100A665F824DC63996552E3BEF0002, offsetMsgId=AC100A6600002A9F0000000000000196, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=3], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=AC100A665F824DC63996552E3BF10003, offsetMsgId=AC100A6700002A9F0000000000000000, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-b, queueId=0], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=AC100A665F824DC63996552E3C0F0004, offsetMsgId=AC100A6700002A9F00000000000000CB, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-b, queueId=1], queueOffset=0]

Click refresh to view multiple topic tests, which are generated automatically by executing the official example

You open another terminal connection zjj102 and execute the following command to start the consumer

sh bin/ org.apache.rocketmq.example.quickstart.Consumer

You can start the example, production message and consumption message repeatedly

Click consumer management of TopicTest to view the consumption

The delay 1000 shown below means that 1000 items are not consumed. After you execute sh bin/ org.apache.rocketmq.example.quickstart.Consumer to start the official consumer example, you can see that the delay becomes less, indicating consumption

The following figure shows that they are consumed by this consumer. A delay of 0 indicates that there is no message backlog

Tags: Java Linux Windows RocketMQ

Posted on Sun, 17 Oct 2021 00:57:29 -0400 by mcfmullen