Example usage for com.rabbitmq.client ConnectionFactory ConnectionFactory

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

Introduction

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

Prototype

ConnectionFactory

Source Link

Usage

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);//from   ww w. j a  v a 2s.c  om
    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);/*w w  w . jav  a2  s.  c  om*/
        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);//from  w ww  .  jav a  2s .com
        factory.setPort(mqPort);
        factory.setUsername(mqUser);
        factory.setPassword(mqPassword);
        factory.setVirtualHost(mqVirtualHost);
        factory.setRequestedHeartbeat(10);
        mqConnection = factory.newConnection();
    }
    return mqConnection;
}

From source file:com.kenshoo.flume.rabbitmq.SimpleRabbitMqProducer.java

License:Apache License

public SimpleRabbitMqProducer(String hosts, String userName, String password, String virtualHost) {
    factory = new ConnectionFactory();
    factory.setUsername(userName);/*www  . java 2 s . co m*/
    factory.setPassword(password);
    factory.setVirtualHost(virtualHost);
    factory.setPort(5672);
    this.hosts = hosts;
}

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 va2  s.  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.lang.pat.rabbitirc.Consumer.java

public Consumer() {
    try {//from  w w w  . j a  va2s  .co m
        factory = new ConnectionFactory();
        factory.setHost(ClientMain.HOSTNAME);
        connection = factory.newConnection();
        channel = connection.createChannel();
        ClientMain.QUEUENAME = channel.queueDeclare().getQueue();
    } catch (IOException ex) {
        Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TimeoutException ex) {
        Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.lang.pat.rabbitirc.Producer.java

public Producer() {
    try {//w  w w  .ja va2  s. c  o m
        factory = new ConnectionFactory();
        factory.setHost(ClientMain.HOSTNAME);

        connection = factory.newConnection();
        channel = connection.createChannel();
        channel.exchangeDeclare(ClientMain.EXCHANGE_NAME, "direct");
    } catch (IOException ex) {
        Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TimeoutException ex) {
        Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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 + "'");
    }/* www .  java  2s.c  o  m*/

}

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  a  v a2s.c om
    channel.basicPublish(EXCHANGE_NAME, "", bp, messageOut.getBytes());
    System.out.println(" [x] Sent by JSONtester: '" + messageOut + "'");

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

From source file:com.lumlate.midas.email.GmailReader.java

License:Apache License

/**
 * Authenticates to IMAP with parameters passed in on the commandline.
 *//* www.  ja  v  a2s  .c  o  m*/
public static void main(String args[]) throws Exception {

    String mysqlhost = "localhost";
    String mysqlport = "3306";
    String mysqluser = "lumlate";
    String mysqlpassword = "lumlate$";
    String database = "lumlate";
    MySQLAccess myaccess = new MySQLAccess(mysqlhost, mysqlport, mysqluser, mysqlpassword, database);

    String email = "sharmavipul@gmail.com";
    String oauthToken = "1/co5CyT8QrJXyJagK5wzWNGZk2RTA0FU_dF9IhwPvlBs";
    String oauthTokenSecret = "aK5LCYOFrUweFPfMcPYNXWzg";
    String TASK_QUEUE_NAME = "gmail_oauth";
    String rmqserver = "rmq01.deallr.com";

    initialize();
    IMAPSSLStore imapSslStore = connectToImap("imap.googlemail.com", 993, email, oauthToken, oauthTokenSecret,
            getDeallrConsumer(), true);
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(rmqserver);
    factory.setUsername("lumlate");
    factory.setPassword("lumlate$");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

    Folder folder = imapSslStore.getFolder("INBOX");//get inbox
    folder.open(Folder.READ_WRITE);//open folder only to read
    SearchTerm flagterm = new FlagTerm(new Flags(Flags.Flag.SEEN), false);

    RetailersDAO retaildao = new RetailersDAO();
    retaildao.setStmt(myaccess.getConn().createStatement());
    LinkedList<String> retaildomains = retaildao.getallRetailerDomains();
    LinkedList<SearchTerm> searchterms = new LinkedList<SearchTerm>();
    for (String retaildomain : retaildomains) {
        SearchTerm retailsearchterm = new FromStringTerm(retaildomain);
        searchterms.add(retailsearchterm);
    }
    SearchTerm[] starray = new SearchTerm[searchterms.size()];
    searchterms.toArray(starray);
    SearchTerm st = new OrTerm(starray); //TODO add date to this as well so that fetch is since last time
    SearchTerm searchterm = new AndTerm(st, flagterm);

    Message message[] = folder.search(searchterm);
    for (int i = 0; i < message.length; i++) {
        Message msg = message[i];
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        msg.writeTo(bos);
        byte[] buf = bos.toByteArray();
        channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, buf);
    }
    myaccess.Dissconnect();
    channel.close();
    connection.close();
}