Start RocketMQ

Getting started is easy, just call the script in the bin directory. Just take a look at their JVM memory configuration before starting. The default configuration is high.

1. Start nameServer.

Modify bin/runserver.sh on the three nodes to adjust the JVM memory configuration. Go to the next line and adjust the memory

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
Copy the code

Start nameServer directly on the three nodes.

nohup bin/mqadminsrv &
Copy the code

When the startup is complete and you see this key log in nohup.out, the startup is successful.

Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release. The Name Server boot success. serializeType=JSON

Use the JPS directive to see a NamesrvStartup process.

It is also seen here that RocketMQ uses the CMS garbage collection period in runServer.sh and the G1 garbage collection period in runBroker.

2. Restart the broker

The MQBroker directive is used to start the broker, just note that the corresponding configuration file needs to be specified by -c when starting the broker.

Start the master node of broker -A and slave node of broker b on Worker2

nohup ./mqbroker -c .. /conf/2m-2s-async/broker-a.properties & nohup ./mqbroker -c .. /conf/2m-2s-async/broker-b-s.properties &Copy the code

Start the master node of broker- B and slave node of broker- A on work3

nohup ./mqbroker -c .. /conf/2m-2s-async/broker-b.properties & nohup ./mqbroker -c .. /conf/2m-2s-async/broker-a-s.properties &Copy the code

If the Lock failed,MQ already started error is reported during slave startup, this is because multiple instances share the same storePath. In this case, you need to adjust the store path.

3. Check the startup status

Using the JPS directive, you can see a NameSrvStartup process and two BrokerStartup processes.

The startup success log is also displayed in nohup.out.

The corresponding log file:

#View nameServer logs
tail -500f ~/logs/rocketmqlogs/namesrv.log
#Viewing broker Logs
tail -500f ~/logs/rocketmqlogs/broker.log
Copy the code

4. Test the MQadmin management tool

The RocketMQ source code does not give us a console like Nacos or RabbitMQ. It only provides an mqadmin directive to manage RocketMQ, which is in the bin directory. /mqadmin {command} {args}

All instructions are as follows:

The Topic related to:

The name of the meaning Command options instructions
updateTopic Create the update Topic configuration -b Broker address: indicates the Broker in which the topic resides. Only one Broker is supported. The address is IP :port
-c Cluster name, which indicates the cluster where the topic resides. (You can query the cluster by clusterList.)
-h- Print the help
-n NameServer service address in the format of IP :port
-p Specify the new topic of read and write access (W = 2 | | R = 4 WR = 6)
-r Number of readable queues (default: 8)
-w Number of writable queues (default: 8)
-t ^[a-za-z0-9_ -]+$^[a-za-z0-9_ -]+$
deleteTopic Delete the Topic -c Cluster name: deleting a topic from a cluster (You can query a cluster by clusterList)
-h Print the help
-n NameServer service address in the format of IP :port
-t ^[a-za-z0-9_ -]+$^[a-za-z0-9_ -]+$
topicList View the Topic list -h Print the help
-c If -c is not configured, only the topic list is returned. If -c is added, information about clusterName, topic, and consumerGroup is returned. That is, the cluster and subscription relationship of a topic are not specified
-n NameServer service address in the format of IP :port
topicRoute View Topic routing information -t The name of the topic
-h Print the help
-n NameServer service address in the format of IP :port
topicStatus View the Topic message queue offset -t The name of the topic
-h Print the help
-n NameServer service address in the format of IP :port
topicClusterList View the Topic cluster list -t The name of the topic
-h Print the help
-n NameServer service address in the format of IP :port
updateTopicPerm Update Topic read and write permissions -t The name of the topic
-h Print the help
-n NameServer service address in the format of IP :port
-b Broker address: indicates the Broker in which the topic resides. Only one Broker is supported. The address is IP :port
-p Specify the new topic of read and write access (W = 2 | | R = 4 WR = 6)
-c Cluster name: indicates the cluster where the topic resides (you can query the cluster through clusterList). -b is preferred. If -b is not available, commands are executed for all brokers in the cluster
updateOrderConf Creating, deleting, and obtaining namespace-specific kV configurations from NameServer is not currently enabled -h Print the help
-n NameServer service address in the format of IP :port
-t The topic, the key
-v OrderConf, value
-m Method can be GET, PUT, or DELETE
allocateMQ The load results of the consumer list load message queue are calculated using the load averaging algorithm -t The name of the topic
-h Print the help
-n NameServer service address in the format of IP :port
-i The ipList, separated by commas, calculates the message queues for these IP unloaded topics
statsAll Print the Topic subscription relationship, TPS, accumulative amount, 24h read and write total amount, and other information -h Print the help
-n NameServer service address in the format of IP :port
-a Whether to print only active topics
-t Specify the topic

The cluster related

