Example usage for com.rabbitmq.client Address getHost

List of usage examples for com.rabbitmq.client Address getHost

Introduction

In this page you can find the example usage for com.rabbitmq.client Address getHost.

Prototype

public String getHost() 

Source Link

Document

Get the host name

Usage

From source file:org.apache.flume.rabbitmq.RabbitMQConnectionFactory.java

License:Apache License

private RabbitMQConnectionFactory(List<Address> hosts, int port, String virtualHost, int connectionTimeout,
        int requestedHeartbeat, int requestedChannelMax, int requestedFrameMax, String userName,
        String password, ConnectionFactory connectionFactory) {

    Preconditions.checkArgument(hosts != null, "host can not be null");
    Preconditions.checkArgument(!hosts.isEmpty(), "hosts can not be empty");
    Preconditions.checkArgument(userName != null, "user name can not be null");
    Preconditions.checkArgument(password != null, "password can not be null");
    Preconditions.checkArgument(virtualHost != null, "virtual host can not be null");
    Preconditions.checkArgument(connectionFactory != null, "connection factory can not be null");

    this.hosts = hosts;

    this.connectionFactory = connectionFactory;
    connectionFactory.setPort(port);// w w w  . j  av  a2s.  co m
    if (this.hosts.size() == 1) { // Only one host to connect
        Address address = hosts.get(0);
        this.connectionFactory.setHost(address.getHost());
        if (address.getPort() != -1) { // If port is also supplied then use it.
            this.connectionFactory.setPort(address.getPort());
        }
    }
    this.connectionFactory.setVirtualHost(virtualHost);
    this.connectionFactory.setConnectionTimeout(connectionTimeout);
    this.connectionFactory.setRequestedHeartbeat(requestedHeartbeat);
    this.connectionFactory.setRequestedChannelMax(requestedChannelMax);
    this.connectionFactory.setRequestedFrameMax(requestedFrameMax);
    this.connectionFactory.setUsername(userName);
    this.connectionFactory.setPassword(password);
}

From source file:org.mule.transport.amqp.internal.connector.AmqpConnector.java

License:Open Source License

protected void connectToFirstResponsiveBroker(final List<Address> brokerAddresses) throws Exception {
    Exception lastException = null;

    for (final Address brokerAddress : brokerAddresses) {
        lastException = null;/*from   w  w  w .  j  ava 2 s.co  m*/

        try {
            logger.debug("Connecting to AMQP host: " + brokerAddress.getHost() + " and port: "
                    + brokerAddress.getPort());
            connectionFactory.setHost(brokerAddress.getHost());
            connectionFactory.setPort(brokerAddress.getPort());
            connection = connectionFactory.newConnection(receiverExecutor);

            connection.addShutdownListener(new ShutdownListener() {
                public void shutdownCompleted(final ShutdownSignalException sse) {
                    if (sse.isInitiatedByApplication()) {
                        return;
                    }

                    forceReconnect("Connection shutdown detected for: " + getName(), sse);
                }
            });
            logger.info("Connected to AMQP host: " + brokerAddress.getHost() + " and port: "
                    + brokerAddress.getPort());
            break;
        } catch (final Exception e) {
            logger.error("Error occurred when connecting to AMQP host: " + brokerAddress.getHost()
                    + " and port: " + brokerAddress.getPort(), e);
            lastException = e;
        }
    }

    if (lastException != null) {
        throw lastException;
    }
}