Example usage for com.rabbitmq.client ConnectionFactory setHost

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

Introduction

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

Prototype

public void setHost(String host) 

Source Link

Usage

From source file:com.hp.ov.sdk.messaging.core.RabbitMqClientConnectionFactory.java

License:Apache License

public static ConnectionFactory getConnectionFactory(final SSLContext sslContext, final RestParams params) {

    final ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(params.getHostname());
    factory.setPort(params.getAmqpPort());

    // Set Auth mechanism to "EXTERNAL" so that commonName of the client
    // certificate is mapped to AMQP user name. Hence, No need to set
    // userId/Password here.
    factory.setSaslConfig(DefaultSaslConfig.EXTERNAL);
    factory.useSslProtocol(sslContext);//w  w w .j a  v a  2 s  .  c om
    factory.setAutomaticRecoveryEnabled(true);

    return factory;
}

From source file:com.insa.tp3g1.esbsimulator.view.MessageHandler.java

public static String sendConfig1(String who, String config) throws Exception {

    /* calling connectionFactory to create a custome connexion with
    * rabbitMQ server information.//from  w ww.  j av  a2s .  c  o  m
    */
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("146.148.27.98");
    factory.setUsername("admin");
    factory.setPassword("adminadmin");
    factory.setPort(5672);
    System.out.println("connection ok");
    // establish the connection with RabbitMQ server using our factory.
    Connection connection = factory.newConnection();
    // System.out.println("connection ok1");
    // We're connected now, to the broker on the cloud machine.
    // If we wanted to connect to a broker on a the local machine we'd simply specify "localhost" as IP adresse.
    // creating a "configuration" direct channel/queue
    Channel channel = connection.createChannel();
    //  System.out.println("connection ok2");
    channel.exchangeDeclare(EXCHANGE_NAME, "direct");
    //  System.out.println("exchangeDeclare");
    // the message and the distination
    String forWho = who;
    String message = config;

    // publish the message
    channel.basicPublish(EXCHANGE_NAME, forWho, null, message.getBytes());
    //  System.out.println("basicPublish");
    // close the queue and the connexion
    channel.close();
    connection.close();
    return " [x] Sent '" + forWho + "':'" + message + "'";
}

From source file:com.insa.tp3g1.esbsimulator.view.MessageHandler.java

public static void logGetter() throws java.io.IOException {
    ConnectionFactory factory = new ConnectionFactory();
    LogHandler logHandler = new LogHandler();
    factory.setHost("146.148.27.98");
    factory.setUsername("admin");
    factory.setPassword("adminadmin");
    factory.setPort(5672);/*from w  w  w .  ja va 2 s  . c o  m*/

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

    channel.exchangeDeclare(LOG_NAME, "fanout");
    String queueName = channel.queueDeclare().getQueue();
    channel.queueBind(queueName, LOG_NAME, "");

    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(queueName, true, consumer);
    count = 0;
    boolean over = false;
    while (!over) {

        QueueingConsumer.Delivery delivery = null;
        try {
            delivery = consumer.nextDelivery();
            String message = new String(delivery.getBody());
            //System.out.println(" [x] Received '" + message + "'");
            synchronized (count) {
                count++;
            }
            logHandler.add(message);
            System.out.print(Thread.currentThread().getId() + " ");

        } catch (InterruptedException interruptedException) {
            System.out.println("finished");
            System.out.println(logHandler);

            System.out.println(logHandler);
            Thread.currentThread().interrupt();
            System.out.println(Thread.currentThread().getId() + " ");
            break;
            // Thread.currentThread().stop();
            // over = true;
        } catch (ShutdownSignalException shutdownSignalException) {
            System.out.println("finished");
            // Thread.currentThread().stop();
            over = true;
        } catch (ConsumerCancelledException consumerCancelledException) {
            System.out.println("finished");
            //  Thread.currentThread().stop();
            over = true;
        } catch (IllegalMonitorStateException e) {
            System.out.println("finished");
            // Thread.currentThread().stop();
            over = true;
        }

    }
    System.out.println("before close");
    channel.close();
    connection.close();
    System.out.println("finished handling");
    Result res = logHandler.fillInResultForm(logHandler.getTheLog());
    ResultHandler resH = new ResultHandler(res);
    resH.createResultFile("/home/alpha/alphaalpha.xml");
    final OverlaidBarChart demo = new OverlaidBarChart("Response Time Chart", res);
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
    int lost = Integer.parseInt(res.getTotalResult().getLostRequests()) / logHandler.getNbRequests();
    PieChart demo1 = new PieChart("Messages", lost * 100);
    demo1.pack();
    demo1.setVisible(true);
    //System.out.println(logHandler);

}

