rocketmq源码分析

rocketmq-client源码分析

注释:

0、PullMessageService.run

1、RebalanceImpl.updateProcessQueueTableInRebalance

2、PullMessageService.executePullRequestImmediately

3、DefaultMQPushConsumerImpl.pullMessage

4、PullCallback

5、NettyRemotingAbstract.invokeAsyncImpl

6、NettyRemotingAbstract.processResponseCommand

7、ConsumeMessageConcurrentlyService.submitConsumeRequest

8、DefaultRocketMQListenerContainer.DefaultMessageListenerConcurrently.consumeMessage

9、ConsumeMessageConcurrentlyService.processConsumeResult

10、PullMessageService.executePullRequestImmediately

问题分析

1、消费者是否拉取queueid=4的最新消息?

watch org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl pullMessage "{params}" "params.{? #this.messageQueue.topic == 'prod_ykq_prescription_data' }.size()>0 && params.{? #this.messageQueue.queueId == 4 }.size()>0" -x 3

2、服务端是否对queueid=4的请求予以响应?

watch org.apache.rocketmq.client.impl.consumer.PullAPIWrapper processPullResult "{params}" "params[0].{? #this.topic == 'prod_ykq_prescription_data' }.size()>0 && params[0].{? #this.queueId == 4 }.size()>0" -x 3

3、消费者拉取到消息之后是否提交,线程是否阻塞,队列是否堆积?

watch org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService submitConsumeRequest "{params,target,returnObj}" "params[0].{? #this.topic == 'prod_ykq_prescription_data' }.size()>0 && params[0].{? #this.queueId == 4 }.size()>0" -x 3

4、消费者是否进行消息消费?

watch org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently consumeMessage "{params}" "params[0].{? #this.topic == 'prod_ykq_prescription_data' }.size()>0 && params[0].{? #this.queueId == 4 }.size()>0" -x 3 -b -s

 

返回信息

