Search in sources :

Example 1 with ChannelManager

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;
}
Also used : ChannelManager(com.rabbitmq.client.impl.ChannelManager) AMQConnection(com.rabbitmq.client.impl.AMQConnection) Channel(com.rabbitmq.client.Channel) AutorecoveringChannel(com.rabbitmq.client.impl.recovery.AutorecoveringChannel) ArrayList(java.util.ArrayList) ConsumerDetail(com.pamirs.attach.plugin.rabbitmq.common.ConsumerDetail) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Consumer(com.rabbitmq.client.Consumer) ChannelN(com.rabbitmq.client.impl.ChannelN) Map(java.util.Map) HashMap(java.util.HashMap) SocketFrameHandler(com.rabbitmq.client.impl.SocketFrameHandler) AutorecoveringConnection(com.rabbitmq.client.impl.recovery.AutorecoveringConnection) HashSet(java.util.HashSet)

Example 2 with ChannelManager

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;
}
Also used : ChannelManager(com.rabbitmq.client.impl.ChannelManager) AMQConnection(com.rabbitmq.client.impl.AMQConnection) ExecutorService(java.util.concurrent.ExecutorService) ConsumerWorkService(com.rabbitmq.client.impl.ConsumerWorkService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) TimeoutException(java.util.concurrent.TimeoutException) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) IOException(java.io.IOException)

Aggregations

AMQConnection (com.rabbitmq.client.impl.AMQConnection)2 ChannelManager (com.rabbitmq.client.impl.ChannelManager)2 Map (java.util.Map)2 ConsumerDetail (com.pamirs.attach.plugin.rabbitmq.common.ConsumerDetail)1 Channel (com.rabbitmq.client.Channel)1 Consumer (com.rabbitmq.client.Consumer)1 ChannelN (com.rabbitmq.client.impl.ChannelN)1 ConsumerWorkService (com.rabbitmq.client.impl.ConsumerWorkService)1 SocketFrameHandler (com.rabbitmq.client.impl.SocketFrameHandler)1 AutorecoveringChannel (com.rabbitmq.client.impl.recovery.AutorecoveringChannel)1 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)1 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1