The name of the meaning Command options instructions
clusterList View cluster information, such as cluster, BrokerName, BrokerId, and TPS -m #InTotalYest, #OutTotalYest, #InTotalToday,#OutTotalToday
-h Print the help
-n NameServer service address in the format of IP :port
-i Print interval, in seconds
clusterRT Send messages to detect the cluster Broker RT. Message is sent to ${BrokerName} Topic. -a Amount, total number of probes per probe, RT = total time/amount
-s Message size, unit B
-c Which cluster to probe
-p Print format log to | segmentation, not print by default
-h Print the help
-m Belongs to the equipment room, printing use
-i Send interval, in seconds
-n NameServer service address in the format of IP :port

The Broker related

The name of the meaning Command options instructions
updateBrokerConfig Updating the Broker configuration file modifies the Broker -b Broker address in the format of IP :port
-c The name of the cluster
-k The key value
-v The value value
-h Print the help
-n NameServer service address in the format of IP :port
brokerStatus View Broker statistics, health status (almost everything you want is there) -b Broker address: IP :port
-h Print the help
-n NameServer service address in the format of IP :port
brokerConsumeStats Consumption of each consumer in the Broker. Consume Offset, Broker Offset, Diff, TImestamp and other information are returned according to Message Queue dimension -b Broker address: IP :port
-t Request timeout
-l Diff Indicates the threshold. The value is printed only when the threshold is exceeded
-o Whether it is an order topic, usually false
-h Print the help
-n NameServer service address in the format of IP :port
getBrokerConfig Getting Broker configuration -b Broker address: IP :port
-n NameServer service address in the format of IP :port
wipeWritePerm Clear Broker write permission from NameServer -b Broker address: IP :port
-n NameServer service address in the format of IP :port
-h Print the help
cleanExpiredCQ Clear the expired Consume Queue on the Broker. Manually reducing the number of columns may result in an expired Queue -n NameServer service address in the format of IP :port
-h Print the help
-b Broker address: IP :port
-c The name of the cluster
cleanUnusedTopic Clean up the unused topics on the Broker and free the Consume Queue from memory. Manually deleting a Topic would produce unused topics -n NameServer service address in the format of IP :port
-h Print the help
-b Broker address: IP :port
-c The name of the cluster
sendMsgStatus Sends a message to the Broker, returning the send status and RT -n NameServer service address in the format of IP :port
-h Print the help
-b BrokerName, note that it is different from the Broker address
-s Message size, unit B
-c Send the number

News related to

The name of the meaning Command options instructions
queryMsgById If you are using an open source console, you should use offsetMsgId. This command has other parameters. For details, see QueryMsgByIdSubCommand. -i msgId
-h Print the help
-n NameServer service address in the format of IP :port
queryMsgByKey Query messages based on message keys -k msgKey
-t The name of the Topic
-h Print the help
-n NameServer service address in the format of IP :port
queryMsgByOffset Query the message by Offset -b Name of the Broker (please note that this is the name of the Broker, not the address of the Broker. The name of the Broker can be found in the clusterList)
-i Query queue id
-o Offset value
-t The name of the topic
-h Print the help
-n NameServer service address in the format of IP :port
queryMsgByUniqueKey According to the msgId query, the msgId is different from the offsetMsgId. For details, see Common Operation and maintenance issues. -g and -d are used together to try to get a specific consumer to consume the message and return the consumption result -h Print the help
-n NameServer service address in the format of IP :port
-i uniqe msg id
-g consumerGroup
-d clientId
-t The name of the topic
checkMsgSendRT Detects the RT that sends messages to a topic. The function is similar to clusterRT -h Print the help
-n NameServer service address in the format of IP :port
-t The name of the topic
-a Number of detection
-s Message size
sendMessage Send a Message, either to a specific Message Queue or to a general Message Queue, depending on the configuration. -h Print the help
-n NameServer service address in the format of IP :port
-t The name of the topic
-p Body, message body
-k keys
-c tags
-b BrokerName
-i queueId
consumeMessage Consume messages. You can perform different consumption logic with different configurations based on offset, start and end timestamps, and message queue consumption. See ConsumeMessageCommand. -h Print the help
-n NameServer service address in the format of IP :port
-t The name of the topic
-b BrokerName
-o The consumption starts at offset
-i queueId
-g Consumer Group
-s Start time stamp. See -h for the format
-d End timestamp
-c How many messages to consume
printMsg Consume messages from the Broker and print them, optionally for a period of time -h Print the help
-n NameServer service address in the format of IP :port
-t The name of the topic
-c Character set, such as UTF-8
-s SubExpress, filter expressions
-b Start timestamp. See -h for the format
-e End timestamp
-d Whether to print the message body
printMsgByQueue Similar to printMsg, but specifying a Message Queue -h Print the help
-n NameServer service address in the format of IP :port
-t The name of the topic
-i queueId
-a BrokerName
-c Character set, such as UTF-8
-s SubExpress, filter expressions
-b Start timestamp. See -h for the format
-e End timestamp
-p Print message or not
-d Whether to print the message body
-f Whether to count the number of tags and print them
resetOffsetByTime To reset the offset with the timestamp, both the Broker and the consumer are reset -h Print the help
-n NameServer service address in the format of IP :port
-g Consumer Group
-t The name of the topic
-s Reset the offset corresponding to this timestamp
-f Whether to force reset. If false, only backtracking offset is supported. If true, the timestamp corresponds to offset and consumeOffset regardless
-c Whether to reset the c++ client offset

