关闭

java客户端使用RocketMQ 消息队列

748人阅读 评论(1) 收藏 举报
分类:

2.java客户端使用RocketMQ 消息队列

备注:RocketMq 服务器启动好, 防火墙关闭或者9876 、10911等端口加入白名单

2.1 依赖配置

<code class="language-java hljs  has-numbering"><!-- RocketMQ Java SDK -->
<dependency>
    <groupId>com.alibaba.rocketmq</groupId>
    <artifactId>rocketmq-client</artifactId>
    <version><span class="hljs-number">3.2</span><span class="hljs-number">.6</span></version>
</dependency></code>

2.2 创建生产者

用来获取一个单例的生产者。

<code class="language-java hljs  has-numbering"><span class="hljs-keyword">package</span> com.autonavi.rocketmq.producer;

<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.exception.MQClientException;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.producer.DefaultMQProducer;

<span class="hljs-javadoc">/**
 *<span class="hljs-javadoctag"> @author</span> dddd
 *<span class="hljs-javadoctag"> @description</span> 消息生产者
 *<span class="hljs-javadoctag"> @date</span> 2016-04-07
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Producer</span> {</span>

     <span class="hljs-comment">/*
     * Constructs a client instance with your account for accessing DefaultMQProducer
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> DefaultMQProducer producer = <span class="hljs-keyword">new</span> DefaultMQProducer(<span class="hljs-string">"ProducerGroupName"</span>);
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> initialState = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">private</span> <span class="hljs-title">Producer</span>() {

    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> DefaultMQProducer <span class="hljs-title">getDefaultMQProducer</span>(){     
        <span class="hljs-keyword">if</span>(producer == <span class="hljs-keyword">null</span>){
            producer = <span class="hljs-keyword">new</span> DefaultMQProducer(<span class="hljs-string">"ProducerGroupName"</span>);          
        }

        <span class="hljs-keyword">if</span>(initialState == <span class="hljs-number">0</span>){
            producer.setNamesrvAddr(<span class="hljs-string">"100.125.1.186:9876"</span>);
            <span class="hljs-keyword">try</span> {
                producer.start();
            } <span class="hljs-keyword">catch</span> (MQClientException e) {
                <span class="hljs-comment">// TODO Auto-generated catch block</span>
                e.printStackTrace();
                <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
            }

            initialState = <span class="hljs-number">1</span>;
        }

        <span class="hljs-keyword">return</span> producer;        
    }

}</code>

2.3 创建消费者

用来获取一个单例的消费者。消费者类似于直接操作数据库的对象,比如生产者下了订单订火车票,消费者就一直监听,有订单消息过来了,就去执行下订单操作。

<code class="language-java hljs  has-numbering"><span class="hljs-keyword">package</span> com.autonavi.rocketmq.consumer;

<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.common.consumer.ConsumeFromWhere;

<span class="hljs-javadoc">/**
 *<span class="hljs-javadoctag"> @author</span> dddd
 *<span class="hljs-javadoctag"> @description</span> 消息消费者
 *<span class="hljs-javadoctag"> @date</span> 2016-04-07
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Consumer</span> {</span>

     <span class="hljs-comment">/*
     * Constructs a client instance with your account for accessing DefaultMQConsumer
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> DefaultMQPushConsumer consumer = <span class="hljs-keyword">new</span> DefaultMQPushConsumer(<span class="hljs-string">"ConsumerGroupName"</span>);
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> initialState = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">private</span> <span class="hljs-title">Consumer</span>() {

    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> DefaultMQPushConsumer <span class="hljs-title">getDefaultMQPushConsumer</span>(){     
        <span class="hljs-keyword">if</span>(consumer == <span class="hljs-keyword">null</span>){
            consumer = <span class="hljs-keyword">new</span> DefaultMQPushConsumer(<span class="hljs-string">"ConsumerGroupName"</span>);          
        }

        <span class="hljs-keyword">if</span>(initialState == <span class="hljs-number">0</span>){
            consumer.setNamesrvAddr(<span class="hljs-string">"100.125.1.186:9876"</span>);
            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
            initialState = <span class="hljs-number">1</span>;
        }

        <span class="hljs-keyword">return</span> consumer;        
    }

}</code>

2.4 创建生产和消费服务

<code class="language-java hljs  has-numbering"><span class="hljs-keyword">package</span> com.autonavi.rocketmq.service;

<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;

<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.exception.MQBrokerException;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.exception.MQClientException;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.producer.DefaultMQProducer;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.client.producer.SendResult;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.common.message.Message;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.common.message.MessageExt;
<span class="hljs-keyword">import</span> com.alibaba.rocketmq.remoting.exception.RemotingException;
<span class="hljs-keyword">import</span> com.autonavi.rocketmq.consumer.Consumer;
<span class="hljs-keyword">import</span> com.autonavi.rocketmq.producer.Producer;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> {</span>

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger logger = LoggerFactory.getLogger(Test.class);

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span>(String[] args){

        sendMsg();
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">sendMsg</span>(){

        <span class="hljs-comment">// 获取消息生产者</span>
        DefaultMQProducer producer = Producer.getDefaultMQProducer();

        <span class="hljs-keyword">try</span> {
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i<<span class="hljs-number">2000</span>;i++){
                Message msg = <span class="hljs-keyword">new</span> Message(
                        <span class="hljs-string">"TopicTest1"</span>,                   <span class="hljs-comment">// topic</span>
                        <span class="hljs-string">"TagA"</span>,                         <span class="hljs-comment">// tag</span>
                        <span class="hljs-string">"OrderID00"</span>+i,                  <span class="hljs-comment">// key</span>
                        (<span class="hljs-string">"Hello MetaQ"</span>+i).getBytes());  <span class="hljs-comment">// body</span>
                SendResult sendResult = producer.send(msg);
                <span class="hljs-comment">//logger.info("sendResult:{}", sendResult);</span>
            }           
        } <span class="hljs-keyword">catch</span> (MQClientException e) {
            <span class="hljs-comment">// TODO Auto-generated catch block</span>
            e.printStackTrace();
        } <span class="hljs-keyword">catch</span> (RemotingException e) {
            <span class="hljs-comment">// TODO Auto-generated catch block</span>
            e.printStackTrace();
        } <span class="hljs-keyword">catch</span> (MQBrokerException e) {
            <span class="hljs-comment">// TODO Auto-generated catch block</span>
            e.printStackTrace();
        } <span class="hljs-keyword">catch</span> (InterruptedException e) {
            <span class="hljs-comment">// TODO Auto-generated catch block</span>
            e.printStackTrace();
        }

        producer.shutdown();
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">receiveMsg</span>(){

        <span class="hljs-comment">// 获取消息生产者</span>
        DefaultMQPushConsumer consumer = Consumer.getDefaultMQPushConsumer();

        <span class="hljs-comment">// 订阅主体</span>
        <span class="hljs-keyword">try</span> {
            consumer.subscribe(<span class="hljs-string">"TopicTest1"</span>, <span class="hljs-string">"*"</span>);

            consumer.registerMessageListener(<span class="hljs-keyword">new</span> MessageListenerConcurrently() {

                <span class="hljs-javadoc">/**
                 * * 默认msgs里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
                 */</span>
                <span class="hljs-keyword">public</span> ConsumeConcurrentlyStatus <span class="hljs-title">consumeMessage</span>(
                        List<MessageExt> msgs, ConsumeConcurrentlyContext context) {

                    logger.info(<span class="hljs-string">"currentThreadName:{} and Receive New Messages:{}"</span>,Thread.currentThread().getName(),msgs);

                    MessageExt msg = msgs.get(<span class="hljs-number">0</span>);

                    <span class="hljs-keyword">if</span> (msg.getTopic().equals(<span class="hljs-string">"TopicTest1"</span>)) {
                        <span class="hljs-comment">// 执行TopicTest1的消费逻辑</span>
                        <span class="hljs-keyword">if</span> (msg.getTags() != <span class="hljs-keyword">null</span> && msg.getTags().equals(<span class="hljs-string">"TagA"</span>)) {
                            <span class="hljs-comment">// 执行TagA的消费</span>
                            logger.info(<span class="hljs-string">"MsgBody:{}"</span>,<span class="hljs-keyword">new</span> String(msg.getBody()));
                        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (msg.getTags() != <span class="hljs-keyword">null</span>
                                && msg.getTags().equals(<span class="hljs-string">"TagC"</span>)) {
                            <span class="hljs-comment">// 执行TagC的消费</span>
                        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (msg.getTags() != <span class="hljs-keyword">null</span>
                                && msg.getTags().equals(<span class="hljs-string">"TagD"</span>)) {
                            <span class="hljs-comment">// 执行TagD的消费</span>
                        }
                    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (msg.getTopic().equals(<span class="hljs-string">"TopicTest2"</span>)) {
                        <span class="hljs-comment">// 执行TopicTest2的消费逻辑</span>
                    }

                    <span class="hljs-keyword">return</span> ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                }           
            });

            <span class="hljs-javadoc">/**
             * Consumer对象在使用之前必须要调用start初始化,初始化一次即可<br>
             */</span>
            consumer.start();                      

            logger.info(<span class="hljs-string">"Consumer Started."</span>);
        } <span class="hljs-keyword">catch</span> (MQClientException e) {
            <span class="hljs-comment">// TODO Auto-generated catch block</span>
            e.printStackTrace();
        }
    }

}</code>

