Search in sources :

Example 1 with Command

use of com.rabbitmq.client.Command in project LinkAgent by shulieTech.

the class ChannelNProcessDeliveryInterceptor method beforeFirst.

@Override
public void beforeFirst(Advice advice) {
    Object[] args = advice.getParameterArray();
    String methodName = advice.getBehaviorName();
    if (!PradarSwitcher.isClusterTestEnabled()) {
        logger.warn("PradarSwitcher isClusterTestEnabled false, {} to start shadow {} skip it", advice.getTargetClass().getName(), methodName);
        return;
    }
    AMQP.Basic.Deliver m = (AMQP.Basic.Deliver) args[1];
    validatePressureMeasurement(m.getConsumerTag());
    try {
        Command command = (Command) args[0];
        BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
        Map<String, Object> headers = contentHeader.getHeaders();
        if (null != headers && headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY) != null && ClusterTestUtils.isClusterTestRequest(headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY).toString())) {
            Pradar.setClusterTest(true);
        }
        if (!Pradar.isClusterTest()) {
            String routingKey = m.getRoutingKey();
            if (StringUtils.isNotBlank(routingKey) && ClusterTestUtils.isClusterTestRequest(routingKey)) {
                Pradar.setClusterTest(true);
            }
            String exchange = m.getExchange();
            if (StringUtils.isNotBlank(exchange) && ClusterTestUtils.isClusterTestRequest(exchange)) {
                Pradar.setClusterTest(true);
            }
        }
    } catch (Throwable e) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : Deliver(com.rabbitmq.client.impl.AMQImpl.Basic.Deliver) AMQP(com.rabbitmq.client.AMQP) Command(com.rabbitmq.client.Command) BasicProperties(com.rabbitmq.client.BasicProperties) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 2 with Command

use of com.rabbitmq.client.Command in project LinkAgent by shulieTech.

the class ChannelNProcessDeliveryInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    if (ConfigCache.isWorkWithSpring()) {
        return null;
    }
    Object[] args = advice.getParameterArray();
    Command command = (Command) args[0];
    Deliver method = (Deliver) args[1];
    SpanRecord record = new SpanRecord();
    record.setService(method.getExchange());
    record.setMethod(method.getRoutingKey());
    BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
    Map<String, Object> headers = contentHeader.getHeaders();
    if (headers != null) {
        Map<String, String> rpcContext = new HashMap<String, String>();
        for (String key : Pradar.getInvokeContextTransformKeys()) {
            String value = ObjectUtils.toString(headers.get(key));
            if (!StringUtil.isEmpty(value)) {
                rpcContext.put(key, value);
            }
        }
        record.setContext(rpcContext);
    }
    byte[] body = command.getContentBody();
    record.setRequestSize(body.length);
    record.setRequest(body);
    Channel channel = (Channel) advice.getTarget();
    Connection connection = channel.getConnection();
    record.setRemoteIp(connection.getAddress().getHostAddress());
    record.setPort(connection.getPort() + "");
    return record;
}
Also used : Deliver(com.rabbitmq.client.impl.AMQImpl.Basic.Deliver) BasicProperties(com.rabbitmq.client.BasicProperties) HashMap(java.util.HashMap) Channel(com.rabbitmq.client.Channel) AutorecoveringChannel(com.rabbitmq.client.impl.recovery.AutorecoveringChannel) Connection(com.rabbitmq.client.Connection) AutorecoveringConnection(com.rabbitmq.client.impl.recovery.AutorecoveringConnection) AMQConnection(com.rabbitmq.client.impl.AMQConnection) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Command(com.rabbitmq.client.Command)

Aggregations

BasicProperties (com.rabbitmq.client.BasicProperties)2 Command (com.rabbitmq.client.Command)2 Deliver (com.rabbitmq.client.impl.AMQImpl.Basic.Deliver)2 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)1 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)1 AMQP (com.rabbitmq.client.AMQP)1 Channel (com.rabbitmq.client.Channel)1 Connection (com.rabbitmq.client.Connection)1 AMQConnection (com.rabbitmq.client.impl.AMQConnection)1 AutorecoveringChannel (com.rabbitmq.client.impl.recovery.AutorecoveringChannel)1 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)1 HashMap (java.util.HashMap)1