List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setQueueNames
@Override public void setQueueNames(String... queueName)
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean SimpleMessageListenerContainer container_eventRegister(ConnectionFactory connectionFactory, @Qualifier("listenerAdapter_nfvoGenericActions") MessageListenerAdapter listenerAdapter) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName_nfvoGenericActions); if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) { container.setConcurrentConsumers(5); container.setMaxConcurrentConsumers(15); } else {/*from w ww . ja v a 2 s. c o m*/ container.setConcurrentConsumers(minConcurrency); container.setMaxConcurrentConsumers(maxConcurrency); } container.setMessageListener(listenerAdapter); return container; }
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean SimpleMessageListenerContainer container_emsRegistrator(ConnectionFactory connectionFactory) { if (listenerAdapter_emsRegistrator != null) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName_emsRegistrator); container.setConcurrentConsumers(1); container.setMaxConcurrentConsumers(15); container.setMessageListener(listenerAdapter_emsRegistrator); return container; } else/*from w w w.j a va2 s . c o m*/ return null; }
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean SimpleMessageListenerContainer container_logDispatcher(ConnectionFactory connectionFactory, @Qualifier("listenerAdapter_logDispatch") MessageListenerAdapter listenerAdapter) { if (listenerAdapter != null) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName_logDispatch); if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) { container.setConcurrentConsumers(5); container.setMaxConcurrentConsumers(15); } else {//from w w w .jav a 2s .c o m container.setConcurrentConsumers(minConcurrency); container.setMaxConcurrentConsumers(maxConcurrency); } container.setMessageListener(listenerAdapter); return container; } else return null; }
From source file:crawler.configuration.rabbitmq.RabbitMQConfiguration.java
@Bean SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(htmlQueue().getName()); container.setMessageListener(this); container.setConcurrentConsumers(rabbitMQConfigurationProperties.getConcurrentConsumers()); // container.setMaxConcurrentConsumers(32); container.setPrefetchCount(rabbitMQConfigurationProperties.getPrefetchCount()); // rabbitListenerContainerFactory.setConcurrentConsumers(16); return container; }
From source file:limey.git.amqp.SampleAmqpSimpleApplication.java
@Bean public SimpleMessageListenerContainer container() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory); Object listener = new Object() { @SuppressWarnings("unused") public void handleMessage(String foo) { System.out.println(foo); }// www.j a v a 2s . com }; MessageListenerAdapter adapter = new MessageListenerAdapter(listener); container.setMessageListener(adapter); container.setQueueNames("foo"); return container; }
From source file:org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactoryTests.java
@SuppressWarnings("unchecked") @Test/*from w ww .j av a 2 s . com*/ public void testFailOver() throws Exception { ConnectionFactory defaultConnectionFactory = mockCF("localhost:1234", null); String rabbit1 = "localhost:1235"; String rabbit2 = "localhost:1236"; String[] addresses = new String[] { rabbit1, rabbit2 }; String[] adminUris = new String[] { "http://localhost:11235", "http://localhost:11236" }; String[] nodes = new String[] { "rabbit@foo", "rabbit@bar" }; String vhost = "/"; String username = "guest"; String password = "guest"; final AtomicBoolean firstServer = new AtomicBoolean(true); final Client client1 = doCreateClient(adminUris[0], username, password, nodes[0]); final Client client2 = doCreateClient(adminUris[1], username, password, nodes[1]); final Map<String, ConnectionFactory> mockCFs = new HashMap<String, ConnectionFactory>(); CountDownLatch latch1 = new CountDownLatch(1); CountDownLatch latch2 = new CountDownLatch(1); mockCFs.put(rabbit1, mockCF(rabbit1, latch1)); mockCFs.put(rabbit2, mockCF(rabbit2, latch2)); LocalizedQueueConnectionFactory lqcf = new LocalizedQueueConnectionFactory(defaultConnectionFactory, addresses, adminUris, nodes, vhost, username, password, false, null) { @Override protected Client createClient(String adminUri, String username, String password) throws MalformedURLException, URISyntaxException { return firstServer.get() ? client1 : client2; } @Override protected ConnectionFactory createConnectionFactory(String address, String node) throws Exception { return mockCFs.get(address); } }; Log logger = spy(TestUtils.getPropertyValue(lqcf, "logger", Log.class)); doReturn(true).when(logger).isInfoEnabled(); new DirectFieldAccessor(lqcf).setPropertyValue("logger", logger); doAnswer(new CallsRealMethods()).when(logger).debug(anyString()); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(lqcf); container.setQueueNames("q"); container.afterPropertiesSet(); container.start(); assertTrue(latch1.await(10, TimeUnit.SECONDS)); Channel channel = this.channels.get(rabbit1); assertNotNull(channel); verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), Matchers.any(Consumer.class)); verify(logger, atLeast(1)).info(captor.capture()); assertTrue(assertLog(captor.getAllValues(), "Queue: q is on node: rabbit@foo at: localhost:1235")); // Fail rabbit1 and verify the container switches to rabbit2 firstServer.set(false); this.consumers.get(rabbit1).handleCancel(consumerTags.get(rabbit1)); assertTrue(latch2.await(10, TimeUnit.SECONDS)); channel = this.channels.get(rabbit2); assertNotNull(channel); verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), Matchers.any(Consumer.class)); container.stop(); verify(logger, atLeast(1)).info(captor.capture()); assertTrue(assertLog(captor.getAllValues(), "Queue: q is on node: rabbit@bar at: localhost:1236")); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testDebatchByContainer() throws Exception { final List<Message> received = new ArrayList<Message>(); final CountDownLatch latch = new CountDownLatch(2); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory); container.setQueueNames(ROUTE); container.setMessageListener((MessageListener) message -> { received.add(message);//from w ww. j a v a2 s. c o m latch.countDown(); }); container.setReceiveTimeout(100); container.afterPropertiesSet(); container.start(); try { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); Message message = new Message("foo".getBytes(), props); template.send("", ROUTE, message); message = new Message("bar".getBytes(), props); template.send("", ROUTE, message); assertTrue(latch.await(10, TimeUnit.SECONDS)); assertEquals(2, received.size()); assertEquals("foo", new String(received.get(0).getBody())); assertEquals(3, received.get(0).getMessageProperties().getContentLength()); assertEquals("bar", new String(received.get(1).getBody())); assertEquals(3, received.get(0).getMessageProperties().getContentLength()); } finally { container.stop(); } }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testDebatchByContainerPerformance() throws Exception { final List<Message> received = new ArrayList<Message>(); int count = 100000; final CountDownLatch latch = new CountDownLatch(count); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory); container.setQueueNames(ROUTE); container.setMessageListener((MessageListener) message -> { received.add(message);/*from ww w. j a v a 2s .com*/ latch.countDown(); }); container.setReceiveTimeout(100); container.setPrefetchCount(1000); container.setTxSize(1000); container.afterPropertiesSet(); container.start(); try { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(1000, Integer.MAX_VALUE, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); // RabbitTemplate template = new RabbitTemplate(); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); props.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT); Message message = new Message(new byte[256], props); StopWatch watch = new StopWatch(); watch.start(); for (int i = 0; i < count; i++) { template.send("", ROUTE, message); } assertTrue(latch.await(60, TimeUnit.SECONDS)); watch.stop(); // System .out .println(watch.getTotalTimeMillis()); assertEquals(count, received.size()); } finally { container.stop(); } }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testDebatchByContainerBadMessageRejected() throws Exception { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory); container.setQueueNames(ROUTE); container.setMessageListener((MessageListener) message -> { });/* w w w . jav a 2s. com*/ container.setReceiveTimeout(100); ConditionalRejectingErrorHandler errorHandler = new ConditionalRejectingErrorHandler(); container.setErrorHandler(errorHandler); container.afterPropertiesSet(); container.start(); Log logger = spy(TestUtils.getPropertyValue(errorHandler, "logger", Log.class)); doReturn(true).when(logger).isWarnEnabled(); doAnswer(new DoesNothing()).when(logger).warn(anyString(), any(Throwable.class)); new DirectFieldAccessor(errorHandler).setPropertyValue("logger", logger); try { RabbitTemplate template = new RabbitTemplate(); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); props.getHeaders().put(MessageProperties.SPRING_BATCH_FORMAT, MessageProperties.BATCH_FORMAT_LENGTH_HEADER4); Message message = new Message("\u0000\u0000\u0000\u0004foo".getBytes(), props); template.send("", ROUTE, message); Thread.sleep(1000); ArgumentCaptor<Object> arg1 = ArgumentCaptor.forClass(Object.class); ArgumentCaptor<Throwable> arg2 = ArgumentCaptor.forClass(Throwable.class); verify(logger).warn(arg1.capture(), arg2.capture()); assertThat(arg2.getValue().getMessage(), containsString("Bad batched message received")); } finally { container.stop(); } }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testCompressionWithContainer() throws Exception { final List<Message> received = new ArrayList<Message>(); final CountDownLatch latch = new CountDownLatch(2); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory); container.setQueueNames(ROUTE); container.setMessageListener((MessageListener) message -> { received.add(message);//from w w w. ja v a2s .c o m latch.countDown(); }); container.setReceiveTimeout(100); container.setAfterReceivePostProcessors(new DelegatingDecompressingPostProcessor()); container.afterPropertiesSet(); container.start(); try { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); template.setBeforePublishPostProcessors(new GZipPostProcessor()); MessageProperties props = new MessageProperties(); Message message = new Message("foo".getBytes(), props); template.send("", ROUTE, message); message = new Message("bar".getBytes(), props); template.send("", ROUTE, message); assertTrue(latch.await(10, TimeUnit.SECONDS)); assertEquals(2, received.size()); assertEquals("foo", new String(received.get(0).getBody())); assertEquals(3, received.get(0).getMessageProperties().getContentLength()); assertEquals("bar", new String(received.get(1).getBody())); assertEquals(3, received.get(0).getMessageProperties().getContentLength()); } finally { container.stop(); } }