List of usage examples for com.rabbitmq.client ConnectionFactory setPassword
public void setPassword(String password)
From source file:Colas.Colas.java
private void sender(String string) { try {/* w w w.ja va 2s . c o m*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setPort(5672); factory.setUsername("valencia"); factory.setPassword("admin123"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare("SC", false, false, false, null); channel.basicPublish("", "SC", null, string.getBytes()); System.out.println(" [x] Sent '" + string + "'"); channel.close(); connection.close(); } catch (Exception e) { System.out.println("Error enviando "); e.printStackTrace(); } }
From source file:Colas.Colas.java
@Override public void run() { try {//from w w w . j a va2 s. co m ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setUsername("guest"); factory.setPassword("admin123"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare("CF", false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("CF", true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println(" [x] Received '" + message + "'"); String[] resp = message.split(";"); String p = resp[0]; if (p.equals("Q1")) { pregunta1(resp[1]); } if (p.equals("Q2")) { pregunta2(resp[1]); } if (p.equals("Q3")) { pregunta3(resp[1]); } if (p.equals("Q4")) { pregunta4(resp[1]); } } } catch (Exception e) { System.out.println("Error reciviendo "); e.printStackTrace(); } }
From source file:com.buzz.dbhandlers.RMQHandler.java
public RMQHandler(String host, String username, String passwd, String queue) throws IOException { Queue = queue;/*from w ww. j a v a 2 s. c om*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); factory.setUsername(username); factory.setPassword(passwd); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(Queue, false, false, false, null); }
From source file:com.codio.collab.core.queue.QueueFactory.java
License:Apache License
private void openConnection() { ConnectionFactory factory = new ConnectionFactory(); factory.setVirtualHost(getConnectionConfig().getVhost()); factory.setUsername(getConnectionConfig().getUser()); factory.setPassword(getConnectionConfig().getPassword()); factory.setPort(getConnectionConfig().getPort()); factory.setHost(getConnectionConfig().getHost()); factory.setAutomaticRecoveryEnabled(true); try {/* w w w .j a va 2 s . com*/ connection = factory.newConnection(); } catch (IOException e) { LOG.error("Can not open rmq connection {}", e.getMessage()); } }
From source file:com.colm.app.Main.java
License:Open Source License
public static void main(String[] args) throws Exception { Connection connection;//from w w w .j a v a 2 s . c om Channel channel; String replyQueueName; ConnectionFactory factory = new ConnectionFactory(); factory.setHost("192.168.0.13"); factory.setPassword("admin"); factory.setUsername("admin"); factory.setVirtualHost("admin"); connection = factory.newConnection(); channel = connection.createChannel(); String queneNAme = "rabbitmq_test"; channel.queueDeclare(queneNAme, false, false, false, null); String message = "Something Else"; for (int i = 0; i < 1000; i++) { channel.basicPublish("", queneNAme, null, message.getBytes()); } System.out.println("Sent '" + message + "'"); channel.close(); connection.close(); }
From source file:com.espertech.esperio.amqp.AMQPSink.java
License:Open Source License
public void open(DataFlowOpOpenContext openContext) { log.info("Opening AMQP, settings are: " + settings.toString()); try {/*from ww w .j av a2 s .c o m*/ final ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(settings.getHost()); if (settings.getPort() > -1) { connectionFactory.setPort(settings.getPort()); } if (settings.getUsername() != null) { connectionFactory.setUsername(settings.getUsername()); } if (settings.getPassword() != null) { connectionFactory.setPassword(settings.getPassword()); } if (settings.getVhost() != null) { connectionFactory.setVirtualHost(settings.getVhost()); } connection = connectionFactory.newConnection(); channel = connection.createChannel(); if (settings.getExchange() != null) { channel.exchangeDeclarePassive(settings.getExchange()); } final AMQP.Queue.DeclareOk queue; if (settings.getQueueName() == null || settings.getQueueName().trim().length() == 0) { queue = channel.queueDeclare(); } else { // java.lang.String queue,boolean durable,boolean exclusive,boolean autoDelete,java.util.Map<java.lang.String,java.lang.Object> arguments) throws java.io.IOException queue = channel.queueDeclare(settings.getQueueName(), settings.isDeclareDurable(), settings.isDeclareExclusive(), settings.isDeclareAutoDelete(), settings.getDeclareAdditionalArgs()); } if (settings.getExchange() != null && settings.getRoutingKey() != null) { channel.queueBind(queue.getQueue(), settings.getExchange(), settings.getRoutingKey()); } final String queueName = queue.getQueue(); log.info("AMQP producing queue is " + queueName + (settings.isLogMessages() ? " with logging" : "")); } catch (IOException e) { String message = "AMQP setup failed: " + e.getMessage(); log.error(message, e); throw new RuntimeException(message, e); } }
From source file:com.espertech.esperio.amqp.AMQPSource.java
License:Open Source License
public void open(DataFlowOpOpenContext openContext) { log.info("Opening AMQP, settings are: " + settings.toString()); try {//from ww w. j a va2s .c om final ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(settings.getHost()); if (settings.getPort() > -1) { connectionFactory.setPort(settings.getPort()); } if (settings.getUsername() != null) { connectionFactory.setUsername(settings.getUsername()); } if (settings.getPassword() != null) { connectionFactory.setPassword(settings.getPassword()); } if (settings.getVhost() != null) { connectionFactory.setVirtualHost(settings.getVhost()); } connection = connectionFactory.newConnection(); channel = connection.createChannel(); channel.basicQos(settings.getPrefetchCount()); if (settings.getExchange() != null) { channel.exchangeDeclarePassive(settings.getExchange()); } final AMQP.Queue.DeclareOk queue; if (settings.getQueueName() == null || settings.getQueueName().trim().length() == 0) { queue = channel.queueDeclare(); } else { // java.lang.String queue,boolean durable,boolean exclusive,boolean autoDelete,java.util.Map<java.lang.String,java.lang.Object> arguments) throws java.io.IOException queue = channel.queueDeclare(settings.getQueueName(), settings.isDeclareDurable(), settings.isDeclareExclusive(), settings.isDeclareAutoDelete(), settings.getDeclareAdditionalArgs()); } if (settings.getExchange() != null && settings.getRoutingKey() != null) { channel.queueBind(queue.getQueue(), settings.getExchange(), settings.getRoutingKey()); } final String queueName = queue.getQueue(); log.info("AMQP consuming queue " + queueName + (settings.isLogMessages() ? " with logging" : "")); consumer = new QueueingConsumer(channel); consumerTag = channel.basicConsume(queueName, settings.isConsumeAutoAck(), consumer); } catch (IOException e) { String message = "AMQP source setup failed: " + e.getMessage(); log.error(message, e); throw new EPException(message, e); } }
From source file:com.flipkart.bifrost.framework.Connection.java
License:Apache License
/** * Start the connection. This will try to connect to the cluster hosts provided in the contructor. * Will throw an error in case of failure. * @throws BifrostException in case of connection failure. *///from w w w . j a v a 2s. co m public void start() throws BifrostException { ConnectionFactory connectionFactory = new ConnectionFactory(); Address brokers[] = new Address[hosts.size()]; int i = 0; for (String member : hosts) { brokers[i++] = new Address(member); } connectionFactory.setUsername(username); connectionFactory.setPassword(password); connectionFactory.setAutomaticRecoveryEnabled(true); connectionFactory.setTopologyRecoveryEnabled(true); try { connection = connectionFactory.newConnection(brokers); } catch (IOException e) { throw new BifrostException(BifrostException.ErrorCode.IO_ERROR, "Could not connect", e); } }
From source file:com.github.liyp.rabbitmq.demo2.Producer.java
License:Apache License
public static void main(String[] args) throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername("liyp"); factory.setPassword("liyp"); factory.setVirtualHost("/"); factory.setHost("127.0.0.1"); factory.setPort(5672);/* ww w.ja v a2 s. co m*/ Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); for (int i = 0; i < 10000; i++) { byte[] messageBodyBytes = "Hello, world!".getBytes(); channel.basicPublish("", "my-queue", null, messageBodyBytes); System.out.println(channel.isOpen()); } channel.close(); conn.close(); }
From source file:com.googlesource.gerrit.plugins.rabbitmq.AMQPSession.java
License:Apache License
public void connect() { LOGGER.info("Connect to {}...", properties.getString(Keys.AMQP_URI)); ConnectionFactory factory = new ConnectionFactory(); try {/* w w w . jav a 2 s . com*/ if (StringUtils.isNotEmpty(properties.getString(Keys.AMQP_URI))) { factory.setUri(properties.getString(Keys.AMQP_URI)); if (StringUtils.isNotEmpty(properties.getString(Keys.AMQP_USERNAME))) { factory.setUsername(properties.getString(Keys.AMQP_USERNAME)); } if (StringUtils.isNotEmpty(properties.getString(Keys.AMQP_PASSWORD))) { factory.setPassword(properties.getString(Keys.AMQP_PASSWORD)); } connection = factory.newConnection(); connection.addShutdownListener(this); LOGGER.info("Connection established."); } //TODO: Consume review // setupConsumer(); } catch (URISyntaxException ex) { LOGGER.error("URI syntax error: {}", properties.getString(Keys.AMQP_URI)); } catch (IOException ex) { LOGGER.error("Connection cannot be opened."); } catch (Exception ex) { LOGGER.warn("Connection has something error. it will be disposed.", ex); } }