use of com.rabbitmq.client.impl.recovery.AutorecoveringChannel 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.recovery.AutorecoveringChannel in project LinkAgent by shulieTech.
the class AutorecoveringChannelConsumerMetaDataBuilder method tryBuild.
@Override
public ConsumerMetaData tryBuild(ConsumerDetail consumerDetail) {
String consumerTag = consumerDetail.getConsumerTag();
Consumer consumer = consumerDetail.getConsumer();
Channel channel = unWrapChannel(consumerDetail.getChannel(), consumerTag, consumer);
if (!(channel instanceof AutorecoveringChannel)) {
return null;
}
/*
如果一个connection有多个channel,这多个channel之间又有相同的consumer tag订阅不同的queue,那么这里就有问题。
因为consumer_tag对于connection来说不是唯一的,对于channel才是唯一的,最早订阅的conusmer会被覆盖
rabbitmq client的内部实现就是有bug,see : AutorecoveringConnection#recordConsumer,
所以应该不太会出现重复consumer tag的情况,这里就先不考虑相同consumer tag在同一个connection的情况
*/
RecordedConsumer recordedConsumer = getRecordedConsumer(channel, consumerTag);
return new ConsumerMetaData((String) Reflect.on(recordedConsumer).get("queue"), consumerTag, consumer, (Boolean) Reflect.on(recordedConsumer).get("exclusive"), (Boolean) Reflect.on(recordedConsumer).get("autoAck"), (Integer) Reflect.on(channel).get("prefetchCountConsumer"), false);
}
Aggregations