use of com.rabbitmq.client.impl.ChannelManager in project LinkAgent by shulieTech.
the class ChannelNProcessDeliveryInterceptor method getAllConsumersFromConnection.
private List<ConsumerDetail> getAllConsumersFromConnection(Connection connection) {
List<ConsumerDetail> consumerDetails = new ArrayList<ConsumerDetail>();
Set<Channel> channels = new HashSet<Channel>();
if (connection instanceof AMQConnection) {
ChannelManager _channelManager = Reflect.on(connection).get("_channelManager");
Map<Integer, ChannelN> _channelMap = Reflect.on(_channelManager).get("_channelMap");
channels.addAll(_channelMap.values());
} else if (connection instanceof AutorecoveringConnection) {
Map<Integer, AutorecoveringChannel> _channels = Reflect.on(connection).get("channels");
channels.addAll(_channels.values());
} else {
logger.error("[RabbitMQ] SIMULATOR unsupport rabbitmqConnection");
}
AMQConnection amqConnection = RabbitMqUtils.unWrapConnection(connection);
SocketFrameHandler frameHandler = Reflect.on(amqConnection).get("_frameHandler");
String localIp = frameHandler.getLocalAddress().getHostAddress();
if (isLocalHost(localIp)) {
localIp = AddressUtils.getLocalAddress();
logger.warn("[RabbitMQ] SIMULATOR get localIp from connection is localIp use {} instead", localIp);
}
int localPort = frameHandler.getLocalPort();
for (Channel channel : channels) {
ChannelN channelN = RabbitMqUtils.unWrapChannel(channel);
Map<String, Consumer> _consumers = Reflect.on(channelN).get("_consumers");
for (Entry<String, Consumer> entry : _consumers.entrySet()) {
consumerDetails.add(new ConsumerDetail(connection, entry.getKey(), channel, entry.getValue(), localIp, localPort));
}
}
return consumerDetails;
}
use of com.rabbitmq.client.impl.ChannelManager in project LinkAgent by shulieTech.
the class ChannelHolder method getThreadPoolInfoFromBiz.
private static ThreadPoolInfo getThreadPoolInfoFromBiz(Connection connection) {
if (connection instanceof AMQConnection) {
try {
ConsumerWorkService workService = Reflect.on(connection).get("_workService");
ExecutorService executorService = Reflect.on(workService).get("executor");
if (executorService instanceof ThreadPoolExecutor) {
ThreadPoolExecutor te = (ThreadPoolExecutor) executorService;
int queueSize = getQueueSize(te.getQueue());
if (isInfoEnabled) {
LOGGER.info("[RabbitMQ] biz consumer use thread pool info : [coreSize : {}, maxSize : {}, keepAliveTime : " + "{} " + "queueSize : {}]", te.getCorePoolSize(), te.getMaximumPoolSize(), te.getKeepAliveTime(TimeUnit.SECONDS), queueSize);
}
return new ThreadPoolInfo(te.getCorePoolSize(), te.getMaximumPoolSize(), (int) te.getKeepAliveTime(TimeUnit.SECONDS), queueSize);
}
} catch (Exception e) {
LOGGER.warn("[RabbitMQ] can not get executor from connection" + " try set max pool size equal channel num connection is : {}", connection.getClass().getName(), e);
try {
ChannelManager channelManager = Reflect.on(connection).get("_channelManager");
Map map = Reflect.on(channelManager).get("_channelMap");
return new ThreadPoolInfo(map.size(), map.size(), 10, Integer.MAX_VALUE);
} catch (ReflectException ex) {
LOGGER.warn("[RabbitMQ] can not get channels from connection connection is : {}", connection.getClass().getName(), e);
}
}
}
return null;
}
Aggregations