/** * Sets up the queue. The default implementation just declares the queue. The user may override * this method to have a custom setup for the queue (i.e. binding the queue to an exchange or * defining custom queue parameters) */ protected void setupQueue() throws IOException { if (queueName != null) { channel.queueDeclare(queueName, false, false, false, null); } }
/** * Sets up the queue. The default implementation just declares the queue. The user may override * this method to have a custom setup for the queue (i.e. binding the queue to an exchange or * defining custom queue parameters) */ protected void setupQueue() throws IOException { channel.queueDeclare(queueName, true, false, false, null); }
channel.queueDeclare(queueName, true, false, false, null); if (exchangeBind) { channel.queueBind(queueName, exchange, routingKey);
@Test public void simpleRabbitMqTest() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(rabbitMq.getContainerIpAddress()); factory.setPort(rabbitMq.getMappedPort(RABBITMQ_PORT)); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(RABBIQMQ_TEST_EXCHANGE, "direct", true); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, RABBIQMQ_TEST_EXCHANGE, RABBITMQ_TEST_ROUTING_KEY); // Set up a consumer on the queue final boolean[] messageWasReceived = new boolean[1]; channel.basicConsume(queueName, false, new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { messageWasReceived[0] = Arrays.equals(body, RABBITMQ_TEST_MESSAGE.getBytes()); } }); // post a message channel.basicPublish(RABBIQMQ_TEST_EXCHANGE, RABBITMQ_TEST_ROUTING_KEY, null, RABBITMQ_TEST_MESSAGE.getBytes()); // check the message was received assertTrue("The message was received", Unreliables.retryUntilSuccess(5, TimeUnit.SECONDS, () -> { if (!messageWasReceived[0]) { throw new IllegalStateException("Message not received yet"); } return true; })); }
private void connect() throws IOException { Map<String, Object> arguments = new HashMap<>(); arguments.put("x-queue-mode", "lazy"); // we want to minimize memory usage; see http://www.rabbitmq.com/lazy-queues.html boolean lazys = lazy.get(); try { RabbitQueueFactory.this.channel.queueDeclare(this.queueName, true, false, false, lazys ? arguments : null); } catch (AlreadyClosedException e) { lazys = !lazys; try { channel = connection.createChannel(); // may happen if a queue was previously not declared "lazy". So we try non-lazy queue setting now. RabbitQueueFactory.this.channel.queueDeclare(this.queueName, true, false, false, lazys ? arguments : null); // if this is successfull, set the new lazy value lazy.set(lazys); } catch (AlreadyClosedException ee) { throw new IOException(ee.getMessage()); } } }
channel.queueDeclare(queue, durable, exclusive, autoDelete, null); channel.queueBind(queue, exchange, routingKey); channel.addShutdownListener(
public void construct() { try { eventChan = conn.createChannel(); eventChan.queueDeclare(queueName, false, false, true, queueArguments()); eventChan.basicConsume(queueName, true, this); } catch (IOException e) { throw new CloudRuntimeException(e); } }
public void construct() { try { nrouteChan = conn.createChannel(); nrouteChan.queueDeclare(nrouteName, false, false, true, null); nrouteChan.queueBind(nrouteName, BusExchange.NO_ROUTE.toString(), ""); nrouteChan.basicConsume(nrouteName, true, this); } catch (IOException e) { throw new CloudRuntimeException(e); } }
public static void main(String[] args) { try { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername("guest"); factory.setPassword("guest"); factory.setHost("60.205.191.82"); factory.setPort(5672); Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); // channel.qu channel.queueDeclare("hello", false, false, false, null); String message = "Hello World!"; channel.basicPublish("", "hello", null, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); conn.close(); } catch (IOException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } } }
void init() { try { ConnectionFactory connFactory = new ConnectionFactory(); List<Address> addresses = CollectionUtils.transformToList(bus.getServerIps(), new Function<Address, String>() { @Override public Address call(String arg) { return Address.parseAddress(arg); } }); conn = connFactory.newConnection(addresses.toArray(new Address[]{})); chan = conn.createChannel(); String name = MessageTracker.class.getName(); chan.queueDeclare(name, true, false, true, null); chan.basicConsume(name, true, this); chan.queueBind(name, BusExchange.P2P.toString(), "#"); chan.queueBind(name, BusExchange.BROADCAST.toString(), "#"); } catch (Exception e) { throw new CloudRuntimeException(e); } }
@Override public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclare() throws IOException { return this.delegate.queueDeclare(); }
@Override public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments) throws IOException { return this.delegate.queueDeclare(queue, durable, exclusive, autoDelete, arguments); }
chan.queueDeclare(name, false, false, true, null); chan.basicConsume(name, true, tracker); chan.queueBind(name, BusExchange.BROADCAST.toString(), "#");
@SuppressWarnings("unchecked") @Test public void testPtP() throws Exception { final Channel channel = mock(Channel.class); DeclareOk declareOk = mock(DeclareOk.class); when(declareOk.getQueue()).thenReturn("noSubscribersChannel"); when(channel.queueDeclare(anyString(), anyBoolean(), anyBoolean(), anyBoolean(), isNull())) .thenReturn(declareOk); Connection connection = mock(Connection.class); doAnswer(invocation -> channel).when(connection).createChannel(anyBoolean()); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(connection); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); PointToPointSubscribableAmqpChannel amqpChannel = new PointToPointSubscribableAmqpChannel("noSubscribersChannel", container, amqpTemplate); amqpChannel.setBeanName("noSubscribersChannel"); amqpChannel.setBeanFactory(mock(BeanFactory.class)); amqpChannel.afterPropertiesSet(); MessageListener listener = (MessageListener) container.getMessageListener(); try { listener.onMessage(new Message("Hello world!".getBytes(), null)); fail("Exception expected"); } catch (MessageDeliveryException e) { assertThat(e.getMessage(), containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.")); } }
outboundQueue = new BusQueue(makeMessageQueueName(SERVICE_ID), BusExchange.P2P); Channel chan = channelPool.acquire(); chan.queueDeclare(outboundQueue.getName(), false, false, true, queueArguments()); chan.basicConsume(outboundQueue.getName(), true, consumer); chan.queueBind(outboundQueue.getName(), outboundQueue.getBusExchange().toString(), outboundQueue.getBindingKey());
protected String setupQueue(Channel on) throws IOException { String queueName = on.queueDeclare().getQueue(); on.exchangeDeclare("bergamot.update", "topic", true); on.queueBind(queueName, "bergamot.update", (site == null ? "*" : site.toString()) + "." + (check == null ? "*" : check.toString())); return queueName; }
public String setupQueue(Channel on) throws IOException { on.queueDeclare("bergamot.reading.fallback_queue", true, false, false, null); on.exchangeDeclare("bergamot.reading.fallback", "fanout", true, false, null); on.queueBind("bergamot.reading.fallback_queue", "bergamot.reading.fallback", ""); return "bergamot.reading.fallback_queue"; } };
public String setupQueue(Channel on) throws IOException { // exchange on.exchangeDeclare("bergamot.notification", "topic", true); // queue String queueName = on.queueDeclare().getQueue(); // bind using the site on.queueBind(queueName, "bergamot.notification", site == null ? "#" : site.toString()); return queueName; } };
@Bean QueueingConsumer queueingConsumer() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(messageQueueHostname); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(Constants.ANSWERSHEET_DATA_QUEUE, true, false, false, null); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(Constants.ANSWERSHEET_DATA_QUEUE, true, consumer); return consumer; }
@Override public void open() throws IOException { getChannel().exchangeDeclare(exchange, "direct"); getChannel().queueDeclare(queueName, true, false, false, null); for (String routingKey : routingKeys) { getChannel().queueBind(queueName, exchange, routingKey); } getChannel().basicConsume(queueName, false, this); }