RocketMQ在windows上安装和开发使用

1.概述


RocketMQ是什么? 
RocketMQ是一款分布式、队列模型的消息中间件,具有以下特点: 
能够保证严格的消息顺序 
提供丰富的消息拉取模式 
高效的订阅者水平扩展能力 
实时的消息订阅机制 
亿级消息堆积能力 
RocketMQ是alibaba开源的java消息中间件。在github上开源,项目同时也在oschina上。



2.开发测试环境搭建

1.   安装&启动

进入到RocketMQ下载包解压的路径下

D:\machine\RocketMQ-3.0.8\RocketMQ-3.0.8>

接下来安装

执行下边的命令或者执行install.bat(在这个bat文件中的命令如下)对maven熟悉的一眼就知道是执行clean package install assembly等操作。

mvn -Dmaven.test.skip=true clean packageinstall assembly:assembly –U

 

操作信息如下:

[html]  view plain copy
  1. [INFO] Scanning for projects...  
  2. [INFO] ------------------------------------------------------------------------  
  3. [INFO] Reactor Build Order:  
  4. [INFO]  
  5. [INFO] rocketmq-all 3.0.8  
  6. [INFO] rocketmq-remoting 3.0.8  
  7. [INFO] rocketmq-common 3.0.8  
  8. [INFO] rocketmq-client 3.0.8  
  9. [INFO] rocketmq-store 3.0.8  
  10. [INFO] rocketmq-broker 3.0.8  
  11. [INFO] rocketmq-tools 3.0.8  
  12. [INFO] rocketmq-research 3.0.8  
  13. [INFO] rocketmq-namesrv 3.0.8  
  14. [INFO] rocketmq-example 3.0.8  
  15. [INFO] rocketmq-qatest 3.0.8  
  16. [INFO]                                                                          
  17. [INFO] ------------------------------------------------------------------------  
  18. [INFO] Building rocketmq-all 3.0.8 3.0.8  
  19. [INFO]------------------------------------------------------------------------  
  20. [INFO]///省了…..编译打包过程  
  21. [INFO]------------------------------------------------------------------------  
  22. [INFO] Reactor Summary:  
  23. [INFO]  
  24. [INFO] rocketmq-all 3.0.8................................ SUCCESS [5.861s]  
  25. [INFO] rocketmq-remoting 3.0.8 ...........................SUCCESS [1.483s]  
  26. [INFO] rocketmq-common 3.0.8............................. SUCCESS [1.627s]  
  27. [INFO] rocketmq-client 3.0.8............................. SUCCESS [1.486s]  
  28. [INFO] rocketmq-store 3.0.8.............................. SUCCESS [1.398s]  
  29. [INFO] rocketmq-broker 3.0.8............................. SUCCESS [1.512s]  
  30. [INFO] rocketmq-tools 3.0.8.............................. SUCCESS [1.125s]  
  31. [INFO] rocketmq-research 3.0.8........................... SUCCESS [0.917s]  
  32. [INFO] rocketmq-namesrv 3.0.8............................ SUCCESS [0.609s]  
  33. [INFO] rocketmq-example 3.0.8............................ SUCCESS [0.604s]  
  34. [INFO] rocketmq-qatest 3.0.8............................. SUCCESS [0.057s]  
  35. [INFO] ------------------------------------------------------------------------  
  36. [INFO] BUILD SUCCESS  
  37. [INFO]------------------------------------------------------------------------  
  38. [INFO] Total time: 18.145s  
  39. [INFO] Finished at: Fri Mar 28 10:36:08 CST2014  
  40. [INFO] Final Memory: 60M/395M  
  41. [INFO]------------------------------------------------------------------------  
  42. D:\machine\RocketMQ-3.0.8\RocketMQ-3.0.8>  


 

 

 

 

 

接下来把编译好的项目copy出来

