Search in sources :

Example 36 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class OrderlyTraceContextInterceptor method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    try {
        MessageQueue messageQueue = getMessageQueue(advice.getTarget());
        String consumeGroup = getConsumeGroup(advice.getTarget());
        ConsumeMessageContext consumeMessageContext = new ConsumeMessageContext();
        consumeMessageContext.setConsumerGroup(consumeGroup);
        consumeMessageContext.setMq(messageQueue);
        consumeMessageContext.setSuccess(false);
        OrderlyTraceContexts.set(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : ConsumeMessageContext(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) MessageQueue(com.alibaba.rocketmq.common.message.MessageQueue) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 37 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class OrderlyTraceAfterInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeOrderlyStatus status = (ConsumeOrderlyStatus) advice.getParameterArray()[1];
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null || consumeMessageContext.getMsgList() == null) {
            return;
        }
        consumeMessageContext.setSuccess(ConsumeOrderlyStatus.SUCCESS == status || ConsumeOrderlyStatus.COMMIT == status);
        consumeMessageContext.setStatus(status.name());
        hook.consumeMessageAfter(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    } finally {
        OrderlyTraceContexts.remove();
    }
}
Also used : ConsumeMessageContext(org.apache.rocketmq.client.hook.ConsumeMessageContext) PradarException(com.pamirs.pradar.exception.PradarException) ConsumeOrderlyStatus(org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 38 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ConcurrentlyTraceInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeMessageContext consumeMessageContext = contextThreadLocal.get();
        if (consumeMessageContext == null) {
            return;
        }
        consumeMessageContext.setSuccess(true);
        consumeMessageContext.setStatus("CONSUME_SUCCESS");
        hook.consumeMessageAfter(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    } finally {
        contextThreadLocal.remove();
    }
}
Also used : ConsumeMessageContext(org.apache.rocketmq.client.hook.ConsumeMessageContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 39 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class PulsarTraceProducerInterceptor method doBefore.

@Override
public void doBefore(Advice advice) {
    Object[] args = advice.getParameterArray();
    String methodName = advice.getBehaviorName();
    Object target = advice.getTarget();
    try {
        if (!(target instanceof org.apache.pulsar.client.impl.ProducerImpl) && methodName.equals("sendAsync")) {
            return;
        }
        ProducerImpl producer = (ProducerImpl) target;
        if (args == null || args.length != 2) {
            return;
        }
        Object messageObj = args[0];
        MessageImpl<?> message = null;
        if (messageObj instanceof MessageImpl) {
            message = (MessageImpl<?>) messageObj;
        }
        if (messageObj instanceof TopicMessageImpl) {
            TopicMessageImpl<?> topicMessage = (TopicMessageImpl<?>) messageObj;
            message = (MessageImpl<?>) topicMessage.getMessage();
        }
        if (message == null) {
            return;
        }
        MQTraceBean traceBean = new MQTraceBean();
        traceBean.setTopic(Pradar.addClusterTestPrefix(producer.getTopic()));
        traceBean.setKeys(message.getKey());
        traceBean.setBodyLength(message.getData().length);
        traceBean.setClusterTest(String.valueOf(Pradar.isClusterTest()));
        ArrayList<MQTraceBean> traceBeans = new ArrayList<MQTraceBean>(1);
        traceBeans.add(traceBean);
        MQTraceContext mqTraceContext = new MQTraceContext();
        mqTraceContext.setMqType(MQType.PULSAR);
        mqTraceContext.setGroup(producer.getProducerName() + ":" + producer.getTopic());
        mqTraceContext.setTraceBeans(traceBeans);
        MQSendMessageTraceLog.sendMessageBefore(mqTraceContext);
        PulsarApi.MessageMetadata.Builder builder = message.getMessageBuilder();
        for (Map.Entry<String, String> entry : traceBean.getContext().entrySet()) {
            builder.addProperties(org.apache.pulsar.common.api.proto.PulsarApi.KeyValue.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build());
        }
        threadLocal.set(mqTraceContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : ProducerImpl(org.apache.pulsar.client.impl.ProducerImpl) PradarException(com.pamirs.pradar.exception.PradarException) ArrayList(java.util.ArrayList) TopicMessageImpl(org.apache.pulsar.client.impl.TopicMessageImpl) MQTraceBean(com.pamirs.attach.plugin.pulsar.common.MQTraceBean) ProducerImpl(org.apache.pulsar.client.impl.ProducerImpl) MQTraceContext(com.pamirs.attach.plugin.pulsar.common.MQTraceContext) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) TopicMessageImpl(org.apache.pulsar.client.impl.TopicMessageImpl) Map(java.util.Map)

Example 40 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class SpringConsumerMetaDataBuilder method tryBuild.

@Override
public ConsumerMetaData tryBuild(ConsumerDetail consumerDetail) {
    Consumer consumer = consumerDetail.getConsumer();
    String consumerTag = consumerDetail.getConsumerTag();
    if (!consumer.getClass().getName().equals("org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$InternalConsumer")) {
        return null;
    }
    try {
        return highVersion(consumer, consumerTag);
    } catch (Throwable e) {
        logger.warn("[RabbitMQ] get ConsumerMetaData from spring rabbitmq fail, try lowVersion");
        try {
            return lowVersion(consumer, consumerTag);
        } catch (Throwable ie) {
            throw new PradarException("spring rabbitmq 版本不支持!", ie);
        }
    }
}
Also used : BlockingQueueConsumer(org.springframework.amqp.rabbit.listener.BlockingQueueConsumer) Consumer(com.rabbitmq.client.Consumer) PradarException(com.pamirs.pradar.exception.PradarException)

Aggregations

PradarException (com.pamirs.pradar.exception.PradarException)46 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)34 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)6 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 ZipException (java.util.zip.ZipException)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 KeeperException (org.apache.zookeeper.KeeperException)6 MQTraceContext (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext)5 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)4 MQTraceBean (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean)4 MQTraceBean (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceBean)4 InetSocketAddress (java.net.InetSocketAddress)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 MQTraceContext (com.pamirs.attach.plugin.pulsar.common.MQTraceContext)3 ConcurrentWeakHashMap (com.shulie.instrument.simulator.message.ConcurrentWeakHashMap)3 List (java.util.List)3 Map (java.util.Map)3 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)3