Search in sources :

Example 1 with ConsumeMessageContext

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

Example 2 with ConsumeMessageContext

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

the class PullConsumerInterceptor method doAfter.

@Override
public void doAfter(Advice advice) {
    Object[] args = advice.getParameterArray();
    Object result = advice.getReturnObj();
    if (!checkArgs(args, result)) {
        return;
    }
    DefaultMQPullConsumerImpl consumer = (DefaultMQPullConsumerImpl) advice.getTarget();
    MessageQueue mq = (MessageQueue) args[0];
    PullResult pullResult = (PullResult) result;
    ConsumeMessageContext consumeMessageContext = new ConsumeMessageContext();
    consumeMessageContext.setConsumerGroup(consumer.groupName());
    consumeMessageContext.setMq(mq);
    consumeMessageContext.setMsgList(pullResult.getMsgFoundList());
    consumeMessageContext.setSuccess(false);
    hook.consumeMessageBefore(consumeMessageContext);
    consumeMessageContext.setStatus(ConsumeConcurrentlyStatus.CONSUME_SUCCESS.toString());
    consumeMessageContext.setSuccess(true);
    hook.consumeMessageAfter(consumeMessageContext);
}
Also used : DefaultMQPullConsumerImpl(com.alibaba.rocketmq.client.impl.consumer.DefaultMQPullConsumerImpl) ConsumeMessageContext(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) MessageQueue(com.alibaba.rocketmq.common.message.MessageQueue) PullResult(com.alibaba.rocketmq.client.consumer.PullResult)

Example 3 with ConsumeMessageContext

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

the class OrderlyTraceBeforeInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null) {
            return;
        }
        List<MessageExt> messageExts = (List<MessageExt>) advice.getReturnObj();
        if (messageExts == null || messageExts.isEmpty()) {
            return;
        }
        consumeMessageContext.setMsgList(messageExts);
        PushConsumeMessageHookImpl.getInstance().consumeMessageBefore(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) MessageExt(com.alibaba.rocketmq.common.message.MessageExt) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) List(java.util.List)

Example 4 with ConsumeMessageContext

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

the class OrderlyTraceContextInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null || consumeMessageContext.getMsgList() == null) {
            return;
        }
        consumeMessageContext.setSuccess(true);
        consumeMessageContext.setStatus("SUCCESS");
        // 兜底,以免after没有执行(consumeMessageContext.getMsgList() != null 说明before 已经执行了)
        PushConsumeMessageHookImpl.getInstance().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(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 5 with ConsumeMessageContext

use of com.alibaba.rocketmq.client.hook.ConsumeMessageContext 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)

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