org.apache.rocketmq.client.hook.ConsumeMessageContext Java Examples

The following examples show how to use org.apache.rocketmq.client.hook.ConsumeMessageContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsumerConsumeMessageHook.java    From pepper-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public void consumeMessageAfter(ConsumeMessageContext context) {
    final Long beginTime = beginTimeCache.remove(context);
    final String[] tags = tags(context);
    stats.decConc(tags);
    stats.observe(System.currentTimeMillis() - beginTime, tags);
    final Map<String, String> props = context.getProps();
    final String returnType = props.getOrDefault(MixAll.CONSUME_CONTEXT_TYPE, ConsumeReturnType.FAILED.name());
    if (StringUtils.equals(returnType, ConsumeReturnType.EXCEPTION.name())) {
        stats.error(tags);
    }
    Counter.builder(METRICS_NAME_RETURN_TYPE)
            .tags(Tags.of(tags).and("returnType", returnType))
            .register(MetricsRegistry.getREGISTRY())
            .increment();
}
 
Example #2
Source File: OnsConsumeMessageHookImpl.java    From rocketmq-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Override
public void consumeMessageAfter(ConsumeMessageContext context) {
    if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
        return;
    }
    OnsTraceContext subBeforeContext = (OnsTraceContext) context.getMqTraceContext();
    OnsTraceContext subAfterContext = new OnsTraceContext();
    subAfterContext.setTraceType(OnsTraceType.SubAfter);//
    subAfterContext.setRegionId(subBeforeContext.getRegionId());//
    subAfterContext.setGroupName(subBeforeContext.getGroupName());//
    subAfterContext.setRequestId(subBeforeContext.getRequestId());//
    subAfterContext.setSuccess(context.isSuccess());//
    // 批量消息全部处理完毕的平均耗时
    int costTime = (int) ((System.currentTimeMillis() - subBeforeContext.getTimeStamp()) / context.getMsgList().size());
    subAfterContext.setCostTime(costTime);//
    subAfterContext.setTraceBeans(subBeforeContext.getTraceBeans());
    localDispatcher.append(subAfterContext);
}
 
Example #3
Source File: DefaultMQPullConsumerImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #4
Source File: DefaultMQPullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #5
Source File: DefaultMQPullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #6
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #7
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #8
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #9
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #10
Source File: DefaultMQPushConsumerImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #11
Source File: DefaultMQPushConsumerImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #12
Source File: DefaultMQPullConsumerImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #13
Source File: DefaultMQPushConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #14
Source File: OnsConsumeMessageHookImpl.java    From rocketmq-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
    public void consumeMessageBefore(ConsumeMessageContext context) {
        if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
            return;
        }
        OnsTraceContext onsTraceContext = new OnsTraceContext();
        context.setMqTraceContext(onsTraceContext);
        onsTraceContext.setTraceType(OnsTraceType.SubBefore);//
        onsTraceContext.setGroupName(context.getConsumerGroup());//
        List<OnsTraceBean> beans = new ArrayList<OnsTraceBean>();
        for (MessageExt msg : context.getMsgList()) {
            if (msg == null) {
                continue;
            }
            OnsTraceBean traceBean = new OnsTraceBean();
            traceBean.setTopic(msg.getTopic());//
            traceBean.setMsgId(msg.getMsgId());//
            traceBean.setTags(msg.getTags());//
            traceBean.setKeys(msg.getKeys());//
//            InetSocketAddress host;
//            // host = (InetSocketAddress) msg.getBornHost();
//            // traceBean.setClientHost(host.getHostName());//
//
//            host = (InetSocketAddress) msg.getStoreHost();
//            traceBean.setStoreHost(host.getHostName());//
            traceBean.setStoreTime(msg.getStoreTimestamp());//
            traceBean.setBodyLength(msg.getStoreSize());//
            traceBean.setRetryTimes(msg.getReconsumeTimes());//
            beans.add(traceBean);
        }
        onsTraceContext.setTraceBeans(beans);
        onsTraceContext.setTimeStamp(System.currentTimeMillis());
        localDispatcher.append(onsTraceContext);
    }
 