[html]  view plain copy
  1. D:\machine\RocketMQ-3.0.8\RocketMQ-3.0.8\target> xcopy /E alibaba-rocketmq-3.0.8  D:\machine\RocketMQ-3.0.8\  
  2. D:\machine\RocketMQ-3.0.8>dir  
  3.  驱动器 D 中的卷是 软件  
  4.  卷的序列号是000F-1D4F  
  5.    
  6.  D:\machine\RocketMQ-3.0.8 的目录  
  7.    
  8. 2014/03/28 10:44    <DIR>          .  
  9. 2014/03/28 10:44    <DIR>          ..  
  10. 2014/03/28 10:44    <DIR>          alibaba-rocketmq  
  11. 2014/03/07 15:08                52pax_global_header  
  12. 2014/03/28 10:37    <DIR>          RocketMQ-3.0.8  
  13.                1 个文件             52 字节  
  14.                4 个目录 105,101,885,440 可用字节  
  15.    
  16. D:\machine\RocketMQ-3.0.8>cd alibaba-rocketmq  




启动服务

//启动mqnamesrv

[html]  view plain copy
  1. D:\machine\RocketMQ-3.0.8\alibaba-rocketmq>start/b bin/mqnamesrv.exe  >D:\logs\alibaba-rocketmq/mqnamesrv.log  


可以通过jps查看一下是不是有了RocketMQ的进程,如下方的6484

[html]  view plain copy
  1. C:\Users\houchangren>jps -v  
  2. 6484 -Djava.ext.dirs=D:\machine\RocketMQ-3.0.8\alibaba-rocketmq\bin/../lib-Drocketmq.home.dir=D:\machine\RocketMQ-3.0.8\alibaba-rocketmq\bin/..-XX:MaxNewSize=512M -XX:MaxPermSize=128M -XX:NewSit abort  
  3. 6876 JConsole -Denv.class.path=D:\ProgramFiles\Java\jdk1.6.0_26\lib -Dapplication.home=D:\Program Files\Java\jdk1.6.0_26-Djconsole.showOutputViewer  
  4. 6936org.eclipse.equinox.launcher_1.2.0.v20110502.jar -Dosgi.requiredJavaVersion=1.5-Xms40m -Xmx512m -XX:MaxPermSize=256m  
  5. 4140 Jps -Denv.class.path=D:\ProgramFiles\Java\jdk1.6.0_26\lib -Dapplication.home=D:\Program Files\Java\jdk1.6.0_26-Xms8m  


 

看日志中信息D:\logs\alibaba-rocketmq/mqnamesrv.log

The Name Server boot success.

 

//启动broker

[html]  view plain copy
  1. D:\machine\RocketMQ-3.0.8\alibaba-rocketmq>start/b bin/mqbroker.exe -n "10.57.41.19:9876">D:\logs\alibaba-rocketmq/mqbroker.log  

 

看日志中信息D:\logs\alibaba-rocketmq/mqbroker.log

The broker[houchangren, 10.57.41.19:10911]boot success.

 

 

 

2.项目实例

 

1.      创建maven项目


Pom.xml文件如下

[html]  view plain copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">  
  3.  <modelVersion>4.0.0modelVersion>  
  4.  <groupId>com.ruishenhgroupId>  
  5.  <artifactId>gomeTestartifactId>  
  6.  <packaging>warpackaging>  
  7.  <version>0.0.1-SNAPSHOTversion>  
  8.  <name>gomeTest Maven Webappname>  
  9.  <url>http://maven.apache.orgurl>  
  10.  <properties>  
  11.       <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>  
  12.    properties>  
  13.  <dependencies>  
  14.     <dependency>  
  15.          <groupId>com.alibaba.rocketmqgroupId>  
  16.          <artifactId>rocketmq-clientartifactId>  
  17.          <version>3.0.8version>  
  18.       dependency>  
  19.       <dependency>  
  20.          <groupId>com.alibaba.rocketmqgroupId>  
  21.          <artifactId>rocketmq-allartifactId>  
  22.          <version>3.0.8version>  
  23.          <type>pomtype>  
  24.       dependency>  
  25.       <dependency>  
  26.          <groupId>ch.qos.logbackgroupId>  
  27.          <artifactId>logback-classicartifactId>  
  28.          <version>1.1.1version>  
  29.       dependency>  
  30.       <dependency>  
  31.          <groupId>ch.qos.logbackgroupId>  
  32.          <artifactId>logback-coreartifactId>  
  33.          <version>1.1.1version>  
  34.       dependency>  
  35.       <dependency>  
  36.          <groupId>junitgroupId>  
  37.          <artifactId>junitartifactId>  
  38.          <version>4.10version>  
  39.          <scope>testscope>  
  40.       dependency>  
  41.   dependencies>  
  42.  <build>  
  43.    <finalName>gomeTestfinalName>  
  44.  build>  
  45. project>  

 

