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:mailmonk.client.MailMonk.java

License:Apache License

/**
 * Connect to a Message Queue and open a channel for 
 * sending Mail Monk jobs./*from w w w .java 2s  .c  om*/
 * */
public void connect() {
    try {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername(getUsername());
        factory.setPassword(getPassword());
        factory.setHost(getHost());

        connection = factory.newConnection();

        channel = connection.createChannel();
        channel.queueDeclare(getQueueName(), false, false, false, null);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:main.TestMain.java

public static void sendMessage(String message) 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.queueDeclare(QUEUE_NAME, false, false, false, null);

    channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();/*from   ww w. j  a  va 2 s  .c o m*/
    connection.close();
}

From source file:mains.RaspiSensorModule_0.java

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

    //________ Basic subscribe direct (Routing) __________
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(host);/*www . j a  v a  2s  .  com*/
    factory.setUsername("piadmin");
    factory.setPassword("3828");
    Connection connection = factory.newConnection();
    System.setProperty("java.rmi.server.hostname", thisIp);

    ControllerPublisher conPub = new ControllerPublisher(connection, NODE_ID);
    LED_Controller ledCon = new LED_Controller("ledControllerRealTest");
    LCD_Controller lcdCon = new LCD_Controller("lcdController_messeges");

    //   NodeController ledCon1 = new NodeController("ledControllerFloor");
    //   NodeController ledCon2 = new NodeController("ledControllerCabin");

    conPub.publishController(ledCon);
    conPub.publishController(lcdCon);

    //     conPub.publishController(ledCon1);
    //   conPub.publishController(ledCon2);

    NodeSensorHandler nodeSensors = new NodeSensorHandler(connection, SENSOR_EXCHANGE,
            SENSOR_ROUT_KEY_BASE + NODE_ID);
    System.out.println("Sensors up");
    //        BusRMIConnector rmiConnection = new BusRMIConnector(connection, SENSOR_EXCHANGE, SENSOR_ROUT_KEY_BASE + NODE_ID);
    //        System.out.println("RMI up");

    System.in.read();

    connection.close();
}

From source file:mapas.Mapas.java

public static void main(String[] args) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    factory.setPassword("test");
    factory.setUsername("test");
    final Connection connection = factory.newConnection();

    final Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    channel.basicQos(1);//from   w  ww .  j  a  v  a 2s  . c o  m

    final 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 + "'");
            try {
                doWork(message);
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
            System.out.println(" [x] Done");
            channel.basicAck(envelope.getDeliveryTag(), false);

        }
    };
    channel.basicConsume(TASK_QUEUE_NAME, false, consumer);
}

From source file:mx.bigdata.utils.amqp.AMQPClientHelperImpl.java

License:Apache License

public ConnectionFactory createConnectionFactory(String key) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    String username = getValueOrDefault("amqp_username", key);
    if (username != null) {
        factory.setUsername(username);/*from   w  w w.j  a  v a2  s . c o  m*/
    }
    String password = getValueOrDefault("amqp_password", key);
    if (password != null) {
        factory.setPassword(password);
    }
    String virtualHost = getValueOrDefault("amqp_virtual_host", key);
    if (virtualHost != null) {
        factory.setVirtualHost(virtualHost);
    }
    String host = getValueOrDefault("amqp_host", key);
    if (host != null) {
        factory.setHost(host);
    }
    Integer port = getIntegerOrDefault("amqp_port", key);
    if (port != null) {
        factory.setPort(port);
    }
    return factory;
}

From source file:net.duckling.falcon.api.mq.DFMQManager.java

License:Apache License