Example #15
Source File: ConsumeMessageTraceHookImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void consumeMessageBefore(ConsumeMessageContext context) {
    if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
        return;
    }
    TraceContext traceContext = new TraceContext();
    context.setMqTraceContext(traceContext);
    traceContext.setTraceType(TraceType.SubBefore);//
    traceContext.setGroupName(NamespaceUtil.withoutNamespace(context.getConsumerGroup()));//
    List<TraceBean> beans = new ArrayList<TraceBean>();
    for (MessageExt msg : context.getMsgList()) {
        if (msg == null) {
            continue;
        }
        String regionId = msg.getProperty(MessageConst.PROPERTY_MSG_REGION);
        String traceOn = msg.getProperty(MessageConst.PROPERTY_TRACE_SWITCH);

        if (traceOn != null && traceOn.equals("false")) {
            // If trace switch is false ,skip it
            continue;
        }
        TraceBean traceBean = new TraceBean();
        traceBean.setTopic(NamespaceUtil.withoutNamespace(msg.getTopic()));//
        traceBean.setMsgId(msg.getMsgId());//
        traceBean.setTags(msg.getTags());//
        traceBean.setKeys(msg.getKeys());//
        traceBean.setStoreTime(msg.getStoreTimestamp());//
        traceBean.setBodyLength(msg.getStoreSize());//
        traceBean.setRetryTimes(msg.getReconsumeTimes());//
        traceContext.setRegionId(regionId);//
        beans.add(traceBean);
    }
    if (beans.size() > 0) {
        traceContext.setTraceBeans(beans);
        traceContext.setTimeStamp(System.currentTimeMillis());
        localDispatcher.append(traceContext);
    }
}
 
Example #16
Source File: ConsumeMessageTraceHookImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void consumeMessageAfter(ConsumeMessageContext context) {
    if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
        return;
    }
    TraceContext subBeforeContext = (TraceContext) context.getMqTraceContext();

    if (subBeforeContext.getTraceBeans() == null || subBeforeContext.getTraceBeans().size() < 1) {
        // If subbefore bean is null ,skip it
        return;
    }
    TraceContext subAfterContext = new TraceContext();
    subAfterContext.setTraceType(TraceType.SubAfter);//
    subAfterContext.setRegionId(subBeforeContext.getRegionId());//
    subAfterContext.setGroupName(NamespaceUtil.withoutNamespace(subBeforeContext.getGroupName()));//
    subAfterContext.setRequestId(subBeforeContext.getRequestId());//
    subAfterContext.setSuccess(context.isSuccess());//

    // Caculate the cost time for processing messages
    int costTime = (int) ((System.currentTimeMillis() - subBeforeContext.getTimeStamp()) / context.getMsgList().size());
    subAfterContext.setCostTime(costTime);//
    subAfterContext.setTraceBeans(subBeforeContext.getTraceBeans());
    String contextType = context.getProps().get(MixAll.CONSUME_CONTEXT_TYPE);
    if (contextType != null) {
        subAfterContext.setContextCode(ConsumeReturnType.valueOf(contextType).ordinal());
    }
    localDispatcher.append(subAfterContext);
}
 
Example #17
Source File: DefaultMQPushConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #18
Source File: DefaultMQPushConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #19
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #20
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #21
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #22
Source File: DefaultMQPushConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #23
Source File: DefaultMQPullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #24
Source File: DefaultMQPullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #25
Source File: ConsumerConsumeMessageHook.java    From pepper-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public void consumeMessageBefore(ConsumeMessageContext context) {
    beginTimeCache.put(context, System.currentTimeMillis());
    final String[] tags = tags(context);
    stats.incConc(tags);

}
 
Example #26
Source File: ConsumerConsumeMessageHook.java    From pepper-metrics with Apache License 2.0 5 votes vote down vote up
private String[] tags(ConsumeMessageContext context) {
    final MessageQueue messageQueue = context.getMq();
    return new String[]{"metric",
                messageQueue.getBrokerName()
                        + "/" + messageQueue.getTopic()
                        + "/" + context.getConsumerGroup()
                        + "/Q" + messageQueue.getQueueId(),
            "broker", messageQueue.getBrokerName(),
            "namespace", namespace,
            "topic", messageQueue.getTopic(),
            "consumerGroup", context.getConsumerGroup(),
            "queueId", String.valueOf(messageQueue.getQueueId())};
}
 
Example #27
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #28
Source File: DefaultMQPushConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable e) {
            }
        }
    }
}
 
Example #29
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void executeHookBefore(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageBefore(context);
            } catch (Throwable ignored) {
            }
        }
    }
}
 
Example #30
Source File: DefaultMQPullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void executeHookAfter(final ConsumeMessageContext context) {
    if (!this.consumeMessageHookList.isEmpty()) {
        for (ConsumeMessageHook hook : this.consumeMessageHookList) {
            try {
                hook.consumeMessageAfter(context);
            } catch (Throwable ignored) {
            }
        }
    }
}