2.      编写消息产生者Producer

文件路径:/gomeTest/src/main/java/com/ruishenh/rocketmq/example/Producer.java

 

 

[html]  view plain copy
  1. package com.ruishenh.rocketmq.example;  
  2.    
  3. import java.util.concurrent.TimeUnit;  
  4.    
  5. import com.alibaba.rocketmq.client.exception.MQClientException;  
  6. import com.alibaba.rocketmq.client.producer.DefaultMQProducer;  
  7. import com.alibaba.rocketmq.client.producer.SendResult;  
  8. import com.alibaba.rocketmq.common.message.Message;  
  9.    
  10. public classProducer {  
  11.    public static void main(String[] args) throws MQClientException,  
  12.          InterruptedException{  
  13.       /**  
  14.        * 一个应用创建一个Producer,由应用来维护此对象,可以设置为全局对象或者单例<br>  
  15.        * 注意:ProducerGroupName需要由应用来保证唯一<br>  
  16.        * ProducerGroup这个概念发送普通的消息时,作用不大,但是发送分布式事务消息时,比较关键,  
  17.        * 因为服务器会回查这个Group下的任意一个Producer  
  18.        */  
  19.       final DefaultMQProducerproducer = newDefaultMQProducer("ProducerGroupName");  
  20.       producer.setNamesrvAddr("10.57.41.19:9876");  
  21.       producer.setInstanceName("Producer");  
  22.    
  23.       /**  
  24.        * Producer对象在使用之前必须要调用start初始化,初始化一次即可<br>  
  25.        * 注意:切记不可以在每次发送消息时,都调用start方法  
  26.        */  
  27.       producer.start();  
  28.    
  29.       /**  
  30.        * 下面这段代码表明一个Producer对象可以发送多个topic,多个tag的消息。  
  31.        * 注意:send方法是同步调用,只要不抛异常就标识成功。但是发送成功也可会有多种状态,<br>  
  32.        * 例如消息写入Master成功,但是Slave不成功,这种情况消息属于成功,但是对于个别应用如果对消息可靠性要求极高,<br>  
  33.        * 需要对这种情况做处理。另外,消息可能会存在发送失败的情况,失败重试由应用来处理。  
  34.        */  
  35.       for (int i = 0; i < 10; i++){  
  36.          try {  
  37.             {  
  38.                 Messagemsg = newMessage("TopicTest1",// topic  
  39.                       "TagA",// tag  
  40.                       "OrderID001",// key  
  41.                       ("Hello MetaQA").getBytes());// body  
  42.                 SendResultsendResult = producer.send(msg);  
  43.                 System.out.println(sendResult);  
  44.             }  
  45.    
  46.             {  
  47.                 Messagemsg = newMessage("TopicTest2",// topic  
  48.                       "TagB",// tag  
  49.                       "OrderID0034",// key  
  50.                       ("Hello MetaQB").getBytes());// body  
  51.                 SendResultsendResult = producer.send(msg);  
  52.                 System.out.println(sendResult);  
  53.             }  
  54.    
  55.             {  
  56.                 Messagemsg = newMessage("TopicTest3",// topic  
  57.                       "TagC",// tag  
  58.                       "OrderID061",// key  
  59.                       ("Hello MetaQC").getBytes());// body  
  60.                 SendResultsendResult = producer.send(msg);  
  61.                 System.out.println(sendResult);  
  62.             }  
  63.          }catch(Exception e) {  
  64.             e.printStackTrace();  
  65.          }  
  66.          TimeUnit.MILLISECONDS.sleep(1000);  
  67.       }  
  68.    
  69.       /**  
  70.        * 应用退出时,要调用shutdown来清理资源,关闭网络连接,从MetaQ服务器上注销自己  
  71.        * 注意:我们建议应用在JBOSS、Tomcat等容器的退出钩子里调用shutdown方法  
  72.        */  
  73. //    producer.shutdown();  
  74.       Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {  
  75.          public void run() {  
  76.             producer.shutdown();  
  77.          }  
  78.       }));  
  79.       System.exit(0);  
  80.    }  
  81. }  
  82.    

