Search in sources :

Example 1 with Deliver

use of com.rabbitmq.client.impl.AMQImpl.Basic.Deliver 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

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