Search in sources :

Example 1 with MessageListener

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());
    }
}
Also used : DefaultMQPushConsumerImpl(org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl) NettyRemotingClient(org.apache.rocketmq.remoting.netty.NettyRemotingClient) RemotingClient(org.apache.rocketmq.remoting.RemotingClient) MQClientInstanceGetter(com.navercorp.pinpoint.plugin.rocketmq.field.accessor.MQClientInstanceGetter) ChannelTablesAccessor(com.navercorp.pinpoint.plugin.rocketmq.field.accessor.ChannelTablesAccessor) ChannelTablesGetter(com.navercorp.pinpoint.plugin.rocketmq.field.accessor.ChannelTablesGetter) MessageListener(org.apache.rocketmq.client.consumer.listener.MessageListener) NettyRemotingClient(org.apache.rocketmq.remoting.netty.NettyRemotingClient) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance)

Example 2 with MessageListener

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;
}
Also used : MessageListenerConcurrently(org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently) MessageListenerOrderly(org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly) ArrayList(java.util.ArrayList) MessageListener(org.apache.rocketmq.client.consumer.listener.MessageListener) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentWeakHashMap(com.shulie.instrument.simulator.message.ConcurrentWeakHashMap) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 3 with MessageListener

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());
    }
}
Also used : DefaultMQPushConsumerImpl(org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl) NettyRemotingClient(org.apache.rocketmq.remoting.netty.NettyRemotingClient) RemotingClient(org.apache.rocketmq.remoting.RemotingClient) MQClientInstanceGetter(com.navercorp.pinpoint.plugin.rocketmq.field.accessor.MQClientInstanceGetter) ChannelTablesAccessor(com.navercorp.pinpoint.plugin.rocketmq.field.accessor.ChannelTablesAccessor) ChannelTablesGetter(com.navercorp.pinpoint.plugin.rocketmq.field.accessor.ChannelTablesGetter) MessageListener(org.apache.rocketmq.client.consumer.listener.MessageListener) NettyRemotingClient(org.apache.rocketmq.remoting.netty.NettyRemotingClient) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance)

Aggregations

MessageListener (org.apache.rocketmq.client.consumer.listener.MessageListener)3 ChannelTablesAccessor (com.navercorp.pinpoint.plugin.rocketmq.field.accessor.ChannelTablesAccessor)2 ChannelTablesGetter (com.navercorp.pinpoint.plugin.rocketmq.field.accessor.ChannelTablesGetter)2 MQClientInstanceGetter (com.navercorp.pinpoint.plugin.rocketmq.field.accessor.MQClientInstanceGetter)2 DefaultMQPushConsumerImpl (org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl)2 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)2 RemotingClient (org.apache.rocketmq.remoting.RemotingClient)2 NettyRemotingClient (org.apache.rocketmq.remoting.netty.NettyRemotingClient)2 ConcurrentWeakHashMap (com.shulie.instrument.simulator.message.ConcurrentWeakHashMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)1 MessageListenerConcurrently (org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently)1 MessageListenerOrderly (org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)1