use of org.apache.rocketmq.client.consumer.listener.MessageListener in project pinpoint by naver.
the class DefaultMQPushConsumerImplStartInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
DefaultMQPushConsumerImpl consumerImpl = (DefaultMQPushConsumerImpl) target;
MessageListener messageListener = consumerImpl.getDefaultMQPushConsumer().getMessageListener();
MQClientInstanceGetter mqClientInstanceGetter = (MQClientInstanceGetter) target;
MQClientInstance mqClientInstance = mqClientInstanceGetter._$PINPOINT$_getMQClientInstance();
RemotingClient remotingClient = mqClientInstance.getMQClientAPIImpl().getRemotingClient();
if (remotingClient instanceof NettyRemotingClient) {
ChannelTablesGetter nettyRemotingClient = (ChannelTablesGetter) remotingClient;
ChannelTablesAccessor channelTablesAccessor = (ChannelTablesAccessor) messageListener;
channelTablesAccessor._$PINPOINT$_setChannelTables(nettyRemotingClient._$PINPOINT$_getChannelTables());
}
}
use of org.apache.rocketmq.client.consumer.listener.MessageListener in project LinkAgent by shulieTech.
the class ConsumerRegistry method buildMQPushConsumer.
/**
* 构建 DefaultMQPushConsumer
* 如果后续支持影子 server 模式,则直接修改此方法即可
*
* @param businessConsumer 业务消费者
* @return 返回注册的影子消费者,如果初始化失败会返回 null
*/
private static synchronized DefaultMQPushConsumer buildMQPushConsumer(DefaultMQPushConsumer businessConsumer) {
DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer();
String instanceName = getInstanceName();
if (instanceName != null && !instanceName.equals("DEFAULT")) {
defaultMQPushConsumer.setInstanceName(Pradar.CLUSTER_TEST_PREFIX + instanceName);
} else {
defaultMQPushConsumer.setInstanceName(Pradar.addClusterTestPrefix(businessConsumer.getConsumerGroup() + instanceName));
}
defaultMQPushConsumer.setNamesrvAddr(businessConsumer.getNamesrvAddr());
defaultMQPushConsumer.setConsumerGroup(Pradar.addClusterTestPrefix(businessConsumer.getConsumerGroup()));
defaultMQPushConsumer.setConsumeFromWhere(businessConsumer.getConsumeFromWhere());
defaultMQPushConsumer.setPullThresholdForQueue(businessConsumer.getPullThresholdForQueue());
final List<String> missFields = new ArrayList<String>();
try {
defaultMQPushConsumer.setPullThresholdSizeForTopic(businessConsumer.getPullThresholdSizeForTopic());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setPullThresholdSizeForQueue(businessConsumer.getPullThresholdSizeForQueue());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setPullBatchSize(businessConsumer.getPullBatchSize());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setConsumeMessageBatchMaxSize(businessConsumer.getConsumeMessageBatchMaxSize());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setConsumeThreadMax(businessConsumer.getConsumeThreadMax());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setConsumeThreadMin(businessConsumer.getConsumeThreadMin());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setInstanceName(Pradar.addClusterTestPrefix(businessConsumer.getInstanceName()));
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setAdjustThreadPoolNumsThreshold(businessConsumer.getAdjustThreadPoolNumsThreshold());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setAllocateMessageQueueStrategy(businessConsumer.getAllocateMessageQueueStrategy());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setConsumeConcurrentlyMaxSpan(businessConsumer.getConsumeConcurrentlyMaxSpan());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setConsumeTimestamp(businessConsumer.getConsumeTimestamp());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setMessageModel(businessConsumer.getMessageModel());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setMessageListener(businessConsumer.getMessageListener());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setOffsetStore(businessConsumer.getOffsetStore());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setPullInterval(businessConsumer.getPullInterval());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setSubscription(businessConsumer.getSubscription());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setUnitMode(businessConsumer.isUnitMode());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setClientCallbackExecutorThreads(businessConsumer.getClientCallbackExecutorThreads());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setClientIP(businessConsumer.getClientIP());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setHeartbeatBrokerInterval(businessConsumer.getHeartbeatBrokerInterval());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setPersistConsumerOffsetInterval(businessConsumer.getPersistConsumerOffsetInterval());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setPostSubscriptionWhenPull(businessConsumer.isPostSubscriptionWhenPull());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setUnitName(businessConsumer.getUnitName());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setUnitMode(businessConsumer.isUnitMode());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setMaxReconsumeTimes(businessConsumer.getMaxReconsumeTimes());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setSuspendCurrentQueueTimeMillis(businessConsumer.getSuspendCurrentQueueTimeMillis());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setConsumeTimeout(businessConsumer.getConsumeTimeout());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setUseTLS(businessConsumer.isUseTLS());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setLanguage(businessConsumer.getLanguage());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
try {
defaultMQPushConsumer.setVipChannelEnabled(businessConsumer.isVipChannelEnabled());
} catch (Throwable e) {
missFields.add(e.getMessage());
}
MessageListener messageListener = businessConsumer.getMessageListener();
if (messageListener != null) {
if (messageListener instanceof MessageListenerConcurrently) {
defaultMQPushConsumer.registerMessageListener((MessageListenerConcurrently) messageListener);
} else if (messageListener instanceof MessageListenerOrderly) {
defaultMQPushConsumer.registerMessageListener((MessageListenerOrderly) messageListener);
}
}
if (!missFields.isEmpty()) {
logger.warn("[RocketMQ] miss some fields: {}", Arrays.toString(missFields.toArray()));
}
ConcurrentMap<String, SubscriptionData> map = businessConsumer.getDefaultMQPushConsumerImpl().getSubscriptionInner();
boolean hasSubscribe = false;
if (map != null) {
for (Map.Entry<String, SubscriptionData> entry : map.entrySet()) {
SubscriptionData subscriptionData = entry.getValue();
String topic = entry.getKey();
if (!isPermitInitConsumer(businessConsumer, topic)) {
continue;
}
String subString = subscriptionData.getSubString();
String filterClassSource = subscriptionData.getFilterClassSource();
if (filterClassSource != null) {
try {
defaultMQPushConsumer.subscribe(Pradar.addClusterTestPrefix(topic), subString, filterClassSource);
} catch (MQClientException e) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.MQ).setErrorCode("MQ-0001").setMessage("Apache-RocketMQ消费端subscribe失败!").setDetail("topic:" + topic + " fullClassName:" + subString + " filterClassSource:" + filterClassSource + "||" + e.getMessage()).report();
logger.error("Apache-RocketMQ: subscribe shadow DefaultMQPushConsumer err! topic:{} fullClassName:{} " + "filterClassSource:{}", topic, subString, filterClassSource, e);
return null;
}
} else {
try {
defaultMQPushConsumer.subscribe(Pradar.addClusterTestPrefix(topic), subString);
} catch (MQClientException e) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.MQ).setErrorCode("MQ-0001").setMessage("Apache-RocketMQ消费端subscribe失败!").setDetail("topic:" + topic + " subExpression:" + subString + "||" + e.getMessage()).report();
logger.error("Apache-RocketMQ: subscribe shadow DefaultMQPushConsumer err! topic:{} subExpression:{}", topic, subString, e);
return null;
}
}
hasSubscribe = true;
}
if (hasSubscribe) {
return defaultMQPushConsumer;
}
}
return null;
}
use of org.apache.rocketmq.client.consumer.listener.MessageListener in project pinpoint by pinpoint-apm.
the class DefaultMQPushConsumerImplStartInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
DefaultMQPushConsumerImpl consumerImpl = (DefaultMQPushConsumerImpl) target;
MessageListener messageListener = consumerImpl.getDefaultMQPushConsumer().getMessageListener();
MQClientInstanceGetter mqClientInstanceGetter = (MQClientInstanceGetter) target;
MQClientInstance mqClientInstance = mqClientInstanceGetter._$PINPOINT$_getMQClientInstance();
RemotingClient remotingClient = mqClientInstance.getMQClientAPIImpl().getRemotingClient();
if (remotingClient instanceof NettyRemotingClient) {
ChannelTablesGetter nettyRemotingClient = (ChannelTablesGetter) remotingClient;
ChannelTablesAccessor channelTablesAccessor = (ChannelTablesAccessor) messageListener;
channelTablesAccessor._$PINPOINT$_setChannelTables(nettyRemotingClient._$PINPOINT$_getChannelTables());
}
}
Aggregations