Search in sources :

Example 46 with PradarException

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

the class PushConsumeMessageHookImpl method consumeMessageBefore.

@Override
public void consumeMessageBefore(ConsumeMessageContext context) {
    try {
        if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
            return;
        }
        MQTraceContext mqTraceContext = new MQTraceContext();
        contexts.put(context, mqTraceContext);
        mqTraceContext.setMqType(MQType.ROCKETMQ);
        mqTraceContext.setTopic(context.getMq().getTopic());
        mqTraceContext.setGroup(context.getConsumerGroup());
        boolean silence = PradarService.isSilence();
        List<MQTraceBean> beans = new ArrayList<MQTraceBean>();
        for (MessageExt msg : context.getMsgList()) {
            if (msg == null) {
                continue;
            }
            MQTraceBean traceBean = new MQTraceBean();
            boolean isClusterTest = msg.getTopic() != null && (Pradar.isClusterTestPrefix(msg.getTopic()) || Pradar.isClusterTestPrefix(msg.getTopic(), RETRYSTR) || Pradar.isClusterTestPrefix(msg.getTopic(), DLQSTR));
            // 消息的properties是否包含Pradar.PRADAR_CLUSTER_TEST_KEY
            isClusterTest = isClusterTest || ClusterTestUtils.isClusterTestRequest(msg.getProperty(PradarService.PRADAR_CLUSTER_TEST_KEY));
            if (isClusterTest) {
                traceBean.setClusterTest(Boolean.TRUE.toString());
            }
            if (silence && isClusterTest) {
                throw new PressureMeasureError(this.getClass().getName() + ":silence module ! can not handle cluster test data");
            }
            Map<String, String> rpcContext = new HashMap<String, String>();
            for (String key : Pradar.getInvokeContextTransformKeys()) {
                String value = msg.getProperty(key);
                if (value != null) {
                    rpcContext.put(key, value);
                }
            }
            traceBean.setContext(rpcContext);
            traceBean.setTopic(msg.getTopic());
            traceBean.setMsgId(msg.getMsgId());
            traceBean.setOriginMsgId(MessageAccessor.getOriginMessageId(msg));
            traceBean.setTags(msg.getTags());
            traceBean.setKeys(msg.getKeys());
            traceBean.setBuyerId(msg.getBuyerId());
            traceBean.setTransferFlag(MessageAccessor.getTransferFlag(msg));
            traceBean.setCorrectionFlag(MessageAccessor.getCorrectionFlag(msg));
            traceBean.setBodyLength(msg.getBody().length);
            traceBean.setBornHost(StringUtils.substring(msg.getBornHost().toString(), 1));
            String storeHost = "";
            String port = "";
            if (msg.getStoreHost() != null && msg.getStoreHost() instanceof InetSocketAddress) {
                InetSocketAddress address = (InetSocketAddress) msg.getStoreHost();
                storeHost = address.getAddress() == null ? null : address.getAddress().getHostAddress();
                port = String.valueOf(address.getPort());
            } else {
                storeHost = StringUtils.substring(msg.getStoreHost().toString(), 1);
            }
            traceBean.setStoreHost(storeHost);
            traceBean.setPort(port);
            traceBean.setStoreTime(msg.getStoreTimestamp());
            traceBean.setBrokerName(context.getMq().getBrokerName());
            traceBean.setQueueId(msg.getQueueId());
            traceBean.setOffset(msg.getQueueOffset());
            traceBean.setRetryTimes(msg.getReconsumeTimes());
            traceBean.setProps(context.getProps());
            beans.add(traceBean);
        }
        mqTraceContext.setTraceBeans(beans);
        MQConsumeMessageTraceLog.consumeMessageBefore(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 : PradarException(com.pamirs.pradar.exception.PradarException) HashMap(java.util.HashMap) ConcurrentWeakHashMap(com.shulie.instrument.simulator.message.ConcurrentWeakHashMap) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) MQTraceBean(com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean) MessageExt(com.alibaba.rocketmq.common.message.MessageExt) MQTraceContext(com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

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