3.      编写消息消费者Consumer

 

文件路径:Test/src/main/java/com/ruishenh/rocketmq/example/PushConsumer.java

 

[java]  view plain copy
  1. package com.ruishenh.rocketmq.example;  
  2.    
  3. import java.util.List;  
  4.    
  5. importcom.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;  
  6. importcom.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;  
  7. importcom.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;  
  8. importcom.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;  
  9. importcom.alibaba.rocketmq.client.exception.MQClientException;  
  10. importcom.alibaba.rocketmq.common.message.MessageExt;  
  11.    
  12. public class PushConsumer {  
  13.          /** 
  14.           * 当前例子是PushConsumer用法,使用方式给用户感觉是消息从RocketMQ服务器推到了应用客户端。
     
  15.           * 但是实际PushConsumer内部是使用长轮询Pull方式从MetaQ服务器拉消息,然后再回调用户Listener方法
     
  16.           */  
  17.          publicstatic void main(String[] args) throws InterruptedException,  
  18.                             MQClientException{  
  19.                    /** 
  20.                     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例
     
  21.                     * 注意:ConsumerGroupName需要由应用来保证唯一 
  22.                     */  
  23.                    DefaultMQPushConsumerconsumer = new DefaultMQPushConsumer(  
  24.                                      "ConsumerGroupName");  
  25.                    consumer.setNamesrvAddr("10.57.41.19:9876");  
  26.                    consumer.setInstanceName("Consumber");  
  27.    
  28.                    /** 
  29.                     * 订阅指定topic下tags分别等于TagA或TagC或TagD 
  30.                     */  
  31.                    consumer.subscribe("TopicTest1","TagA || TagC || TagD");  
  32.                    /** 
  33.                     * 订阅指定topic下所有消息
     
  34.                     * 注意:一个consumer对象可以订阅多个topic 
  35.                     */  
  36.                    consumer.subscribe("TopicTest2","*");  
  37.    
  38.                    consumer.registerMessageListener(newMessageListenerConcurrently() {  
  39.    
  40.                             publicConsumeConcurrentlyStatus consumeMessage(  
  41.                                                Listmsgs, ConsumeConcurrentlyContext context) {  
  42.    
  43.                                      System.out.println(Thread.currentThread().getName()  
  44.                                                         +" Receive New Messages: " + msgs.size());  
  45.    
  46.                                      MessageExtmsg = msgs.get(0);  
  47.                                      if(msg.getTopic().equals("TopicTest1")) {  
  48.                                                //执行TopicTest1的消费逻辑  
  49.                                                if(msg.getTags() != null && msg.getTags().equals("TagA")) {  
  50.                                                         //执行TagA的消费  
  51.                                                         System.out.println(newString(msg.getBody()));  
  52.                                                }else if (msg.getTags() != null  
  53.                                                                  &&msg.getTags().equals("TagC")) {  
  54.                                                         //执行TagC的消费  
  55.                                                         System.out.println(newString(msg.getBody()));  
  56.                                                }else if (msg.getTags() != null  
  57.                                                                  &&msg.getTags().equals("TagD")) {  
  58.                                                         //执行TagD的消费  
  59.                                                         System.out.println(newString(msg.getBody()));  
  60.                                                }  
  61.                                      }else if (msg.getTopic().equals("TopicTest2")) {  
  62.                                                System.out.println(newString(msg.getBody()));  
  63.                                      }  
  64.    
  65.                                      returnConsumeConcurrentlyStatus.CONSUME_SUCCESS;  
  66.    
  67.                             }  
  68.                    });  
  69.    
  70.                    /** 
  71.                     * Consumer对象在使用之前必须要调用start初始化,初始化一次即可
     
  72.                     */  
  73.                    consumer.start();  
  74.    
  75.                    System.out.println("ConsumerStarted.");  
  76.          }  
  77. }  


 

