use of com.pamirs.attach.plugin.rabbitmq.common.ConsumerDetail 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.pamirs.attach.plugin.rabbitmq.common.ConsumerDetail in project LinkAgent by shulieTech.
the class ChannelNProcessDeliveryInterceptor method afterLast.
@Override
public void afterLast(final Advice advice) {
Channel channel = (Channel) advice.getTarget();
Connection connection = channel.getConnection();
Object[] args = advice.getParameterArray();
AMQP.Basic.Deliver m = (AMQP.Basic.Deliver) args[1];
String consumerTag = m.getConsumerTag();
if (Pradar.isClusterTestPrefix(consumerTag) || ChannelHolder.existsConsumer(consumerTag)) {
return;
}
// 每个connection只进来一次,一次流量带所有的影子消费者,如果失败异步任务会自动重试
OnceExecutor.execute(connection, new OnceExecutor.Consumer<Connection>() {
@Override
public void accept(Connection connection) {
List<ConsumerDetail> consumerDetails = getAllConsumersFromConnection(connection);
for (ConsumerDetail consumerDetail : consumerDetails) {
THREAD_POOL_EXECUTOR.execute(new ShadowConsumerRegisterRunnable(consumerDetail));
}
}
});
}
Aggregations