全站最硬核 百万字强肝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底层不少地方都这样的,先前也看到了,直接把一些不大的变量(如地址)存到了系统缓存中。

上一篇:flutter —— getx 中各种工具方法


下一篇:netty系列之:请netty再爱UDT一次