List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer addQueueNames
@Override public void addQueueNames(String... queueName)
From source file:org.farrukh.examples.amqp.Application.java
/** * Simple message listener container// w w w . ja v a 2s. co m * @param connectionFactory - RabbitMQ connection factory. * @param configuration - Custom application information. * @param messageListener - The message listener with delegate object in the adapter. * @return */ @Bean public SimpleMessageListenerContainer messageListenerContainer(final ConnectionFactory connectionFactory, final ApplicationProperties configuration, final MessageListener messageListener) { SimpleMessageListenerContainer messageListenerContainer = new SimpleMessageListenerContainer( connectionFactory); messageListenerContainer.addQueueNames(configuration.getQueueName()); messageListenerContainer.setMessageListener(messageListener); return messageListenerContainer; }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerLongTests.java
@Test public void testAddQueuesAndStartInCycle() throws Exception { final SingleConnectionFactory connectionFactory = new SingleConnectionFactory("localhost"); final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setMessageListener((MessageListener) message -> { });// w w w. ja v a 2 s .com container.setConcurrentConsumers(2); container.afterPropertiesSet(); RabbitAdmin admin = new RabbitAdmin(connectionFactory); for (int i = 0; i < 20; i++) { AnonymousQueue anonymousQueue = new AnonymousQueue(); admin.declareQueue(anonymousQueue); container.addQueueNames(anonymousQueue.getName()); if (!container.isRunning()) { container.start(); } } int n = 0; while (n++ < 100 && container.getActiveConsumerCount() != 2) { Thread.sleep(100); } assertEquals(2, container.getActiveConsumerCount()); container.stop(); connectionFactory.destroy(); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java
@Test public void testChangeQueues() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); Channel channel1 = mock(Channel.class); Channel channel2 = mock(Channel.class); when(channel1.isOpen()).thenReturn(true); when(channel2.isOpen()).thenReturn(true); when(connectionFactory.createConnection()).thenReturn(connection); when(connection.createChannel(false)).thenReturn(channel1, channel2); List<Consumer> consumers = new ArrayList<Consumer>(); AtomicInteger consumerTag = new AtomicInteger(); CountDownLatch latch1 = new CountDownLatch(1); CountDownLatch latch2 = new CountDownLatch(2); setupMockConsume(channel1, consumers, consumerTag, latch1); setUpMockCancel(channel1, consumers); setupMockConsume(channel2, consumers, consumerTag, latch2); setUpMockCancel(channel2, consumers); final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueueNames("foo"); container.setReceiveTimeout(1);// w ww . j av a2 s .c om container.setMessageListener((MessageListener) message -> { }); container.afterPropertiesSet(); container.start(); assertTrue(latch1.await(10, TimeUnit.SECONDS)); container.addQueueNames("bar"); assertTrue(latch2.await(10, TimeUnit.SECONDS)); container.stop(); verify(channel1).basicCancel("0"); verify(channel2, atLeastOnce()).basicCancel("1"); verify(channel2, atLeastOnce()).basicCancel("2"); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java
@SuppressWarnings("unchecked") @Test// w w w.j a va 2 s . c om public void testAddQueuesAndStartInCycle() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); Channel channel1 = mock(Channel.class); when(channel1.isOpen()).thenReturn(true); when(connectionFactory.createConnection()).thenReturn(connection); when(connection.createChannel(false)).thenReturn(channel1); final AtomicInteger count = new AtomicInteger(); doAnswer(invocation -> { Consumer cons = (Consumer) invocation.getArguments()[6]; String consumerTag = "consFoo" + count.incrementAndGet(); cons.handleConsumeOk(consumerTag); return consumerTag; }).when(channel1).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class)); final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setMessageListener((MessageListener) message -> { }); container.afterPropertiesSet(); for (int i = 0; i < 10; i++) { container.addQueueNames("foo" + i); if (!container.isRunning()) { container.start(); } } container.stop(); }