相关文章
启动流程:
consumer将自己注册.
每个consumer都有一个pullMessageSrvice,启动线程接受pullReques.
第一个pullReuqest是balanceService里发出的.
RequestCode.pull_message
最终汇总到pullAPIWrapper.pullKernelImpl去请求 ?
为什么说拉数据都是在一个线程里拉取的,不是很懂?
消费数据是每个consumer都有N个线程,在最外层的consumer DefaultMQPushConsumer(主要配置对应配置)里. 封装了真正的DefaultMQPushConsumerImpl实现类.
每个消费者实例都有消费线程,可配置订阅哪些topic. N个消费者实例最终都对应一个MQClientInstance (原因,clientId都是默认值)
public MQClientInstance getAndCreateMQClientInstance(final ClientConfig clientConfig, RPCHook rpcHook) {
String clientId = clientConfig.buildMQClientId();
MQClientInstance instance = this.factoryTable.get(clientId);
if (null == instance) {
instance =
new MQClientInstance(clientConfig.cloneClientConfig(),
this.factoryIndexGenerator.getAndIncrement(), clientId, rpcHook);
MQClientInstance prev = this.factoryTable.putIfAbsent(clientId, instance);
if (prev != null) {
instance = prev;
} else {
// TODO log
}
}
return instance;
}
this.mQClientFactory =
MQClientManager.getInstance().getAndCreateMQClientInstance(this.defaultMQPullConsumer,
this.rpcHook);