Example usage for com.rabbitmq.client Connection getAddress

List of usage examples for com.rabbitmq.client Connection getAddress

Introduction

In this page you can find the example usage for com.rabbitmq.client Connection getAddress.

Prototype

InetAddress getAddress();

Source Link

Document

Retrieve the host.

Usage

From source file:com.esri.geoevent.transport.rabbitmq.RabbitMQConnectionListener.java

License:Apache License

@Override
public void onCreate(Connection connection) {
    notifyObservers(RabbitMQConnectionStatus.CREATED,
            LOGGER.translate("CONNECTION_ESTABLISH_SUCCESS", connection.getAddress().getCanonicalHostName()),
            connection);//from   w  w w.ja  v a 2s  . c  o  m
}

From source file:com.esri.geoevent.transport.rabbitmq.RabbitMQConnectionListener.java

License:Apache License

@Override
public void onRecovery(Connection connection) {

    notifyObservers(RabbitMQConnectionStatus.RECOVERY,
            LOGGER.translate("CONNECTION_RECOVERED", connection.getAddress().getCanonicalHostName()),
            connection);/*from w w w  . ja v  a 2  s  .com*/
}

From source file:com.esri.geoevent.transport.rabbitmq.RabbitMQConnectionListener.java

License:Apache License

@Override
public void onRecoveryStarted(Connection connection) {
    notifyObservers(RabbitMQConnectionStatus.RECOVERY_STARTED,
            LOGGER.translate("CONNECTION_RECOVERY_STARTED", connection.getAddress().getCanonicalHostName()),
            connection);/*from   w  w w .j av  a 2  s .c om*/
}

From source file:com.esri.geoevent.transport.rabbitmq.RabbitMQConnectionListener.java

License:Apache License

@Override
public void onRecoveryCompleted(Connection connection) {
    notifyObservers(new RabbitMQTransportEvent(RabbitMQConnectionStatus.RECOVERY_COMPLETED,
            LOGGER.translate("CONNECTION_RECOVERY_COMPLETED", connection.getAddress().getCanonicalHostName()),
            connection));/*from  w  w  w .java2s .  c om*/
}

From source file:com.esri.geoevent.transport.rabbitmq.RabbitMQConnectionListener.java

License:Apache License

@Override
public void onRecoveryFailure(Connection connection, Throwable failure) {
    notifyObservers(RabbitMQConnectionStatus.RECOVERY_FAILED, LOGGER.translate("CONNECTION_RECOVERY_FAILED",
            connection.getAddress().getCanonicalHostName(), failure.getMessage()), connection);
}

From source file:com.navercorp.pinpoint.plugin.jdk7.rabbitmq.RabbitMQTestRunner.java

License:Apache License

void runPushTest() throws Exception {

    final String message = "hello rabbit mq";

    // producer side
    final Connection producerConnection = connectionFactory.newConnection();
    final Channel producerChannel = producerConnection.createChannel();

    producerChannel.exchangeDeclare(RabbitMQTestConstants.EXCHANGE, "direct", false);
    producerChannel.queueDeclare(RabbitMQTestConstants.QUEUE_PUSH, false, false, false, null);
    producerChannel.queueBind(RabbitMQTestConstants.QUEUE_PUSH, RabbitMQTestConstants.EXCHANGE,
            RabbitMQTestConstants.ROUTING_KEY_PUSH);

    AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
    producerChannel.basicPublish(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PUSH, false,
            false, builder.appId("test").build(), message.getBytes());

    producerChannel.close();/*from  w w  w. jav a  2  s .c  om*/
    producerConnection.close();

    //comsumer side
    final Connection consumerConnection = connectionFactory.newConnection();
    final Channel consumerChannel = consumerConnection.createChannel();
    final String remoteAddress = consumerConnection.getAddress().getHostAddress() + ":"
            + consumerConnection.getPort();

    consumerChannel.queueDeclare(RabbitMQTestConstants.QUEUE_PUSH, false, false, false, null);

    TestConsumer<String> consumer = new TestConsumer<String>(consumerChannel, MessageConverter.FOR_TEST);
    consumerChannel.basicConsume(RabbitMQTestConstants.QUEUE_PUSH, true, consumer);

    // wait consumer
    Assert.assertEquals(message, consumer.getMessage(10, TimeUnit.SECONDS));

    consumerChannel.close();
    consumerConnection.close();

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(verifier, 6, 5000L);

    verifier.printCache();
    Class<?> producerChannelClass = producerChannel.getClass();
    Method channelBasicPublish = producerChannelClass.getDeclaredMethod("basicPublish", String.class,
            String.class, boolean.class, boolean.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace channelBasicPublishTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT, // serviceType
            channelBasicPublish, // method
            null, // rpc
            remoteAddress, // endPoint
            "exchange-" + RabbitMQTestConstants.EXCHANGE, // destinationId
            Expectations.annotation("rabbitmq.exchange", RabbitMQTestConstants.EXCHANGE),
            Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PUSH));
    ExpectedTrace rabbitMqConsumerInvocationTrace = Expectations.root(RabbitMQTestConstants.RABBITMQ_CLIENT, // serviceType
            "RabbitMQ Consumer Invocation", // method
            "rabbitmq://exchange=" + RabbitMQTestConstants.EXCHANGE, // rpc
            null, // endPoint (collected but API to retrieve local address is not available in all versions, so skip)
            remoteAddress, // remoteAddress
            Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PUSH));
    Class<?> consumerDispatchClass = Class.forName("com.rabbitmq.client.impl.ConsumerDispatcher");
    Method consumerDispatchHandleDelivery = consumerDispatchClass.getDeclaredMethod("handleDelivery",
            Consumer.class, String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace consumerDispatcherHandleDeliveryTrace = Expectations
            .event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, consumerDispatchHandleDelivery); // method
    ExpectedTrace asynchronousInvocationTrace = Expectations.event(ServiceType.ASYNC.getName(),
            "Asynchronous Invocation");
    Class<?> consumerClass = consumer.getClass();
    Method consumerHandleDelivery = consumerClass.getDeclaredMethod("handleDelivery", String.class,
            Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace consumerHandleDeliveryTrace = Expectations
            .event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, consumerHandleDelivery);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    verifier.verifyTrace(channelBasicPublishTrace, rabbitMqConsumerInvocationTrace,
            consumerDispatcherHandleDeliveryTrace, asynchronousInvocationTrace, consumerHandleDeliveryTrace,
            markTrace);
    verifier.verifyTraceCount(0);
}

