Example usage for com.rabbitmq.client ConnectionFactory setPort

List of usage examples for com.rabbitmq.client ConnectionFactory setPort

Introduction

In this page you can find the example usage for com.rabbitmq.client ConnectionFactory setPort.

Prototype

public void setPort(int port) 

Source Link

Document

Set the target port.

Usage

From source file:org.mule.transport.rmq.RmqConnector.java

License:Open Source License

private ConnectionFactory createConnectionFactory() {
    ConnectionFactory factory = new ConnectionFactory();
    //Construct the factory from the connector URI if available
    //else from the variables.
    if (connectorURI != null) {
        RmqConnectorParser rcp = new RmqConnectorParser(connectorURI);
        host = rcp.getHost();// w  w w  .  j  a  va 2  s. c om
        port = rcp.getPort();
        vhost = rcp.getVhost();
        username = rcp.getUsername();
        password = rcp.getPassword();
    }
    factory.setHost(host);
    factory.setPort(port);
    if (vhost != null)
        factory.setVirtualHost(vhost);
    if (password != null)
        factory.setPassword(password);
    if (username != null)
        factory.setUsername(username);
    return factory;
}

From source file:org.objectweb.proactive.extensions.amqp.remoteobject.ConnectionAndChannelFactory.java

License:Open Source License

private synchronized CachedConnection getConnection(AMQPConnectionParameters connectionParameters)
        throws IOException {
    String key = connectionParameters.getKey();
    CachedConnection connection = cachedConnections.get(key);
    if (connection == null) {
        logger.debug(String.format("creating a new connection %s", key));

        ConnectionFactory factory = new ConnectionFactory();
        if (socketFactory != null) {
            factory.setSocketFactory(socketFactory);
        }/*from  ww w  . j av  a2s.  c o m*/
        factory.setHost(connectionParameters.getHost());
        factory.setPort(connectionParameters.getPort());
        factory.setUsername(connectionParameters.getUsername());
        factory.setPassword(connectionParameters.getPassword());
        factory.setVirtualHost(connectionParameters.getVhost());
        Connection c = factory.newConnection();
        c.addShutdownListener(new AMQPShutDownListener(c.toString()));

        connection = new CachedConnection(this, c);
        cachedConnections.put(key, connection);
    }

    return connection;
}

From source file:org.openbaton.plugin.PluginListener.java

License:Apache License

private void initRabbitMQ() throws IOException, TimeoutException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(brokerIp);//from  w w w.  j  a va 2 s. c o  m
    factory.setPort(brokerPort);
    factory.setPassword(password);
    factory.setUsername(username);
    factory.setVirtualHost(virtualHost);

    connection = factory.newConnection();
    channel = connection.createChannel();

    channel.queueDeclare(pluginId, this.durable, false, true, null);
    channel.queueBind(pluginId, exchange, pluginId);

    channel.basicQos(1);
}

From source file:org.openbaton.plugin.utils.PluginCaller.java

License:Apache License

public PluginCaller(String pluginId, String brokerIp, String username, String password, int port,
        int managementPort) throws IOException, TimeoutException, NotFoundException {
    this.pluginId = getFullPluginId(pluginId, brokerIp, username, password, managementPort);
    this.managementPort = managementPort;
    this.brokerIp = brokerIp;
    this.username = username;
    this.password = password;
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(brokerIp);/*from w  w w.j  a va2  s.  com*/
    if (username != null)
        factory.setUsername(username);
    else
        factory.setUsername("admin");
    if (password != null)
        factory.setPassword(password);
    else
        factory.setPassword("openbaton");
    if (port > 1024)
        factory.setPort(port);
    else
        factory.setPort(5672);
    connection = factory.newConnection();

    //        replyQueueName = channel.queueDeclare().getQueue();
    //        channel.queueBind(replyQueueName,exchange,replyQueueName);
    //        consumer = new QueueingConsumer(channel);
    //        channel.basicConsume(replyQueueName, true, consumer);
}

From source file:org.opendaylight.federationmessagequeue.impl.RabbitMessageBus.java

License:Open Source License

@Override
public boolean createQueue(String queueName, String mqBrokerIp, int mqPortNumber, String mqUser,
        String mqUserPwd) {//from w  ww  . j a  va2  s .co m
    LOG.info("Creating connection for queue {} on broker {}", queueName, mqBrokerIp);

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(mqBrokerIp);
    factory.setPort(mqPortNumber);
    factory.setUsername(mqUser);
    factory.setPassword(mqUserPwd);
    factory.setAutomaticRecoveryEnabled(true);

    try {
        Connection connection = factory.newConnection();
        LOG.info("Created connection to broker {}:{} for user {} ", mqBrokerIp, mqPortNumber, mqUser);
        Channel channel = connection.createChannel();
        channel.queueDeclare(queueName, false, false, false, null);
        LOG.info("Declared queue {} on broker {}", queueName, mqBrokerIp);
        MessageBusConnectionData mbcd = new MessageBusConnectionData(mqBrokerIp, connection, channel);
        queueNameToConnectionData.put(queueName, mbcd);
        return true;
    } catch (IOException | TimeoutException e) {
        LOG.warn("Failed creating queue {} on broker {}:{} for user {} because: {}", queueName, mqBrokerIp,
                mqPortNumber, mqUser, e.getMessage());
        return false;
    }
}

