List of usage examples for com.rabbitmq.client ConnectionFactory setPort
public void setPort(int port)
From source file:Colas.Colas.java
private void sender(String string) { try {/*from w ww . ja v a 2 s . 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:com.adr.data.rabbitmq.RabbitServer.java
License:Apache License
protected Connection connect() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host);//from ww w . j a v a2s . co m factory.setPort(port); return factory.newConnection(); }
From source file:com.arakelian.docker.junit.RabbitIntegrationTest.java
License:Apache License
@Test public void testConnectsToDocker() throws ExecutionException, RetryException { final Retryer<Void> retryer = RetryerBuilder.<Void>newBuilder() // .retryIfException() // .withStopStrategy(StopStrategies.stopAfterDelay(1, TimeUnit.MINUTES)) // .withWaitStrategy(WaitStrategies.fixedWait(5, TimeUnit.SECONDS)) // .build();/*from w w w . j a v a 2 s .co m*/ // wait for RabbitMQ retryer.call(() -> { final ConnectionFactory factory = new ConnectionFactory(); final Container container = rabbitmq.getContainer(); final Binding binding = container.getPortBinding("5672/tcp"); factory.setHost(binding.getHost()); factory.setPort(binding.getPort()); final Connection connection = factory.newConnection(); connection.close(); return null; }); }
From source file:com.boulmier.machinelearning.jobexecutor.consumer.RequestConsumer.java
public RequestConsumer(InetAddress vmscheduler_ip, Integer port) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(vmscheduler_ip.getHostAddress()); if (port != null) { factory.setPort(port); }/*w w w.j a v a 2 s. com*/ connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, true, false, false, null); consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, false, consumer); }
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 {/*ww w . ja v a 2 s. com*/ connection = factory.newConnection(); } catch (IOException e) { LOG.error("Can not open rmq connection {}", e.getMessage()); } }
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 . ja v a2 s. com 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 {//www . j a v 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(); 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.eventbook.controller.SpringbootPocController.java
@RequestMapping(value = "/rabbitMQSendTest", method = RequestMethod.GET) public String rabbitMQSendTest(@RequestParam(value = "message", defaultValue = "Hello World!") String message) { try {//www .j av a 2 s. c o m ConnectionFactory factory = new ConnectionFactory(); factory.setHost("rabbitmq"); factory.setPort(5672); 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(); connection.close(); return "rabbitMQSendTest Sent: " + message; } catch (IOException | TimeoutException ex) { Logger.getLogger(SpringbootPocController.class.getName()).log(Level.SEVERE, null, ex); } return "rabbitMQSendTest has been failed!!!"; }
From source file:com.eventbook.controller.SpringbootPocController.java
@RequestMapping(value = "/rabbitMQReceiveTest", method = RequestMethod.GET) public String rabbitMQReceiveTest() { try {/*from w ww. j a v a 2 s . c o m*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("rabbitmq"); factory.setPort(5672); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); 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 + "'"); } }; channel.basicConsume(QUEUE_NAME, true, consumer); } catch (IOException | TimeoutException ex) { Logger.getLogger(SpringbootPocController.class.getName()).log(Level.SEVERE, null, ex); } return "Getting messages from RabbitMQ!!"; }
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); 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()); }/*from w w w .j a v a 2 s .co m*/ channel.close(); conn.close(); }