Example usage for com.rabbitmq.client ConnectionFactory setPassword

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

Introduction

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

Prototype

public void setPassword(String password) 

Source Link

Document

Set the password.

Usage

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);//  ww  w.j a v  a 2  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. ja v a  2  s.  c  om
    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);//w w w.  j  a v a2s .  c  o  m
    factory.setUsername("chs");
    factory.setPassword("chs123");
    Connection connection = null;
    try {
        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;/*  ww 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);/*from  w  w  w  .j a  v  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.springframework.cloud.vault.config.rabbitmq.VaultConfigRabbitMqTests.java

License:Apache License

@Test
public void shouldConnectUsingRabbitMQClient() throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(RABBITMQ_HOST);/*w w  w  . j  av a 2 s. c  o m*/
    factory.setPort(RABBITMQ_PORT);
    factory.setUsername(username);
    factory.setPassword(password);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.close();
    connection.close();
}

From source file:org.teksme.server.common.messaging.AMQPBrokerManager.java

License:Apache License

protected Connection connect(MessageMiddleware msgMiddlewareConfig) throws IOException {

    logger.info("Connecting to AMQP broker...");

    ConnectionFactory connFactory = new ConnectionFactory();
    connFactory.setUsername(msgMiddlewareConfig.getUsername());
    connFactory.setPassword(msgMiddlewareConfig.getPasswd());
    connFactory.setVirtualHost(msgMiddlewareConfig.getVirtualHost());
    connFactory.setHost(msgMiddlewareConfig.getHost());
    connFactory.setRequestedHeartbeat(0);
    connFactory.setPort(/*from  w w w  .java 2  s  .c om*/
            msgMiddlewareConfig.getPort() == null ? AMQP.PROTOCOL.PORT : msgMiddlewareConfig.getPort());

    toString(connFactory);

    try {
        conn = connFactory.newConnection();
    } catch (Exception e) {
        e.printStackTrace();
    }
    conn.addShutdownListener(this);

    logger.info("RabbitMQ AMQP broker connected!");

    return conn;
}

From source file:org.thingsboard.rule.engine.rabbitmq.TbRabbitMqNode.java

License:Apache License

@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
    this.config = TbNodeUtils.convert(configuration, TbRabbitMqNodeConfiguration.class);
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(this.config.getHost());
    factory.setPort(this.config.getPort());
    factory.setVirtualHost(this.config.getVirtualHost());
    factory.setUsername(this.config.getUsername());
    factory.setPassword(this.config.getPassword());
    factory.setAutomaticRecoveryEnabled(this.config.isAutomaticRecoveryEnabled());
    factory.setConnectionTimeout(this.config.getConnectionTimeout());
    factory.setHandshakeTimeout(this.config.getHandshakeTimeout());
    this.config.getClientProperties().forEach((k, v) -> factory.getClientProperties().put(k, v));
    try {/*from www .  j av  a 2  s  .  c  om*/
        this.connection = factory.newConnection();
        this.channel = this.connection.createChannel();
    } catch (Exception e) {
        throw new TbNodeException(e);
    }
}

From source file:org.thingsboard.server.extensions.rabbitmq.DemoClient.java

License:Apache License

public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(HOST);/*from ww w  . j a  v  a  2 s.com*/
    factory.setUsername(USERNAME);
    factory.setPassword(PASSWORD);

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

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages.");
    Consumer consumer = new DefaultConsumer(channel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String message = new String(body, "UTF-8");
            System.out.println(" [x] Received '" + message + "'");
        }
    };
    channel.basicConsume(QUEUE_NAME, true, consumer);

}

From source file:org.trianacode.TrianaCloud.Broker.BrokerServletContextListener.java

License:Open Source License

public void contextInitialized(ServletContextEvent event) {
    ServletContext sc = event.getServletContext();

    String host = sc.getInitParameter("rabbitmq.host");
    int port = Integer.parseInt(sc.getInitParameter("rabbitmq.port"));
    String user = sc.getInitParameter("rabbitmq.user");
    String pass = sc.getInitParameter("rabbitmq.pass");
    String rpc_queue_name = sc.getInitParameter("rabbitmq.rpc_queue_name");
    String vHost = sc.getInitParameter("rabbitmq.vhost");

    ConcurrentHashMap<String, Task> taskMap = new ConcurrentHashMap<String, Task>();
    ConcurrentHashMap<String, Task> resultMap = new ConcurrentHashMap<String, Task>();

    receiver = new Receiver(host, port, user, pass, vHost);
    rpcServer = new RPCServer(host, port, user, pass, vHost, rpc_queue_name);

    String replyQueue = receiver.init();
    try {/*from   w w w.  ja v a 2s  .com*/
        rpcServer.init();
    } catch (ServletException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

    receiverThread = new Thread(receiver);
    receiverThread.start();

    rpcServerThread = new Thread(rpcServer);
    rpcServerThread.start();

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(host);
    factory.setPort(port);
    factory.setUsername(user);
    factory.setPassword(pass);

    sc.setAttribute("RabbitMQConnectionFactory", factory);
    sc.setAttribute("taskmap", taskMap);
    sc.setAttribute("replyQueue", replyQueue);
    sc.setAttribute("resultMap", resultMap);
    sc.setAttribute("rpc_queue_name", rpc_queue_name);
}