From source file:org.openmrs.module.amqpmodule.utils.impl.PublisherServiceImpl.java

License:Open Source License

@Override
public boolean PublisherCreateConnection() throws java.io.IOException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("192.168.43.123");
    factory.setPort(5672);
    factory.setUsername("chs");
    factory.setPassword("chs123");
    Connection connection = null;
    try {// ww w .  j  a v  a2 s .c o  m
        connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);

        channel.basicPublish(EXCHANGE_NAME, topic, MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
        System.out.println(" [x] Sent '" + msg + "'");

        channel.close();

    } catch (TimeoutException e) {
        System.out.println("Connection Timed out");
        e.printStackTrace();
    }

    connection.close();

    return true;
}

From source file:org.s23m.cell.repository.client.connector.RepositoryClientConnector.java

License:Mozilla Public License

private void initClient() {
    final ConnectionFactory cfconn = new ConnectionFactory();
    cfconn.setHost(ConfigValues.getString("RepositoryClientServer.HOST_NAME"));
    cfconn.setPort(Integer.parseInt(ConfigValues.getString("RepositoryClientServer.PORT")));
    cfconn.setVirtualHost(ConfigValues.getString("RepositoryClientServer.VHOST_NAME"));
    cfconn.setUsername(ConfigValues.getString("RepositoryClientServer.USER_NAME"));
    cfconn.setPassword(ConfigValues.getString("RepositoryClientServer.PW"));
    Connection conn;/* w  w  w  .jav  a  2s. c o  m*/
    try {
        conn = cfconn.newConnection();
        final Channel ch = conn.createChannel();
        clientService = new RpcClient(ch, "", ConfigValues.getString("RepositoryClientServer.QUEUE"));
    } catch (final IOException ex) {
        throw new IllegalStateException("Client set up failed", ex);
    }
}

From source file:org.s23m.cell.repository.client.server.RepositoryClientServer.java

License:Mozilla Public License

private void setupConnection() throws IOException {
    final ConnectionFactory connFactory = new ConnectionFactory();
    connFactory.setHost(LOCALHOST);/*www.j  av  a 2s  . c o m*/
    connFactory.setPort(PORT);
    connFactory.setVirtualHost(ConfigValues.getString("RepositoryClientServer.VHOST_NAME"));
    connFactory.setUsername(ConfigValues.getString("RepositoryClientServer.USER_NAME"));
    connFactory.setPassword(ConfigValues.getString("RepositoryClientServer.PW"));
    final Connection conn = connFactory.newConnection();
    ch = conn.createChannel();
    ch.queueDeclare(QUEUE_NAME, false, false, false, null);
}

From source file:org.smartdeveloperhub.curator.connector.BrokerController.java

License:Apache License

void connect() throws ControllerException {
    this.write.lock();
    try {// www.  j  av a  2 s  . c o m
        if (this.connected) {
            return;
        }
        final ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(this.broker.host());
        factory.setPort(this.broker.port());
        factory.setVirtualHost(this.broker.virtualHost());
        factory.setThreadFactory(brokerThreadFactory());
        factory.setExceptionHandler(new BrokerControllerExceptionHandler(this));
        this.connection = factory.newConnection();
        createChannel();
    } catch (IOException | TimeoutException e) {
        this.connected = false;
        final String message = String.format("Could not connect to broker at %s:%s using virtual host %s",
                this.broker.host(), this.broker.port(), this.broker.virtualHost());
        throw new ControllerException(message, e);
    } finally {
        this.write.unlock();
    }
}

From source file:org.smartdeveloperhub.harvesters.it.notification.ConnectionManager.java

License:Apache License

void connect() throws ControllerException {
    this.lock.lock();
    try {/*from  w ww .  ja v  a  2 s  . co m*/
        if (connected()) {
            return;
        }
        final ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(this.brokerHost);
        factory.setPort(this.brokerPort);
        factory.setVirtualHost(this.virtualHost);
        factory.setThreadFactory(brokerThreadFactory());
        factory.setExceptionHandler(new ConnectionManagerExceptionHandler(this));
        this.connection = factory.newConnection();
        createChannel();
    } catch (IOException | TimeoutException e) {
        final String message = String.format("Could not connect to broker at %s:%s using virtual host %s",
                this.brokerHost, this.brokerPort, this.virtualHost);
        throw new ControllerException(this.brokerHost, this.brokerPort, this.virtualHost, message, e);
    } finally {
        this.lock.unlock();
    }
}