Search in sources :

Example 6 with ConsumeMessageContext

use of com.alibaba.rocketmq.client.hook.ConsumeMessageContext 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(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 7 with ConsumeMessageContext

use of com.alibaba.rocketmq.client.hook.ConsumeMessageContext in project LinkAgent by shulieTech.

the class ConcurrentlyTraceInterceptor method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    try {
        MessageQueue messageQueue = getMessageQueue(advice.getTarget());
        List<MessageExt> messageExts = getMessages(advice.getTarget());
        String consumeGroup = getConsumeGroup(advice.getTarget());
        if (messageExts == null || messageExts.isEmpty()) {
            return;
        }
        ConsumeMessageContext consumeMessageContext = new ConsumeMessageContext();
        consumeMessageContext.setConsumerGroup(consumeGroup);
        consumeMessageContext.setMq(messageQueue);
        consumeMessageContext.setMsgList(messageExts);
        consumeMessageContext.setSuccess(false);
        hook.consumeMessageBefore(consumeMessageContext);
        contextThreadLocal.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 : MessageExt(com.alibaba.rocketmq.common.message.MessageExt) 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)

Aggregations

ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)7 PradarException (com.pamirs.pradar.exception.PradarException)6 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)6 MessageQueue (com.alibaba.rocketmq.common.message.MessageQueue)3 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)2 PullResult (com.alibaba.rocketmq.client.consumer.PullResult)1 ConsumeOrderlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus)1 DefaultMQPullConsumerImpl (com.alibaba.rocketmq.client.impl.consumer.DefaultMQPullConsumerImpl)1 List (java.util.List)1