Modify ROCKETMQ Official Code test:
PackageCOM.ALIBABA.MIDDLEWARE.RACE.ROCKETMQ;ImportJava.util.Scanner;Importcom.alibaba.rocketmq.client.exception.MQClientException;ImportCom.alibaba.rocketmq.client.producer.DefaultMQProducer;ImportCom.alibaba.rocketmq.client.producer.SendCallback;ImportCom.alibaba.rocketmq.client.producer.SendResult;ImportCom.alibaba.rocketmq.common.message.Message;Importcom.alibaba.rocketmq.remoting.exception.RemotingException;/*** Producer, simulate possible problems with rocket MQ usage, learn how to troubleshoot Q issues*/ Public classProducer { Public Static voidMain (string[] args)throwsmqclientexception, Interruptedexception, remotingexception {defaultmqproducer producer=NewDefaultmqproducer ("Procedure_group_name"); PRODUCER.SETNAMESRVADDR ("127.0.0.1:9876"); Producer.start (); FinalString topics = "Topic-it-worker-test"; for(inti = 0; i < 1000; i++) {@SuppressWarnings ("Resource") Scanner Reader=NewScanner (system.in); intKey =Reader.nextint (); FinalString message = "Order-message-" + i + "key:" +key; byte[] BODY =message.getbytes (); Message Msgtobroker=NewMessage (topics, "Tag-push", String.valueof (key), body); Producer.send (Msgtobroker,NewSendcallback () { Public voidonsuccess (Sendresult sendresult) {System.out.println (message); } Public voidonexception (Throwable throwable) {throwable.printstacktrace (); } }); } }}
PackageCOM.ALIBABA.MIDDLEWARE.RACE.ROCKETMQ;ImportCom.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;ImportCom.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;ImportCom.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;Importcom.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;Importcom.alibaba.rocketmq.client.exception.MQClientException;ImportCom.alibaba.rocketmq.common.consumer.ConsumeFromWhere;Importcom.alibaba.rocketmq.common.message.MessageExt;Importjava.util.List;ImportJava.util.Scanner; Public classConsumer { Public Static voidMain (string[] args)throwsinterruptedexception, mqclientexception {defaultmqpushconsumer consumer=NewDefaultmqpushconsumer ("Consumer_group_name"); Consumer.setconsumefromwhere (Consumefromwhere.consume_from_first_offset); CONSUMER.SETNAMESRVADDR ("127.0.0.1:9876"); Consumer.subscribe ("Topic-it-worker-test", "*"); Consumer.registermessagelistener (Newmessagelistenerconcurrently () {@Override PublicConsumeconcurrentlystatus Consumemessage (list<messageext>msgs, Consumeconcurrentlycontext context) { for(Messageext msg:msgs) {Scanner reader=NewScanner (system.in); Reader.hasnext (); byte[] BODY =Msg.getbody (); if(Body.length = = 2 && body[0] = = 0 && body[1] = = 0) {System.out.println ("Got The End Signal"); Continue; } String paymentmessage=NewString (body); System.out.println (Paymentmessage+ "key:" + Msg.getkeys () + "tag:" +msg.gettags ()); Try{Thread.Sleep (3000); } Catch(interruptedexception e) {e.printstacktrace (); } } returnconsumeconcurrentlystatus.consume_success; } }); Consumer.start (); System.out.println ("Consumer Started."); }}
<?xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelversion>4.0.0 </modelVersion> <groupId>com.alibaba.race</groupId> <artifactid>preliminary.demo</ artifactid> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugi N> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-compil Er-plugin</artifactid> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>m Aven-assembly-plugin</artifactid> <version>2.5.3</version> <configurati On> <appendasseMblyid> false </appendAssemblyId> <descriptors> <DESCRIPTOR>SRC/MAIN/RESOURC Es/assembly.xml</descriptor> </descriptors> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorrefs& Gt </configuration> <executions> <execution> <i D>make-assembly</id> <phase>install</phase> <GOALS&G T <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build><!--com.alibaba.middleware The. race.jstorm-2.1.1 version of the default log frame is Logback, in order to avoid log conflicts, exclude log4j--> <dependencies> <dePendency> <groupId>com.alibaba.rocketmq</groupId> <ARTIFACTID>ROCKETMQ-CLIENT&L t;/artifactid> <version>3.2.6</version> </dependency> </dependencies></ Project>
-DROCKETMQ.NAMESRV.ADDR=127.0.0.1:9876-CP preliminary.demo-1.0--drocketmq.namesrv.addr=127.0.0.1:9876- CP Preliminary.demo-1.0-snapshot.jar Com.alibaba.middleware.race.rocketmq.Consumer
Startup & Parameter Modification
Mqnamesrv start nameserver JPS- namesrvstartupmqbroker-n localhost:9876 start broker JPS- Brokerstartup default port 10911mqadmin updatebrokerconfig-c defaultcluster-n 127.0.0.1:9876-k listenport-v 10911 Update broke R parameter Configuration
View current system Status
Mqadmin Clusterlist-n 127.0.0.1:9876
View all current Topiclist
Mqadmin Topiclist-n 127.0.0.1:9876
View broker Status
Mqadmin brokerstatus-n 127.0.0.1:9876-b 127.0.0.1:10911
View the status of a topic
Mqadmin topicstatus-n 127.0.0.1:9876-t Topic-it-worker-test
Currently visible, producer only sends a message, Max offset is 1, and the last time the message is received is updated, since the configuration of four brokers is native, only the first one received the current first message
The second picture is the state after sending four messages, which may look like polling, because when I add 4 key to 1 msg, it is still four nodes each two bar
View the Procedure/consumer of a connection
Mqadmin producerconnection-n 127.0.0.1:9876-g procedure_group_name-t topic-it-worker--N 127.0.0.1:9876-g Consumer_group_name
View msg for a key
Mqadmin querymsgbykey-n 127.0.0.1:9876-t topic-it-worker-test-1-K 1
Because we sent 5 key 1 data, we can see 5, each with a message ID.
View the corresponding MSG according to the ID
Mqadmin Querymsgbyid- g consumer_group_name-i ac1f78b700002a9f00000000000a3208- n 127.0.0.1:9876
Query the above data based on the position offset
Mqadmin querymsgbyoffset-n 127.0.0.1:9876-o 1-t topic-it-worker-test-1-I 1-b Izm5e210z0uiwyavdbmpxaz
View consumption details
Mqadmin consumerprogress-n 127.0.0.1:9876-g Consumer_group_name
Here to consume a, altogether eight, poor 7 no consumption
Reset Consumer Offset
Mqadmin resetoffsetbytime true -S 1536820000
Print messages directly
Mqadmin printmsg-t topic-it-worker-test-1-N 127.0.0.1:9876
The most commonly used mqadmin commands are:updatetopic Update or create topic Deletetopic Dele Te topic from broker and NameServer. Updatesubgroup Update or create subscription group Deletesubgroup Delete subscription group from broker. Updatebrokerconfig Update Broker' s configupdatetopicperm Update topic perm Topicroute Examine topic route info Topicstatus Exami NE topic Status Info topicclusterlist get cluster info fortopic Brokerstatus Fetch Broker Runtime status data Querymsgbyid Query Message by Id Querymsgby Key Query message by Key querymsgbyuniquekey Query message by Unique key querymsgbyoffset query message by Offset Querymsgbyuniquekey Query message by Unique key printmsg Print message Detail printmsgbyqueue Print Message Detail sendmsgstatus send msg to broker. Brokerconsumestats Fetch broker consume stats data producerconnection Query producer' s socket connection and client version consumerconnection Query consumer ' s socket connection, client version and Subs Cription consumerprogress Query Consumers ' s progress, speed consumerstatus query consumer ' s internal Data st Ructure Clonegroupoffset clone offset from the other group. Clusterlist list all the clusters topiclist Fetch all topic List from name server Updatekvconfig Create or update KV CONFIG. Deletekvconfig Delete KV config. Wipewriteperm Wipe write perm of broker in all name servers Resetoffsetbytime Reset consumer offset by Timestam P (without client restart). updateorderconf Create or UPDATE or delete order conf CLEANEXPIREDCQ clean expired consumequeue on broker. Cleanunusedtopic clean unused topic on broker. startmonitoring Start monitoring Statsall Topic and Consumer TPS stats ALLOCATEMQ Allocate MQ CHECKMSGSENDRT Check message send response time CLUSTERRT List all clusters message send RT GETN Amesrvconfig Get configs of name server. Updatenamesrvconfig Update configs of name server. Getbrokerconfig Get Broker config by cluster or special broker!querycq Query CQ command.
Rocket MQ Troubleshooting Commands