2.5 测试效果

2.5.1 生产100个消息

<code class="language-java hljs  has-numbering"><span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C286, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">0</span>], queueOffset=<span class="hljs-number">617</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C31B, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">1</span>], queueOffset=<span class="hljs-number">616</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C3B0, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">2</span>], queueOffset=<span class="hljs-number">614</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C445, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">3</span>], queueOffset=<span class="hljs-number">614</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C4DA, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">0</span>], queueOffset=<span class="hljs-number">618</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C56F, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">1</span>], queueOffset=<span class="hljs-number">617</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C604, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">2</span>], queueOffset=<span class="hljs-number">615</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C699, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">3</span>], queueOffset=<span class="hljs-number">615</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C72E, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">0</span>], queueOffset=<span class="hljs-number">619</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C7C3, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">1</span>], queueOffset=<span class="hljs-number">618</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C858, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">2</span>], queueOffset=<span class="hljs-number">616</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C8EF, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">3</span>], queueOffset=<span class="hljs-number">616</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C986, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">0</span>], queueOffset=<span class="hljs-number">620</span>]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">01</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - sendResult:SendResult [sendStatus=SEND_OK, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005CA1D, messageQueue=MessageQueue [topic=TopicTest1, brokerName=e010125001186.bja, queueId=<span class="hljs-number">1</span>], queueOffset=<span class="hljs-number">619</span>]
     ...</code>

