use of com.rabbitmq.client.impl.AMQCommand in project pinpoint by naver.
the class RabbitMQConsumerHandleCompleteInboundCommandInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (!validate(target, args)) {
return;
}
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();
}
}
use of com.rabbitmq.client.impl.AMQCommand in project rabbitmq-java-client by rabbitmq.
the class ConnectionOpen method correctProtocolHeader.
@Test
public void correctProtocolHeader() throws IOException {
SocketFrameHandler fh = new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT));
fh.sendHeader();
AMQCommand command = new AMQCommand();
while (!command.handleFrame(fh.readFrame())) {
}
Method m = command.getMethod();
assertTrue("First command must be Connection.start", m instanceof AMQP.Connection.Start);
AMQP.Connection.Start start = (AMQP.Connection.Start) m;
assertTrue("Version in Connection.start is <= what we sent", start.getVersionMajor() < AMQP.PROTOCOL.MAJOR || (start.getVersionMajor() == AMQP.PROTOCOL.MAJOR && start.getVersionMinor() <= AMQP.PROTOCOL.MINOR));
}
use of com.rabbitmq.client.impl.AMQCommand in project rabbitmq-java-client by rabbitmq.
the class AMQChannelTest method testRpcTimeoutReplyComesDuringNexRpc.
@Test
public void testRpcTimeoutReplyComesDuringNexRpc() throws Exception {
int rpcTimeout = 100;
AMQConnection connection = mock(AMQConnection.class);
when(connection.getChannelRpcTimeout()).thenReturn(rpcTimeout);
when(connection.willCheckRpcResponseType()).thenReturn(Boolean.TRUE);
when(connection.getTrafficListener()).thenReturn(TrafficListener.NO_OP);
final DummyAmqChannel channel = new DummyAmqChannel(connection, 1);
Method method = new AMQImpl.Queue.Declare.Builder().queue("123").durable(false).exclusive(true).autoDelete(true).arguments(null).build();
try {
channel.rpc(method);
fail("Should time out and throw an exception");
} catch (final ChannelContinuationTimeoutException e) {
// OK
assertThat((DummyAmqChannel) e.getChannel()).isEqualTo(channel);
assertThat(e.getChannelNumber()).isEqualTo(channel.getChannelNumber());
assertThat(e.getMethod()).isEqualTo(method);
assertThat(channel.nextOutstandingRpc()).as("outstanding RPC should have been cleaned").isNull();
}
// now do a basic.consume request and have the queue.declareok returned instead
method = new AMQImpl.Basic.Consume.Builder().queue("123").consumerTag("").arguments(null).build();
final Method response1 = new AMQImpl.Queue.DeclareOk.Builder().queue("123").consumerCount(0).messageCount(0).build();
final Method response2 = new AMQImpl.Basic.ConsumeOk.Builder().consumerTag("456").build();
scheduler.schedule((Callable<Void>) () -> {
channel.handleCompleteInboundCommand(new AMQCommand(response1));
Thread.sleep(10);
channel.handleCompleteInboundCommand(new AMQCommand(response2));
return null;
}, (long) (rpcTimeout / 2.0), TimeUnit.MILLISECONDS);
AMQCommand rpcResponse = channel.rpc(method);
assertThat(rpcResponse.getMethod()).isEqualTo(response2);
}
use of com.rabbitmq.client.impl.AMQCommand in project rabbitmq-java-client by rabbitmq.
the class AMQChannelTest method rpcReturnsResultWhenResponseHasCome.
@Test
public void rpcReturnsResultWhenResponseHasCome() throws IOException {
int rpcTimeout = 1000;
AMQConnection connection = mock(AMQConnection.class);
when(connection.getChannelRpcTimeout()).thenReturn(rpcTimeout);
when(connection.getTrafficListener()).thenReturn(TrafficListener.NO_OP);
final DummyAmqChannel channel = new DummyAmqChannel(connection, 1);
Method method = new AMQImpl.Queue.Declare.Builder().queue("").durable(false).exclusive(true).autoDelete(true).arguments(null).build();
final Method response = new AMQImpl.Queue.DeclareOk.Builder().queue("whatever").consumerCount(0).messageCount(0).build();
scheduler.schedule(new Callable<Void>() {
@Override
public Void call() throws Exception {
channel.handleCompleteInboundCommand(new AMQCommand(response));
return null;
}
}, (long) (rpcTimeout / 2.0), TimeUnit.MILLISECONDS);
AMQCommand rpcResponse = channel.rpc(method);
assertThat(rpcResponse.getMethod()).isEqualTo(response);
}
use of com.rabbitmq.client.impl.AMQCommand in project pinpoint by naver.
the class RabbitMQConsumerHandleCompleteInboundCommandInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (!validate(target, args)) {
return;
}
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);
}
}
}
Aggregations