Example usage for com.rabbitmq.client.impl AMQCommand getMethod

List of usage examples for com.rabbitmq.client.impl AMQCommand getMethod

Introduction

In this page you can find the example usage for com.rabbitmq.client.impl AMQCommand getMethod.

Prototype

@Override
public Method getMethod() 

Source Link

Document

Public API -

Usage

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

License:Apache License

@Override
public void before(Object target, Object[] args) {
    if (!validate(target, args)) {
        return;//from   w w  w .  ja  v a  2s.co m
    }
    AMQCommand command = (AMQCommand) args[0];
    Method method = command.getMethod();
    if (!(method instanceof AMQP.Basic.GetOk)) {
        return;
    }
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        AMQChannel channel = (AMQChannel) target;
        final Trace trace = createTrace(channel, command);
        if (trace == null) {
            return;
        }
        if (!trace.canSampled()) {
            return;
        }
        SpanEventRecorder recorder = trace.traceBlockBegin();
        recorder.recordServiceType(RabbitMQClientConstants.RABBITMQ_CLIENT_INTERNAL);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
        }
    }
}

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

License:Apache License

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (!validate(target, args)) {
        return;/*  w ww .j  av a  2  s  .c  o  m*/
    }
    AMQCommand command = (AMQCommand) args[0];
    Method method = command.getMethod();
    if (!(method instanceof AMQP.Basic.GetOk)) {
        return;
    }
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        traceContext.removeTraceObject();
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        if (throwable != null) {
            recorder.recordException(throwable);
        }
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER. Caused:{}", th.getMessage(), th);
        }
    } finally {
        traceContext.removeTraceObject();
        trace.traceBlockEnd();
        trace.close();
    }
}

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

License:Apache License

private Trace createTrace(AMQChannel amqChannel, AMQCommand amqCommand) {
    AMQConnection connection = amqChannel.getConnection();
    if (connection == null) {
        logger.debug("connection is null, skipping trace");
    }/* ww  w .  j  ava  2s.c om*/

    Method method = amqCommand.getMethod();
    AMQP.Basic.GetOk getOk = (AMQP.Basic.GetOk) method;
    String exchange = getOk.getExchange();
    if (RabbitMQClientPluginConfig.isExchangeExcluded(exchange, excludeExchangeFilter)) {
        if (isDebug) {
            logger.debug("exchange {} is excluded", exchange);
        }
        return null;
    }
    String routingKey = getOk.getRoutingKey();

    Map<String, Object> headers = getHeadersFromContentHeader(amqCommand.getContentHeader());

    // If this transaction is not traceable, mark as disabled.
    if (headers.get(RabbitMQClientConstants.META_SAMPLED) != null) {
        return traceContext.disableSampling();
    }

    final TraceId traceId = populateTraceIdFromRequest(headers);
    // If there's no trasanction id, a new trasaction begins here.
    final Trace trace = traceId == null ? traceContext.newTraceObject()
            : traceContext.continueTraceObject(traceId);
    if (trace.canSampled()) {
        final SpanRecorder recorder = trace.getSpanRecorder();
        recordRootSpan(recorder, connection, exchange, routingKey, headers);
    }
    return trace;
}

From source file:de.htwk_leipzig.bis.connection.handshake.clientRewrite.AMQChannel.java

License:Mozilla Public License

public void quiescingTransmit(AMQCommand c) throws IOException {
    synchronized (_channelMutex) {
        if (c.getMethod().hasContent()) {
            while (_blockContent) {
                try {
                    _channelMutex.wait();
                } catch (InterruptedException e) {
                }/* w w  w . j  a v  a  2  s  .c o  m*/

                // This is to catch a situation when the thread wakes up
                // during
                // shutdown. Currently, no command that has content is
                // allowed
                // to send anything in a closing state.
                ensureIsOpen();
            }
        }
        c.transmit(this);
    }
}