From source file:com.interop.webapp.WebApp.java

License:Apache License

@PostConstruct
public void setUpQueue() throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(config.getQueueHostName());
    connection = factory.newConnection();
    channel = connection.createChannel();

    replyQueueName = channel.queueDeclare().getQueue();
    consumer = new QueueingConsumer(channel);
    channel.basicConsume(replyQueueName, true, consumer);
    // Create the folder that will hold the processed files
    String foldername = config.getImageFilesRoot() + '/' + processedFilesWebPath;
    File folder = new File(URI.create(foldername));
    if (folder.exists()) {
        return;// w w  w . ja v a 2  s  . com
    }
    log.info("creating directory: " + foldername);
    try {
        folder.mkdir();
    } catch (SecurityException se) {
        log.error(String.format("creating directory: %s (%s)", foldername, se.getMessage()));
    } catch (Exception e) {
        log.error(String.format("creating directory: %s (%s)", foldername, e.getMessage()));
    }
}

From source file:com.jarova.mqtt.RabbitMQ.java

public void fixConnection() {
    try {//from  w w  w .j a v a 2 s.co  m
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
        factory.setHost(HOST_NAME);

        //adicionado para que a conexao seja recuperada em caso de falha de rede;
        factory.setAutomaticRecoveryEnabled(true);

        Connection connection = factory.newConnection();
        channel = connection.createChannel();
        channel.queueDeclare(QUEUE, true, false, false, null);
        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
    } catch (IOException ex) {
        Logger.getLogger(RabbitMQ.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TimeoutException ex) {
        Logger.getLogger(RabbitMQ.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.jarova.mqtt.RabbitMQConnector.java

public RabbitMQConnector() throws IOException, TimeoutException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername("azhang");
    factory.setPassword("Queens.NY1");
    factory.setHost(hostName);
    Connection connection = factory.newConnection();
    channel = connection.createChannel();
    channel.queueDeclare(QUEUE, false, false, false, null);

    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
}

From source file:com.jbrisbin.vcloud.mbean.CloudInvokerListener.java

License:Apache License

protected Connection getConnection() throws IOException {
    if (null == connection) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(mqHost);
        factory.setPort(mqPort);// ww w. j  a v a 2 s . c  om
        factory.setUsername(mqUser);
        factory.setPassword(mqPassword);
        factory.setVirtualHost(mqVirtualHost);
        if (DEBUG) {
            log.debug("Connecting to RabbitMQ server...");
        }
        connection = factory.newConnection();
    }
    return connection;
}

From source file:com.jbrisbin.vcloud.session.CloudStore.java

License:Apache License

protected synchronized Connection getMqConnection() throws IOException {
    if (null == mqConnection) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(mqHost);
        factory.setPort(mqPort);//ww w  . j  av  a2s . c  o  m
        factory.setUsername(mqUser);
        factory.setPassword(mqPassword);
        factory.setVirtualHost(mqVirtualHost);
        factory.setRequestedHeartbeat(10);
        mqConnection = factory.newConnection();
    }
    return mqConnection;
}

From source file:com.kumuluz.ee.samples.amqp.rabbitmq.messaging.ConnectionInitializer.java

License:MIT License

@AMQPConnection
public Map<String, Connection> localhostConnection() {
    Map<String, Connection> localhost = new HashMap<>();

    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setHost("localhost");

    Connection connection = null;

    try {//from  w w  w  . j a  v a  2s.c  o m
        connection = connectionFactory.newConnection();
    } catch (IOException | TimeoutException e) {
        log.severe("Connection could not be created");
    }

    localhost.put("MQtest2", connection);
    return localhost;
}

From source file:com.loanbroker.old.JSONReceiveTest.java

public static void main(String[] argv) throws IOException, InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("student");
    factory.setPassword("cph");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
    String queueName = "Kender du hende der Arne";
    channel.queueDeclare(queueName, false, false, false, null);

    channel.queueBind(queueName, EXCHANGE_NAME, "");
    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(queueName, true, consumer);

    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        String messageIn = new String(delivery.getBody());
        System.out.println(" [x] Received by tester: '" + messageIn + "'");
    }/*w  w w .  j  a  v  a2s . co  m*/

}