Producer执行console:

12:05:39.399 [main] DEBUGi.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework

12:05:39.405 [main] DEBUGi.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8

12:05:39.411 [main] DEBUGi.n.util.internal.PlatformDependent - Platform: Windows

12:05:39.411 [main] DEBUGi.n.util.internal.PlatformDependent - Java version: 6

12:05:39.411 [main] DEBUGi.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false

12:05:39.412 [main] DEBUGi.n.util.internal.PlatformDependent0 - java.nio.ByteBuffer.cleaner: available

12:05:39.413 [main] DEBUGi.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available

12:05:39.413 [main] DEBUGi.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available

12:05:39.413 [main] DEBUGi.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available

12:05:39.413 [main] DEBUGi.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: true

12:05:39.413 [main] DEBUGi.n.util.internal.PlatformDependent - sun.misc.Unsafe: available

12:05:39.413 [main] DEBUGi.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false

12:05:39.414 [main] DEBUGi.n.util.internal.PlatformDependent - Javassist: unavailable

12:05:39.414 [main] DEBUGi.n.util.internal.PlatformDependent - You don't have Javassist in your classpath or you don't have enough permission to load dynamically generatedclasses.  Please check the configurationfor better performance.

12:05:39.414 [main] DEBUGi.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false

12:05:39.429 [main] DEBUGio.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false

12:05:39.429 [main] DEBUGio.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold:512

12:05:39.481 [main] DEBUGi.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier:0x653a966ddb02e036

12:05:39.523[NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector --Dio.netty.noResourceLeakDetection: false

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BA16, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=0], queueOffset=66]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BAAB, messageQueue=MessageQueue [topic=TopicTest2,brokerName=houchangren, queueId=0], queueOffset=66]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BB41, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=0], queueOffset=66]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BBD6, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=1], queueOffset=66]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BC6B, messageQueue=MessageQueue [topic=TopicTest2,brokerName=houchangren, queueId=1], queueOffset=66]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BD01, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=1], queueOffset=66]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BD96, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=2], queueOffset=61]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BE2B, messageQueue=MessageQueue [topic=TopicTest2,brokerName=houchangren, queueId=2], queueOffset=61]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BEC1, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=2], queueOffset=61]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BF56, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=3], queueOffset=61]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001BFEB, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=3], queueOffset=61]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C081, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=3], queueOffset=61]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C116, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=0], queueOffset=67]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C1AB, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=0], queueOffset=67]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C241, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=0], queueOffset=67]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C2D6, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=1], queueOffset=67]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C36B, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=1], queueOffset=67]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C401, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=1], queueOffset=67]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C496, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=2], queueOffset=62]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C52B, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=2], queueOffset=62]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C5C1, messageQueue=MessageQueue [topic=TopicTest3,brokerName=houchangren, queueId=2], queueOffset=62]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C656, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=3], queueOffset=62]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C6EB, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=3], queueOffset=62]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C781, messageQueue=MessageQueue [topic=TopicTest3,brokerName=houchangren, queueId=3], queueOffset=62]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C816, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=0], queueOffset=68]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C8AB, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=0], queueOffset=68]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C941, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=0], queueOffset=68]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001C9D6, messageQueue=MessageQueue[topic=TopicTest1, brokerName=houchangren, queueId=1], queueOffset=68]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001CA6B, messageQueue=MessageQueue[topic=TopicTest2, brokerName=houchangren, queueId=1], queueOffset=68]