这里写图片描述

2.5.2 消费100个消息

<code class="language-java hljs  has-numbering"><span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [main] [com.autonavi.rocketmq.service.Test] [INFO] - Consumer Started.
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_11] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_11 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">151</span>, queueOffset=<span class="hljs-number">618</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115897</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115856</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005CDA7, commitLogOffset=<span class="hljs-number">380327</span>, bodyCRC=<span class="hljs-number">901334138</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID0019, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">13</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_8] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_8 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">149</span>, queueOffset=<span class="hljs-number">615</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115722</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115680</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C699, commitLogOffset=<span class="hljs-number">378521</span>, bodyCRC=<span class="hljs-number">260218519</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID007, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">12</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_9] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_9 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">151</span>, queueOffset=<span class="hljs-number">616</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115773</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115734</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C8EF, commitLogOffset=<span class="hljs-number">379119</span>, bodyCRC=<span class="hljs-number">996330568</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID0011, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">13</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_3] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_3 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">149</span>, queueOffset=<span class="hljs-number">614</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115669</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115629</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C445, commitLogOffset=<span class="hljs-number">377925</span>, bodyCRC=<span class="hljs-number">149904014</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID003, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">12</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_12] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_12 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">151</span>, queueOffset=<span class="hljs-number">619</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115951</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115911</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005D003, commitLogOffset=<span class="hljs-number">380931</span>, bodyCRC=<span class="hljs-number">2118254247</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID0023, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">13</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_11] [com.autonavi.rocketmq.service.Test] [INFO] - MsgBody:Hello MetaQ19
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_1] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_1 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">1</span>, storeSize=<span class="hljs-number">149</span>, queueOffset=<span class="hljs-number">616</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115635</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115594</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C31B, commitLogOffset=<span class="hljs-number">377627</span>, bodyCRC=<span class="hljs-number">1726036898</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID001, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">641</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">12</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_1] [com.autonavi.rocketmq.service.Test] [INFO] - MsgBody:Hello MetaQ1
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_18] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_18 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">151</span>, queueOffset=<span class="hljs-number">625</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016116319</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016116278</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005DE2B, commitLogOffset=<span class="hljs-number">384555</span>, bodyCRC=<span class="hljs-number">796302648</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID0047, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">13</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_18] [com.autonavi.rocketmq.service.Test] [INFO] - MsgBody:Hello MetaQ47
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_4] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_4 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">2</span>, storeSize=<span class="hljs-number">149</span>, queueOffset=<span class="hljs-number">614</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115648</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115608</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C3B0, commitLogOffset=<span class="hljs-number">377776</span>, bodyCRC=<span class="hljs-number">2145937944</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID002, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">12</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_4] [com.autonavi.rocketmq.service.Test] [INFO] - MsgBody:Hello MetaQ2
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_20] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_20 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">3</span>, storeSize=<span class="hljs-number">151</span>, queueOffset=<span class="hljs-number">627</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016116436</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016116393</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005E2E3, commitLogOffset=<span class="hljs-number">385763</span>, bodyCRC=<span class="hljs-number">1482935637</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID0055, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">639</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">13</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_20] [com.autonavi.rocketmq.service.Test] [INFO] - MsgBody:Hello MetaQ55
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_2] [com.autonavi.rocketmq.service.Test] [INFO] - currentThreadName:ConsumeMessageThread_2 and Receive New Messages:[MessageExt [queueId=<span class="hljs-number">0</span>, storeSize=<span class="hljs-number">149</span>, queueOffset=<span class="hljs-number">617</span>, sysFlag=<span class="hljs-number">0</span>, bornTimestamp=<span class="hljs-number">1460016115587</span>, bornHost=/<span class="hljs-number">30.85</span><span class="hljs-number">.231</span><span class="hljs-number">.35</span>:<span class="hljs-number">58198</span>, storeTimestamp=<span class="hljs-number">1460016115577</span>, storeHost=/<span class="hljs-number">10.125</span><span class="hljs-number">.1</span><span class="hljs-number">.186</span>:<span class="hljs-number">10911</span>, msgId=<span class="hljs-number">0</span>A7D01BA00002A9F000000000005C286, commitLogOffset=<span class="hljs-number">377478</span>, bodyCRC=<span class="hljs-number">300288820</span>, reconsumeTimes=<span class="hljs-number">0</span>, preparedTransactionOffset=<span class="hljs-number">0</span>, toString()=Message [topic=TopicTest1, flag=<span class="hljs-number">0</span>, properties={TAGS=TagA, KEYS=OrderID000, WAIT=<span class="hljs-keyword">true</span>, MAX_OFFSET=<span class="hljs-number">642</span>, MIN_OFFSET=<span class="hljs-number">0</span>}, body=<span class="hljs-number">12</span>]]]
     <span class="hljs-number">2016</span>-<span class="hljs-number">04</span>-<span class="hljs-number">07</span>-<span class="hljs-number">16</span>-<span class="hljs-number">04</span> [ConsumeMessageThread_2] [com.autonavi.rocketmq.service.Test] [INFO] - MsgBody:Hello MetaQ0
     ...</code><div style="display: block;" class="save_code tracking-ad" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

这里写图片描述

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2135次
    • 积分:83
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:3篇
    • 译文:0篇
    • 评论:1条
    文章分类