[arthas@23377]$ watch org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService submitConsumeRequest "{params,target,returnObj}" "params[0].{? #this.queueId == 4 }.size()>0" -x 3
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 163 ms, listenerId: 60
ts=2020-12-08 15:41:02; [cost=0.045307ms] result=@ArrayList[
    @Object[][
        @ArrayList[
            @MessageClientExt[MessageExt [queueId=4, storeSize=350, queueOffset=56183, sysFlag=0, bornTimestamp=1607413262065, bornHost=/172.16.1.67:29391, storeTimestamp=1607413262065, storeHost=/172.16.7.186:10911, msgId=AC1007BA00002A9F00000003AD3AB2AC, commitLogOffset=15791207084, bodyCRC=1469103624, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='prod_im_notify_build_pdf_message', flag=0, properties={MIN_OFFSET=48539, MAX_OFFSET=56184, CONSUME_START_TIME=1607413262067, UNIQ_KEY=AC10014360E61055E4AF276A0EF19A07, WAIT=true}, body=[123, 34, 109, 115, 103, 34, 58, 34, -26, -120, -112, -27, -118, -97, -25, -108, -97, -26, -120, -112, -24, -127, -118, -27, -92, -87, 80, 68, 70, 34, 44, 34, 99, 111, 100, 101, 34, 58, 48, 44, 34, 112, 100, 102, 70, 105, 108, 101, 85, 114, 108, 34, 58, 34, 104, 116, 116, 112, 115, 58, 47, 47, 117, 112, 108, 111, 97, 100, 46, 121, 98, 109, 49, 48, 48, 46, 99, 111, 109, 47, 71, 51, 47, 77, 48, 48, 47, 53, 65, 47, 70, 51, 47, 67, 105, 73, 67, 101, 108, 95, 80, 76, 103, 54, 65, 81, 50, 72, 69, 65, 65, 65, 74, 89, 108, 95, 74, 118, 103, 65, 57, 53, 54, 46, 80, 68, 70, 34, 44, 34, 105, 110, 113, 117, 114, 121, 73, 100, 34, 58, 34, 102, 101, 101, 51, 101, 100, 101, 49, 53, 101, 98, 97, 52, 57, 53, 53, 57, 99, 53, 53, 48, 56, 52, 50, 50, 97, 49, 51, 48, 102, 100, 54, 34, 125], transactionId='null'}]],
        ],
        @ProcessQueue[
            REBALANCE_LOCK_MAX_LIVE_TIME=@Long[30000],
            REBALANCE_LOCK_INTERVAL=@Long[20000],
            PULL_MAX_IDLE_TIME=@Long[120000],
            log=@InnerLogger[org.apache.rocketmq.logging.InnerLoggerFactory$InnerLogger@700fb0f4],
            lockTreeMap=@ReentrantReadWriteLock[java.util.concurrent.locks.ReentrantReadWriteLock@3b938f38[Write locks = 0, Read locks = 0]],
            msgTreeMap=@TreeMap[isEmpty=false;size=1],
            msgCount=@AtomicLong[1],
            msgSize=@AtomicLong[175],
            lockConsume=@ReentrantLock[java.util.concurrent.locks.ReentrantLock@5f860447[Unlocked]],
            consumingMsgOrderlyTreeMap=@TreeMap[isEmpty=true;size=0],
            tryUnlockTimes=@AtomicLong[0],
            queueOffsetMax=@Long[56183],
            dropped=@Boolean[false],
            lastPullTimestamp=@Long[1607413261751],
            lastConsumeTimestamp=@Long[1607413184146],
            locked=@Boolean[false],
            lastLockTimestamp=@Long[1607342584880],
            consuming=@Boolean[true],
            msgAccCnt=@Long[1],
        ],
        @MessageQueue[
            serialVersionUID=@Long[6191200464116433425],
            topic=@String[prod_im_notify_build_pdf_message],
            brokerName=@String[broker-a],
            queueId=@Integer[4],
        ],
        @Boolean[false],
    ],
    @ConsumeMessageConcurrentlyService[
        log=@InnerLogger[
            logger=@Logger[org.apache.rocketmq.logging.inner.Logger@343574ea],
        ],
        defaultMQPushConsumerImpl=@DefaultMQPushConsumerImpl[
            pullTimeDelayMillsWhenException=@Long[1000],
            PULL_TIME_DELAY_MILLS_WHEN_FLOW_CONTROL=@Long[50],
            PULL_TIME_DELAY_MILLS_WHEN_SUSPEND=@Long[1000],
            BROKER_SUSPEND_MAX_TIME_MILLIS=@Long[15000],
            CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND=@Long[30000],
            log=@InnerLogger[org.apache.rocketmq.logging.InnerLoggerFactory$InnerLogger@700fb0f4],
            defaultMQPushConsumer=@DefaultMQPushConsumer[ClientConfig [namesrvAddr=mq01-ykq-prod.rocketmq.ybm100.top:9876;mq02-ykq-prod.rocketmq.ybm100.top:9876;mq03-ykq-prod.rocketmq.ybm100.top:9876;mq04-ykq-prod.rocketmq.ybm100.top:9876, clientIP=172.16.9.127, instanceName=ykqInstance, clientCallbackExecutorThreads=4, pollNameServerInterval=30000, heartbeatBrokerInterval=30000, persistConsumerOffsetInterval=5000, pullTimeDelayMillsWhenException=1000, unitMode=false, unitName=null, vipChannelEnabled=false, useTLS=false, language=JAVA, namespace=null]],
            rebalanceImpl=@RebalancePushImpl[org.apache.rocketmq.client.impl.consumer.RebalancePushImpl@61c81443],
            filterMessageHookList=@ArrayList[isEmpty=true;size=0],
            consumerStartTimestamp=@Long[1607342584748],
            consumeMessageHookList=@ArrayList[isEmpty=false;size=1],
            rpcHook=null,
            serviceState=@ServiceState[RUNNING],
            mQClientFactory=@MQClientInstance[org.apache.rocketmq.client.impl.factory.MQClientInstance@25be9076],
            pullAPIWrapper=@PullAPIWrapper[org.apache.rocketmq.client.impl.consumer.PullAPIWrapper@79b7c068],
            pause=@Boolean[false],
            consumeOrderly=@Boolean[false],
            messageListenerInner=@DefaultMessageListenerConcurrently[org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer$DefaultMessageListenerConcurrently@776d2df3],
            offsetStore=@RemoteBrokerOffsetStore[org.apache.rocketmq.client.consumer.store.RemoteBrokerOffsetStore@515e3caa],
            consumeMessageService=@ConsumeMessageConcurrentlyService[org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService@22503928],
            queueFlowControlTimes=@Long[0],
            queueMaxSpanFlowControlTimes=@Long[0],
        ],
        defaultMQPushConsumer=@DefaultMQPushConsumer[
            log=@InnerLogger[org.apache.rocketmq.logging.InnerLoggerFactory$InnerLogger@700fb0f4],
            defaultMQPushConsumerImpl=@DefaultMQPushConsumerImpl[org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl@31b5b2d],
            consumerGroup=@String[CID_prod_im_notify_build_pdf_message],
            messageModel=@MessageModel[CLUSTERING],
            consumeFromWhere=@ConsumeFromWhere[CONSUME_FROM_LAST_OFFSET],
            consumeTimestamp=@String[20201207193304],
            allocateMessageQueueStrategy=@AllocateMessageQueueAveragely[org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely@1d87ec08],
            subscription=@HashMap[isEmpty=true;size=0],
            messageListener=@DefaultMessageListenerConcurrently[org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer$DefaultMessageListenerConcurrently@776d2df3],
            offsetStore=@RemoteBrokerOffsetStore[org.apache.rocketmq.client.consumer.store.RemoteBrokerOffsetStore@515e3caa],
            consumeThreadMin=@Integer[20],
            consumeThreadMax=@Integer[64],
            adjustThreadPoolNumsThreshold=@Long[100000],
            consumeConcurrentlyMaxSpan=@Integer[2000],
            pullThresholdForQueue=@Integer[1000],
            pullThresholdSizeForQueue=@Integer[100],
            pullThresholdForTopic=@Integer[-1],
            pullThresholdSizeForTopic=@Integer[-1],
            pullInterval=@Long[0],
            consumeMessageBatchMaxSize=@Integer[1],
            pullBatchSize=@Integer[32],
            postSubscriptionWhenPull=@Boolean[false],
            unitMode=@Boolean[false],
            maxReconsumeTimes=@Integer[-1],
            suspendCurrentQueueTimeMillis=@Long[1000],
            consumeTimeout=@Long[30000],
            traceDispatcher=@AsyncTraceDispatcher[org.apache.rocketmq.client.trace.AsyncTraceDispatcher@3d1c287e],
            SEND_MESSAGE_WITH_VIP_CHANNEL_PROPERTY=@String[com.rocketmq.sendMessageWithVIPChannel],
            namesrvAddr=@String[mq01-ykq-prod.rocketmq.ybm100.top:9876;mq02-ykq-prod.rocketmq.ybm100.top:9876;mq03-ykq-prod.rocketmq.ybm100.top:9876;mq04-ykq-prod.rocketmq.ybm100.top:9876],
            clientIP=@String[172.16.9.127],
            instanceName=@String[ykqInstance],
            clientCallbackExecutorThreads=@Integer[4],
            namespace=null,
            accessChannel=@AccessChannel[LOCAL],
            pollNameServerInterval=@Integer[30000],
            heartbeatBrokerInterval=@Integer[30000],
            persistConsumerOffsetInterval=@Integer[5000],
            pullTimeDelayMillsWhenException=@Long[1000],
            unitMode=@Boolean[false],
            unitName=null,
            vipChannelEnabled=@Boolean[false],
            useTLS=@Boolean[false],
            language=@LanguageCode[JAVA],
        ],
        messageListener=@DefaultMessageListenerConcurrently[
            this$0=@DefaultRocketMQListenerContainer[DefaultRocketMQListenerContainer{consumerGroup='CID_prod_im_notify_build_pdf_message', nameServer='mq01-ykq-prod.rocketmq.ybm100.top:9876;mq02-ykq-prod.rocketmq.ybm100.top:9876;mq03-ykq-prod.rocketmq.ybm100.top:9876;mq04-ykq-prod.rocketmq.ybm100.top:9876', topic='prod_im_notify_build_pdf_message', consumeMode=CONCURRENTLY, selectorType=TAG, selectorExpression='*', messageModel=CLUSTERING}],
        ],
        consumeRequestQueue=@LinkedBlockingQueue[isEmpty=true;size=0],
        consumeExecutor=@ThreadPoolExecutor[
            ctl=@AtomicInteger[-536870892],
            COUNT_BITS=@Integer[29],
            CAPACITY=@Integer[536870911],
            RUNNING=@Integer[-536870912],
            SHUTDOWN=@Integer[0],
            STOP=@Integer[536870912],
            TIDYING=@Integer[1073741824],
            TERMINATED=@Integer[1610612736],
            workQueue=@LinkedBlockingQueue[isEmpty=true;size=0],
            mainLock=@ReentrantLock[java.util.concurrent.locks.ReentrantLock@1e26df8c[Unlocked]],
            workers=@HashSet[isEmpty=false;size=20],
            termination=@ConditionObject[java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@473d2d56],
            largestPoolSize=@Integer[20],
            completedTaskCount=@Long[0],
            threadFactory=@ThreadFactoryImpl[org.apache.rocketmq.common.ThreadFactoryImpl@65787e15],
            handler=@AbortPolicy[java.util.concurrent.ThreadPoolExecutor$AbortPolicy@22bf7249],
            keepAliveTime=@Long[60000000000],
            allowCoreThreadTimeOut=@Boolean[false],
            corePoolSize=@Integer[20],
            maximumPoolSize=@Integer[64],
            defaultHandler=@AbortPolicy[java.util.concurrent.ThreadPoolExecutor$AbortPolicy@22bf7249],
            shutdownPerm=@RuntimePermission[("java.lang.RuntimePermission" "modifyThread")],
            acc=null,
            ONLY_ONE=@Boolean[true],
            $assertionsDisabled=@Boolean[true],
        ],
        consumerGroup=@String[CID_prod_im_notify_build_pdf_message],
        scheduledExecutorService=@DelegatedScheduledExecutorService[
            e=@ScheduledThreadPoolExecutor[java.util.concurrent.ScheduledThreadPoolExecutor@397bf51c[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]],
            e=@ScheduledThreadPoolExecutor[java.util.concurrent.ScheduledThreadPoolExecutor@397bf51c[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]],
            $assertionsDisabled=@Boolean[true],
        ],
        cleanExpireMsgExecutors=@DelegatedScheduledExecutorService[
            e=@ScheduledThreadPoolExecutor[java.util.concurrent.ScheduledThreadPoolExecutor@11899700[Running, pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]],
            e=@ScheduledThreadPoolExecutor[java.util.concurrent.ScheduledThreadPoolExecutor@11899700[Running, pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]],
            $assertionsDisabled=@Boolean[true],
        ],
    ],
    null,
]
posted @ 2020-12-10 18:33  damiao_hungry  阅读(193)  评论(0编辑  收藏  举报