Example usage for com.rabbitmq.client.impl AMQConnection getFrameHandler

List of usage examples for com.rabbitmq.client.impl AMQConnection getFrameHandler

Introduction

In this page you can find the example usage for com.rabbitmq.client.impl AMQConnection getFrameHandler.

Prototype

public FrameHandler getFrameHandler() 

Source Link

Usage

From source file:com.navercorp.pinpoint.plugin.rabbitmq.client.interceptor.RabbitMQConsumerDispatchInterceptor.java

License:Apache License

private void recordRootSpan(SpanRecorder recorder, Connection connection, Envelope envelope,
        Map<String, Object> headers) {
    recorder.recordServiceType(RabbitMQClientConstants.RABBITMQ_CLIENT);
    recorder.recordApi(CONSUMER_ENTRY_METHOD_DESCRIPTOR);

    String endPoint = RabbitMQClientConstants.UNKNOWN;
    String remoteAddress = RabbitMQClientConstants.UNKNOWN;
    if (connection instanceof AMQConnection) {
        AMQConnection amqConnection = (AMQConnection) connection;
        FrameHandler frameHandler = amqConnection.getFrameHandler();
        // Endpoint should be the local socket address of the consumer.
        if (frameHandler instanceof LocalAddressAccessor) {
            endPoint = ((LocalAddressAccessor) frameHandler)._$PINPOINT$_getLocalAddress();
        }/*from  w  w  w.jav  a2  s  .  com*/
        // Remote address is the socket address of where the consumer is connected to.
        if (frameHandler instanceof RemoteAddressAccessor) {
            remoteAddress = ((RemoteAddressAccessor) frameHandler)._$PINPOINT$_getRemoteAddress();
        }
    }
    recorder.recordEndPoint(endPoint);
    recorder.recordRemoteAddress(remoteAddress);

    String exchange = envelope.getExchange();
    if (StringUtils.isEmpty(exchange)) {
        exchange = RabbitMQClientConstants.UNKNOWN;
    }
    recorder.recordRpcName("rabbitmq://exchange=" + exchange);
    recorder.recordAcceptorHost("exchange-" + exchange);
    if (isDebug) {
        logger.debug("endPoint={}->{}", envelope.getExchange(), exchange);
    }
    recorder.recordAttribute(RabbitMQClientConstants.RABBITMQ_ROUTINGKEY_ANNOTATION_KEY,
            envelope.getRoutingKey());

    if (!MapUtils.isEmpty(headers)) {
        Object parentApplicationName = headers.get(RabbitMQClientConstants.META_PARENT_APPLICATION_NAME);
        if (!recorder.isRoot() && parentApplicationName != null) {
            Object parentApplicationType = headers.get(RabbitMQClientConstants.META_PARENT_APPLICATION_TYPE);
            recorder.recordParentApplication(parentApplicationName.toString(),
                    NumberUtils.parseShort(parentApplicationType.toString(), ServiceType.UNDEFINED.getCode()));
        }
    }
}

From source file:com.navercorp.pinpoint.plugin.rabbitmq.client.interceptor.RabbitMQConsumerHandleCompleteInboundCommandInterceptor.java

License:Apache License

private void recordRootSpan(SpanRecorder recorder, AMQConnection amqConnection, String exchange,
        String routingKey, Map<String, Object> headers) {
    recorder.recordServiceType(RabbitMQClientConstants.RABBITMQ_CLIENT);
    recorder.recordApi(CONSUMER_ENTRY_METHOD_DESCRIPTOR);

    String endPoint = RabbitMQClientConstants.UNKNOWN;
    String remoteAddress = RabbitMQClientConstants.UNKNOWN;
    if (amqConnection != null) {
        FrameHandler frameHandler = amqConnection.getFrameHandler();
        // Endpoint should be the local socket address of the consumer.
        if (frameHandler instanceof LocalAddressAccessor) {
            endPoint = ((LocalAddressAccessor) frameHandler)._$PINPOINT$_getLocalAddress();
        }/*from  ww w  .j av  a  2 s.  c o m*/
        // Remote address is the socket address of where the consumer is connected to.
        if (frameHandler instanceof RemoteAddressAccessor) {
            remoteAddress = ((RemoteAddressAccessor) frameHandler)._$PINPOINT$_getRemoteAddress();
        }
    }
    recorder.recordEndPoint(endPoint);
    recorder.recordRemoteAddress(remoteAddress);

    String convertedExchange = exchange;
    if (StringUtils.isEmpty(convertedExchange)) {
        convertedExchange = RabbitMQClientConstants.UNKNOWN;
    }
    recorder.recordRpcName("rabbitmq://exchange=" + convertedExchange);
    recorder.recordAcceptorHost("exchange-" + convertedExchange);
    if (isDebug) {
        logger.debug("endPoint={}->{}", exchange, convertedExchange);
    }
    recorder.recordAttribute(RabbitMQClientConstants.RABBITMQ_ROUTINGKEY_ANNOTATION_KEY, routingKey);

    if (!MapUtils.isEmpty(headers)) {
        Object parentApplicationName = headers.get(RabbitMQClientConstants.META_PARENT_APPLICATION_NAME);
        if (!recorder.isRoot() && parentApplicationName != null) {
            Object parentApplicationType = headers.get(RabbitMQClientConstants.META_PARENT_APPLICATION_TYPE);
            recorder.recordParentApplication(parentApplicationName.toString(),
                    NumberUtils.parseShort(parentApplicationType.toString(), ServiceType.UNDEFINED.getCode()));
        }
    }
}