public DFMQManager(String userName, String password, String host) {
    ConnectionFactory factory = new ConnectionFactory();
    try {/*  ww  w. j av  a2s .  co  m*/
        factory.setUsername(userName);
        factory.setPassword(password);
        factory.setHost(host);
        connection = factory.newConnection();
        channel = connection.createChannel();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.duckling.falcon.api.mq.impl.DFMQBasePublisherClient.java

License:Apache License

public DFMQBasePublisherClient(String username, String password, String host) {
    this.host = host;
    this.password = password;
    this.username = username;
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(host);/*www. ja v a2 s  . c  om*/
    factory.setPassword(password);
    factory.setUsername(username);
    try {
        connection = factory.newConnection();
        channel = connection.createChannel();
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:net.duckling.falcon.api.mq.impl.DFMQBaseSubscriberClient.java

License:Apache License

public DFMQBaseSubscriberClient(String username, String password, String host) {
    this.host = host;
    this.username = username;
    this.password = password;
    this.ssm = new SimpleStringMatch();
    this.handlerMap = new HashMap<String, IDFMessageHandler>();
    ConnectionFactory factory = new ConnectionFactory();
    try {/*from  w  w  w .j  a  v a2  s . c  o  m*/
        factory.setHost(host);
        factory.setUsername(username);
        factory.setPassword(password);
        connection = factory.newConnection();
        channel = connection.createChannel();
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    } catch (ShutdownSignalException e) {
        LOG.error(e.getMessage(), e);
    } catch (ConsumerCancelledException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:net.echinopsii.ariane.community.messaging.rabbitmq.Client.java

License:Open Source License

/**
 * Initialize RabbitMQ connection with provided properties and this client ServiceFactory.
 * <br/>//  www .j  a v a2  s  .c o  m
 * Following properties fields MUST be defined :
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_HOST}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_PORT}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_VHOST}
 * <br/>
 * Following properties fields MAY be defined:
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_USER}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_PSWD}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_MSG_DEBUG_ON_TIMEOUT}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_ROUTEES_NB_PER_SERVICE}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_RPC_TIMEOUT}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_RPC_RETRY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_INFORMATION_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_PRODUCT_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_PLATFORM_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_COPYRIGHT_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_VERSION_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_APP_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_CMP_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_OSI_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_OTM_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_PGURL_KEY}
 * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_PID_KEY}
 * @param properties configuration properties
 * @throws IOException if problems to join NATS server
 */
@Override
public void init(Dictionary properties) throws IOException {
    if (properties.get(MomClient.RBQ_INFORMATION_KEY) != null)
        super.setClientID((String) properties.get(MomClient.RBQ_INFORMATION_KEY));
    if (properties.get(MOM_CLI_MSG_DEBUG_ON_TIMEOUT) != null
            && (((String) properties.get(MOM_CLI_MSG_DEBUG_ON_TIMEOUT)).toLowerCase().equals("true")))
        super.setMsgDebugOnTimeout(true);
    if (properties.get(MOM_CLI_ROUTEES_NB_PER_SERVICE) != null)
        super.setRouteesCountPerService(new Integer((String) properties.get(MOM_CLI_ROUTEES_NB_PER_SERVICE)));
    try {
        if (Class.forName("akka.osgi.ActorSystemActivator") != null
                && MessagingAkkaSystemActivator.getSystem() != null)
            super.setActorSystem(MessagingAkkaSystemActivator.getSystem());
        else
            super.setActorSystem(ActorSystem.create("MySystem"));
    } catch (ClassNotFoundException e) {
        super.setActorSystem(ActorSystem.create("MySystem"));
    }

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost((String) properties.get(MOM_HOST));
    factory.setPort(new Integer((String) properties.get(MOM_PORT)));
    if (properties.get(RBQ_VHOST) != null)
        factory.setVirtualHost((String) properties.get(RBQ_VHOST));
    if (properties.get(MOM_USER) != null)
        factory.setUsername((String) properties.get(MOM_USER));
    if (properties.get(MOM_PSWD) != null)
        factory.setPassword((String) properties.get(MOM_PSWD));

    Map<String, Object> factoryProperties = factory.getClientProperties();
    if (properties.get(MomClient.RBQ_PRODUCT_KEY) != null)
        factoryProperties.put(RBQ_PRODUCT_KEY, properties.get(MomClient.RBQ_PRODUCT_KEY));
    if (properties.get(MomClient.RBQ_INFORMATION_KEY) != null)
        factoryProperties.put(RBQ_INFORMATION_KEY, super.getClientID());
    if (properties.get(MomClient.RBQ_PLATFORM_KEY) != null)
        factoryProperties.put(RBQ_PLATFORM_KEY, properties.get(MomClient.RBQ_PLATFORM_KEY));
    else
        factoryProperties.put(RBQ_PLATFORM_KEY, "Java " + System.getProperty("java.version"));
    if (properties.get(MomClient.RBQ_COPYRIGHT_KEY) != null)
        factoryProperties.put(RBQ_COPYRIGHT_KEY, properties.get(MomClient.RBQ_COPYRIGHT_KEY));
    if (properties.get(MomClient.RBQ_VERSION_KEY) != null)
        factoryProperties.put(RBQ_VERSION_KEY, properties.get(MomClient.RBQ_VERSION_KEY));

    Enumeration keys = properties.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof String && ((String) key).startsWith(MomClient.ARIANE_KEYS))
            factoryProperties.put((String) key, properties.get((String) key));
    }

    connection = factory.newConnection();

    super.setServiceFactory(new ServiceFactory(this));
}

From source file:net.es.netshell.rabbitmq.SSLConnection.java

License:Open Source License

public ConnectionFactory createConnection() throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(host);/*  w  w w . j  av a 2  s. co  m*/
    factory.setUsername(user);
    factory.setPassword(password);
    factory.setPort(port);

    if (ssl) {
        char[] keyPassphrase = KEYPASS.toCharArray();
        KeyStore ks = KeyStore.getInstance("PKCS12");
        ks.load(new FileInputStream(KEYCERT), keyPassphrase);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(ks, keyPassphrase);

        char[] trustPassphrase = TRUSTPASS.toCharArray();
        KeyStore tks = KeyStore.getInstance("JKS");
        tks.load(new FileInputStream(KEYSTORE), trustPassphrase);

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(tks);

        SSLContext c = SSLContext.getInstance("SSLv3");
        c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

        factory.useSslProtocol(c);
    }
    return factory;
}