SendResult [sendStatus=SEND_OK,msgId=0A39291300002A9F000000000001CB01, messageQueue=MessageQueue[topic=TopicTest3, brokerName=houchangren, queueId=1], queueOffset=68]

 

 

 

Consumer执行console:

12:00:49.539 [main] DEBUGi.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework

12:00:49.545 [main] DEBUGi.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8

12:00:49.550 [main] DEBUGi.n.util.internal.PlatformDependent - Platform: Windows

12:00:49.550 [main] DEBUGi.n.util.internal.PlatformDependent - Java version: 6

12:00:49.550 [main] DEBUGi.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false

12:00:49.551 [main] DEBUGi.n.util.internal.PlatformDependent0 - java.nio.ByteBuffer.cleaner: available

12:00:49.552 [main] DEBUGi.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available

12:00:49.552 [main] DEBUGi.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available

12:00:49.552 [main] DEBUGi.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available

12:00:49.552 [main] DEBUGi.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: true

12:00:49.552 [main] DEBUGi.n.util.internal.PlatformDependent - sun.misc.Unsafe: available

12:00:49.552 [main] DEBUGi.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false

12:00:49.553 [main] DEBUGi.n.util.internal.PlatformDependent - Javassist: unavailable

12:00:49.553 [main] DEBUGi.n.util.internal.PlatformDependent - You don't have Javassist in your classpath or you don't have enough permission to load dynamically generatedclasses.  Please check the configurationfor better performance.

12:00:49.553 [main] DEBUGi.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false

12:00:49.568 [main] DEBUGio.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false

12:00:49.568 [main] DEBUGio.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold:512

12:00:49.622 [main] DEBUGi.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier:0x2e4f8e2e67b4cc9b

12:00:49.663[NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector --Dio.netty.noResourceLeakDetection: false

Consumer Started.

ConsumeMessageThread-ConsumerGroupName-4Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-2Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-1Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-6Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-5Receive New Messages: 1

ConsumeMessageThread-ConsumerGroupName-3Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-8Receive New Messages: 1

Hello MetaQA

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-9Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-10Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-7Receive New Messages: 1

Hello MetaQA

ConsumeMessageThread-ConsumerGroupName-11Receive New Messages: 1

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-12Receive New Messages: 1

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-13Receive New Messages: 1

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-15Receive New Messages: 1

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-14Receive New Messages: 1

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-16Receive New Messages: 1

ConsumeMessageThread-ConsumerGroupName-17Receive New Messages: 1

Hello MetaQB

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-18Receive New Messages: 1

ConsumeMessageThread-ConsumerGroupName-19Receive New Messages: 1

Hello MetaQB

Hello MetaQB

ConsumeMessageThread-ConsumerGroupName-20Receive New Messages: 1

Hello MetaQB

 

参考:
http://my.oschina.net/cloudcoder/blog/200741

https://github.com/alibaba/RocketMQ/wiki/Quick-Start


如果报com.alibaba.rocketmq.client.exception.MQClientException: No route info of this topic, TopicTest1
See https://github.com/alibaba/RocketMQ/issues/264 for further details.
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:570)
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:972)
at com.alibaba.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:109)
at com.ruishenh.rocketmq.example.Producer.main(Producer.java:43)

这是因为启动broker需要 mqbroker.exe -n localhost:9876,而不是双击 mqbroker.exe

你可能感兴趣的:(java,分布式,java)