From source file:com.navercorp.pinpoint.plugin.jdk7.rabbitmq.RabbitMQTestRunner.java

License:Apache License

void runPullTest() throws Exception {

    final String message = "hello rabbit mq";

    // producer side
    final Connection producerConnection = connectionFactory.newConnection();
    final Channel producerChannel = producerConnection.createChannel();

    producerChannel.exchangeDeclare(RabbitMQTestConstants.EXCHANGE, "direct", false);
    producerChannel.queueDeclare(RabbitMQTestConstants.QUEUE_PULL, false, false, false, null);
    producerChannel.queueBind(RabbitMQTestConstants.QUEUE_PULL, RabbitMQTestConstants.EXCHANGE,
            RabbitMQTestConstants.ROUTING_KEY_PULL);

    AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
    producerChannel.basicPublish(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PULL, false,
            false, builder.appId("test").build(), message.getBytes());

    producerChannel.close();//w ww .j  a  v  a  2 s. co m
    producerConnection.close();

    //comsumer side
    final Connection consumerConnection = connectionFactory.newConnection();
    final Channel consumerChannel = consumerConnection.createChannel();
    final String remoteAddress = consumerConnection.getAddress().getHostAddress() + ":"
            + consumerConnection.getPort();

    TestMessagePuller messagePuller = new TestMessagePuller(consumerChannel);
    Assert.assertEquals(message,
            messagePuller.pullMessage(MessageConverter.FOR_TEST, RabbitMQTestConstants.QUEUE_PULL, true));

    consumerChannel.close();
    consumerConnection.close();

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(verifier, 5, 5000L);

    verifier.printCache();
    // verify producer traces
    Class<?> producerChannelClass = producerChannel.getClass();
    Method channelBasicPublish = producerChannelClass.getDeclaredMethod("basicPublish", String.class,
            String.class, boolean.class, boolean.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace channelBasicPublishTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT, // serviceType
            channelBasicPublish, // method
            null, // rpc
            remoteAddress, // endPoint
            "exchange-" + RabbitMQTestConstants.EXCHANGE, // destinationId
            Expectations.annotation("rabbitmq.exchange", RabbitMQTestConstants.EXCHANGE),
            Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PULL));
    ExpectedTrace rabbitMqConsumerInvocationTrace = Expectations.root(RabbitMQTestConstants.RABBITMQ_CLIENT, // serviceType
            "RabbitMQ Consumer Invocation", // method
            "rabbitmq://exchange=" + RabbitMQTestConstants.EXCHANGE, // rpc
            null, // endPoint (collected but API to retrieve local address is not available in all versions, so skip)
            remoteAddress, // remoteAddress
            Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PULL));
    Class<?> amqChannelClass = Class.forName("com.rabbitmq.client.impl.AMQChannel");
    Method handleCompleteInboundCommand = amqChannelClass.getDeclaredMethod("handleCompleteInboundCommand",
            AMQCommand.class);
    ExpectedTrace handleCompleteInboundCommandTrace = Expectations.event(
            RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // serviceType
            handleCompleteInboundCommand); // method
    verifier.verifyDiscreteTrace(channelBasicPublishTrace, rabbitMqConsumerInvocationTrace,
            handleCompleteInboundCommandTrace);

    // verify consumer traces
    Class<?> consumerChannelClass = consumerChannel.getClass();
    Method channelBasicGet = consumerChannelClass.getDeclaredMethod("basicGet", String.class, boolean.class);
    ExpectedTrace channelBasicGetTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL,
            channelBasicGet);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    verifier.verifyDiscreteTrace(channelBasicGetTrace, markTrace);
    verifier.verifyTraceCount(0);
}

From source file:com.springsource.insight.plugin.rabbitmqClient.AbstractRabbitMQCollectionAspect.java

License:Apache License

protected void applyConnectionData(Operation op, Connection conn) {
    String connectionUrl = null;//from   ww w  .j ava2 s  .com

    if (conn instanceof AMQConnection) {
        connectionUrl = conn.toString();
    } else {
        InetAddress address = conn.getAddress();
        int port = conn.getPort();

        StringBuilder sb = new StringBuilder("amqp://");
        sb.append(address.getHostAddress()).append(":").append(port);

        connectionUrl = sb.toString();
    }

    op.put("host", conn.getAddress().getHostAddress());
    op.put("port", conn.getPort());
    op.put("connectionUrl", connectionUrl);

    //try to extract server version
    String version = getVersion(conn.getServerProperties());
    op.put("serverVersion", version);

    //try to extract client version
    version = getVersion(conn.getClientProperties());
    op.put("clientVersion", version);
}