全站最硬核 百万字强肝RocketMq源码 火热更新中~(三十六)

2022/1/23 12:04:50

本文主要是介绍全站最硬核 百万字强肝RocketMq源码 火热更新中~(三十六),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

org.apache.rocketmq.client.impl.factory.MQClientInstance

MQ客户端实例。进来之后又先是声明:

private final static long LOCK_TIMEOUT_MILLIS = 3000;
private final InternalLogger log = ClientLogger.getLog();
private final ClientConfig clientConfig;
private final int instanceIndex;
private final String clientId;
private final long bootTimestamp = System.currentTimeMillis();
private final ConcurrentMap<String/* group */, MQProducerInner> producerTable = new ConcurrentHashMap<String, MQProducerInner>();
private final ConcurrentMap<String/* group */, MQConsumerInner> consumerTable = new ConcurrentHashMap<String, MQConsumerInner>();
private final ConcurrentMap<String/* group */, MQAdminExtInner> adminExtTable = new ConcurrentHashMap<String, MQAdminExtInner>();
private final NettyClientConfig nettyClientConfig;
private final MQClientAPIImpl mQClientAPIImpl;
private final MQAdminImpl mQAdminImpl;

由于这个MQ客户端示例内容实在太多,所以我先拉出一部分声明,而且内部我们还没读过的类很多,一个一个来。

org.apache.rocketmq.client.ClientConfig

首先是一个客户端通用配置类,看看里面都配了什么。

public static final String SEND_MESSAGE_WITH_VIP_CHANNEL_PROPERTY = "com.rocketmq.sendMessageWithVIPChannel";
private String namesrvAddr = NameServerAddressUtils.getNameServerAddresses();
private String clientIP = RemotingUtil.getLocalAddress();
private String instanceName = System.getProperty("rocketmq.client.name", "DEFAULT");
private int clientCallbackExecutorThreads = Runtime.getRuntime().availableProcessors();
protected String namespace;
protected AccessChannel accessChannel = AccessChannel.LOCAL;

首先又是一系列的声明(头疼),纯字符串的我们就不看了,比如第一个:使用VIP通道发送消息。看下第二行,获取NameServer地址:

org.apache.rocketmq.common.utils.NameServerAddressUtils

这个类不是特别大,我们都看下。

public static String getNameServerAddresses() {
    return System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, System.getenv(MixAll.NAMESRV_ADDR_ENV));
}

获取nameServer地址,其实是从系统缓存中取的,也就是

public static String getProperty(String key, String def)

这个方法,其实rocketMQ底层不少地方都这样的,先前也看到了,直接把一些不大的变量(如地址)存到了系统缓存中。



这篇关于全站最硬核 百万字强肝RocketMq源码 火热更新中~(三十六)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程