Consumers are related to consumer groups

The name of the meaning Command options instructions
consumerProgress By viewing the subscription group consumption status, you can view the message accumulation volume of specific client IP addresses -g Name of the group to which the consumer belongs
-s Whether to print the CLIENT IP address
-h Print the help
-n NameServer service address in the format of IP :port
consumerStatus Check the consumer status, including whether there are all the same subscriptions in the same group, analyze whether the Process Queue is stacked, and return the consumer jStack. See ConsumerStatusSubCommand for more -h Print the help
-n NameServer service address in the format of IP :port
-g consumer group
-i clientId
-s Whether to execute jstack
getConsumerStatus Get the Consumer’s progress -g Name of the group to which the consumer belongs
-t Query subject
-i Consumer IP address of the client
-n NameServer service address in the format of IP :port
-h Print the help
updateSubGroup Update or create a subscription relationship -n NameServer service address in the format of IP :port
-h Print the help
-b The Broker address
-c The name of the cluster
-g Consumer Group Name
-s Whether the group is allowed to consume
-m Whether to start consumption from the minimum offset
-d Broadcast mode or not
-q Retry queue number
-r Maximum retry times
-i When slaveReadEnable is enabled and slave consumption is not reached, BrokerId is recommended for slave consumption. You can configure the slave machine ID to actively slave slave consumption
-w If the Broker recommends consuming from a slave, the configuration determines which slave to consume from. BrokerId is configured, such as 1
-a Whether to notify other consumer load balancers when the number of consumers changes
deleteSubGroup Delete the subscription relationship from the Broker -n NameServer service address in the format of IP :port
-h Print the help
-b The Broker address
-c The name of the cluster
-g Consumer Group Name
cloneGroupOffset The offset of the source group is used in the target group -n NameServer service address in the format of IP :port
-h Print the help
-s Source Consumer Group
-d Target Consumer Group
-t The name of the topic
-o Temporary unused

Connect related

The name of the meaning Command options instructions
consumerConnec tion Example Query a Consumer’s network connection -g Name of the group to which the consumer belongs
-n NameServer service address in the format of IP :port
-h Print the help
producerConnec tion Example Query the network connection of Producer -g Name of the group to which the producer belongs
-t The topic name
-n NameServer service address in the format of IP :port
-h Print the help

NameServer related

The name of the meaning Command options instructions
updateKvConfig Update NameServer kv configuration, currently not in use -s The namespace
-k key
-v value
-n NameServer service address in the format of IP :port
-h Print the help
deleteKvConfig Example Delete the kV configuration of NameServer -s The namespace
-k key
-n NameServer service address in the format of IP :port
-h Print the help
getNamesrvConfig Obtain the NameServer configuration -n NameServer service address in the format of IP :port
-h Print the help
updateNamesrvConfig Example Modify the NameServer configuration -n NameServer service address in the format of IP :port
-h Print the help
-k key
-v value

other

The name of the meaning Command options instructions
startMonitoring Start the monitoring process to monitor the number of deleted messages and messages in the retry queue -n NameServer service address in the format of IP :port
-h Print the help

Note:

1. Almost all directives need to use the -n parameter to set the nameServer address in the format of IP :port

2. Almost any execution can be helped by the -h argument

3. When both the Broker address (-b) and the clusterName (-c) are available, the Broker address is preferred. If no Broker address is configured, the instructions are executed on all hosts in the cluster.

5, command line quick verification

In the RocketMQ installation package, there is a tools.sh tool that can be used to quickly verify the RocketMQ service on the command line. We go to the RocketMQ installation directory on Worker2:

Send messages: By default, 1000 messages are sent

bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
Copy the code

Receive message:

bin/tools.sh  org.apache.rocketmq.example.quickstart.Consumer
Copy the code

Note that this is an official Demo, but the official source code, these two classes are not nameServer specified, so running a bit of a problem. To specify the NameServer address, you can configure an environment variable, NAMESRV_ADDR, so that the NameServer address is read by default. This can be assigned to.bash_profile or temporarily specified.

export NAMESRV_ADDR='worker1:9876; worker2:9876; worker3:9876'Copy the code

Then you can execute normally.

The NameServer address read way to see the source code of org.apache.rocketmq.com mon. Utils. NameServerAddressUtils

    public static String getNameServerAddresses(a) {
        return System.getProperty("rocketmq.namesrv.addr", System.getenv("NAMESRV_ADDR"));
    }
Copy the code

This is the default way to set the NameServer address in DefaultMQProducer. The rokcetMQ.namesrv. Addr property can be specified in Java using System.setProperties. It can also be added to a configuration file in SpringBoot.

This tools.sh encapsulates a simple environment for running RocketMQ. You can run other examples in the source code, and then put your own examples in the RocketMQ lib directory.