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:com.googlesource.gerrit.plugins.rabbitmq.session.type.AMQPSession.java

License:Apache License

@Override
public void connect() {
    if (connection != null && connection.isOpen()) {
        LOGGER.info(MSG("Already connected."));
        return;/*from w w  w. j a va2  s. com*/
    }
    AMQP amqp = properties.getSection(AMQP.class);
    LOGGER.info(MSG("Connect to {}..."), amqp.uri);
    ConnectionFactory factory = new ConnectionFactory();
    try {
        if (StringUtils.isNotEmpty(amqp.uri)) {
            factory.setUri(amqp.uri);
            if (StringUtils.isNotEmpty(amqp.username)) {
                factory.setUsername(amqp.username);
            }
            Gerrit gerrit = properties.getSection(Gerrit.class);
            String securePassword = gerrit.getAMQPUserPassword(amqp.username);
            if (StringUtils.isNotEmpty(securePassword)) {
                factory.setPassword(securePassword);
            } else if (StringUtils.isNotEmpty(amqp.password)) {
                factory.setPassword(amqp.password);
            }
            connection = factory.newConnection();
            connection.addShutdownListener(connectionListener);
            LOGGER.info(MSG("Connection established."));
        }
    } catch (URISyntaxException ex) {
        LOGGER.error(MSG("URI syntax error: {}"), amqp.uri);
    } catch (IOException ex) {
        LOGGER.error(MSG("Connection cannot be opened."), ex);
    } catch (KeyManagementException | NoSuchAlgorithmException ex) {
        LOGGER.error(MSG("Security error when opening connection."), ex);
    }
}

From source file:com.grnet.parsers.Entry.java

License:Open Source License

public static void main(String[] args) throws InterruptedException, InstantiationException,
        IllegalAccessException, ClassNotFoundException, LangDetectException {

    if (args.length != 3) {
        System.err.println("Usage : ");
        System.err.println("java -jar com.grnet.parsers.Entry <input folder> <output folder> <bad folder>");
        System.exit(-1);//from w  w w.ja va 2  s  .  c  om
    }

    File input = new File(args[0]);

    File output = new File(args[1]);

    File bad = new File(args[2]);

    if (!input.exists() || !input.isDirectory()) {
        System.err.println("Input folder does not exist or it is not a folder.");
        System.exit(-1);
    }

    if (!output.exists() || !output.isDirectory()) {
        System.err.println("Output folder does not exist or it is not a folder.");
        System.exit(-1);
    }
    if (!bad.exists() || !bad.isDirectory()) {
        System.err.println("Bad files folder does not exist or it is not a folder.");
        System.exit(-1);
    }

    CheckConfig config = new CheckConfig();

    if (config.checkAttributes()) {

        System.out.println("----------------------------------------");
        System.out.println("Starting lang detection on folder:" + input.getName());

        System.out.println("----------------------------------------");

        String idClass = config.getProps().getProperty(Constants.inputClass);
        ClassLoader myClassLoader = ClassLoader.getSystemClassLoader();
        Class myClass = myClassLoader.loadClass(idClass);
        Object whatInstance = myClass.newInstance();
        Input inpt = (Input) whatInstance;

        Collection<File> data = (Collection<File>) inpt.getData(input);

        Stats stats = new Stats(data.size());

        int threadPoolSize = Integer.parseInt(config.getProps().getProperty(Constants.tPoolSize));
        int availableProcessors = Runtime.getRuntime().availableProcessors();
        System.out.println("Available cores:" + availableProcessors);
        System.out.println("Thread Pool size:" + threadPoolSize);
        ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);

        long start = System.currentTimeMillis();
        Iterator<File> iterator = data.iterator();

        DetectorFactory.loadProfile(config.getProps().getProperty(Constants.profiles));

        String strict = config.getProps().getProperty(Constants.strict);

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(config.getProps().getProperty(Constants.queueHost));
        factory.setUsername(config.getProps().getProperty(Constants.queueUser));
        factory.setPassword(config.getProps().getProperty(Constants.queuePass));

        while (iterator.hasNext()) {

            Worker worker = new Worker(iterator.next(), config.getProps(), output.getPath(), bad.getPath(),
                    stats, slf4jLogger, strict, QUEUE_NAME, factory);
            executor.execute(worker);
        }

        executor.shutdown();
        executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);

        long end = System.currentTimeMillis();
        long diff = end - start;
        System.out.println("Duration:" + diff + "ms");
        System.out.println("Done");

        if (config.getProps().getProperty(Constants.report).equalsIgnoreCase("true")) {
            try {
                System.out.println("Creating report...");
                report report = new report(input.getName(), diff, threadPoolSize, availableProcessors, output,
                        stats);
                report.createReport();
                System.out.println("Done");

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    } else
        System.err.println("Please correct configuration.properties file attribute values");

}

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.// w  ww .j  a  v a 2  s .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. j a  va2s .co  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.jarova.mqtt.RabbitMQ.java

public void fixConnection() {
    try {//w ww .j a  va2  s .  c om
        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);//w ww  .ja va  2s. co  m
    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);//from w  w  w.j  a  va2s .  co  m
        factory.setPort(mqPort);
        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);/* w  ww . j a v a  2  s  . c  o m*/
        factory.setPort(mqPort);
        factory.setUsername(mqUser);
        factory.setPassword(mqPassword);
        factory.setVirtualHost(mqVirtualHost);
        factory.setRequestedHeartbeat(10);
        mqConnection = factory.newConnection();
    }
    return mqConnection;
}

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 + "'");
    }/*from  w w w .  jav a2  s  .com*/

}

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

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

    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, "");
    String messageOut = "{\"ssn\":1605789787,\"creditScore\":699,\"loanAmount\":10.0,\"loanDuration\":360}";
    BasicProperties.Builder props = new BasicProperties().builder();
    props.replyTo("");
    BasicProperties bp = props.build();//from  w  w  w .j  av  a2s .c  o  m
    channel.basicPublish(EXCHANGE_NAME, "", bp, messageOut.getBytes());
    System.out.println(" [x] Sent by JSONtester: '" + messageOut + "'");

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