use of com.rabbitmq.client.impl.FrameHandler in project rabbitmq-java-client by rabbitmq.
the class ConnectionFactoryTest method tryNextAddressIfTimeoutExceptionNoAutoRecovery.
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/262
@Test
public void tryNextAddressIfTimeoutExceptionNoAutoRecovery() throws IOException, TimeoutException {
final AMQConnection connectionThatThrowsTimeout = mock(AMQConnection.class);
final AMQConnection connectionThatSucceeds = mock(AMQConnection.class);
final Queue<AMQConnection> connections = new ArrayBlockingQueue<AMQConnection>(10);
connections.add(connectionThatThrowsTimeout);
connections.add(connectionThatSucceeds);
ConnectionFactory connectionFactory = new ConnectionFactory() {
@Override
protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector) {
return connections.poll();
}
@Override
protected synchronized FrameHandlerFactory createFrameHandlerFactory() throws IOException {
return mock(FrameHandlerFactory.class);
}
};
connectionFactory.setAutomaticRecoveryEnabled(false);
doThrow(TimeoutException.class).when(connectionThatThrowsTimeout).start();
doNothing().when(connectionThatSucceeds).start();
Connection returnedConnection = connectionFactory.newConnection(new Address[] { new Address("host1"), new Address("host2") });
assertSame(connectionThatSucceeds, returnedConnection);
}
use of com.rabbitmq.client.impl.FrameHandler in project pinpoint by naver.
the class RabbitMQConsumerHandleCompleteInboundCommandInterceptor method recordRootSpan.
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();
}
// 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 = StringUtils.defaultIfEmpty(exchange, 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.hasLength(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()));
}
}
}
use of com.rabbitmq.client.impl.FrameHandler in project rabbitmq-java-client by rabbitmq.
the class RecoveryAwareAMQConnectionFactory method newConnection.
/**
* @return an interface to the connection
* @throws java.io.IOException if it encounters a problem
*/
// package protected API, made public for testing only
public RecoveryAwareAMQConnection newConnection() throws IOException, TimeoutException {
Exception lastException = null;
List<Address> resolved = addressResolver.getAddresses();
List<Address> shuffled = addressResolver.maybeShuffle(resolved);
for (Address addr : shuffled) {
try {
FrameHandler frameHandler = factory.create(addr, connectionName());
RecoveryAwareAMQConnection conn = createConnection(params, frameHandler, metricsCollector);
conn.start();
metricsCollector.newConnection(conn);
return conn;
} catch (IOException e) {
lastException = e;
} catch (TimeoutException te) {
lastException = te;
}
}
if (lastException != null) {
if (lastException instanceof IOException) {
throw (IOException) lastException;
} else if (lastException instanceof TimeoutException) {
throw (TimeoutException) lastException;
}
}
throw new IOException("failed to connect");
}
use of com.rabbitmq.client.impl.FrameHandler in project pinpoint by naver.
the class RabbitMQConsumerDispatchInterceptor method recordRootSpan.
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();
}
// 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 = StringUtils.defaultIfEmpty(envelope.getExchange(), 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.hasLength(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()));
}
}
}
use of com.rabbitmq.client.impl.FrameHandler in project pinpoint by naver.
the class ChannelBasicPublishInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args);
}
if (!validate(target, args)) {
return;
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
String exchange = (String) args[0];
String routingKey = (String) args[1];
if (exchange == null || exchange.equals("")) {
exchange = RabbitMQClientConstants.UNKNOWN;
}
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(descriptor);
String endPoint = RabbitMQClientConstants.UNKNOWN;
// Producer's endPoint should be the socket address of where the producer is actually connected to.
final Connection connection = ((Channel) target).getConnection();
if (connection instanceof AMQConnection) {
AMQConnection amqConnection = (AMQConnection) connection;
FrameHandler frameHandler = amqConnection.getFrameHandler();
if (frameHandler instanceof RemoteAddressAccessor) {
endPoint = ((RemoteAddressAccessor) frameHandler)._$PINPOINT$_getRemoteAddress();
}
}
recorder.recordEndPoint(endPoint);
// DestinationId is used to render the virtual queue node.
// We choose the exchange name as the logical name of the queue node.
recorder.recordDestinationId("exchange-" + exchange);
recorder.recordAttribute(RabbitMQClientConstants.RABBITMQ_EXCHANGE_ANNOTATION_KEY, exchange);
recorder.recordAttribute(RabbitMQClientConstants.RABBITMQ_ROUTINGKEY_ANNOTATION_KEY, routingKey);
recorder.recordException(throwable);
} finally {
trace.traceBlockEnd();
}
}
Aggregations