手撕RocketMQ源码——PullMessageService

引言

  • 拉取消息的管理类。
  • 接收拉取消息请求,触发拉取消息流程
  • 提供多种请求的方法,立即执行和延迟执行

运行方法

public void run() {
     
        log.info(this.getServiceName() + " service started");

        while (!this.isStopped()) {
     
            try {
     
                PullRequest pullRequest = this.pullRequestQueue.take();
                this.pullMessage(pullRequest);
            } catch (InterruptedException ignored) {
     
            } catch (Exception e) {
     
                log.error("Pull Message Service Run Method exception", e);
            }
        }

        log.info(this.getServiceName() + " service end");
    }
private void pullMessage(final PullRequest pullRequest) {
     
        final MQConsumerInner consumer = this.mQClientFactory.selectConsumer(pullRequest.getConsumerGroup());
        if (consumer != null) {
     
            DefaultMQPushConsumerImpl impl = (DefaultMQPushConsumerImpl) consumer;
            impl.pullMessage(pullRequest);
        } else {
     
            log.warn("No matched consumer for the PullRequest {}, drop it", pullRequest);
        }
    }

你可能感兴趣的:(RocketMQ源码分析)