List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setMaxConcurrentConsumers
public void setMaxConcurrentConsumers(int maxConcurrentConsumers)
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 ww . j av a 2s.c o m*/ return null; }
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 w w.ja v a2s. 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_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 ww w . j a v a 2s . co m*/ container.setConcurrentConsumers(minConcurrency); container.setMaxConcurrentConsumers(maxConcurrency); } container.setMessageListener(listenerAdapter); return container; } else return null; }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerLongTests.java
private void testChangeConsumerCountGuts(boolean transacted) throws Exception { final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory("localhost"); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(singleConnectionFactory); try {/*w w w .j a v a 2s. c om*/ container.setMessageListener(new MessageListenerAdapter(this)); container.setQueueNames("foo"); container.setAutoStartup(false); container.setConcurrentConsumers(2); container.setChannelTransacted(transacted); container.afterPropertiesSet(); assertEquals(2, ReflectionTestUtils.getField(container, "concurrentConsumers")); container.start(); waitForNConsumers(container, 2); container.setConcurrentConsumers(1); waitForNConsumers(container, 1); container.setMaxConcurrentConsumers(3); RabbitTemplate template = new RabbitTemplate(singleConnectionFactory); for (int i = 0; i < 20; i++) { template.convertAndSend("foo", "foo"); } waitForNConsumers(container, 2); // increased consumers due to work waitForNConsumers(container, 1, 20000); // should stop the extra consumer after 10 seconds idle container.setConcurrentConsumers(3); waitForNConsumers(container, 3); container.stop(); waitForNConsumers(container, 0); singleConnectionFactory.destroy(); } finally { container.stop(); } }
From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java
private void doRegisterConsumer(String name, MessageChannel moduleInputChannel, Queue queue, RabbitPropertiesAccessor properties, boolean isPubSub) { // Fix for XD-2503 // Temporarily overrides the thread context classloader with the one where the SimpleMessageListenerContainer is defined // This allows for the proxying that happens while initializing the SimpleMessageListenerContainer to work correctly ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader(); try {//from w w w .jav a2 s. c om ClassUtils.overrideThreadContextClassLoader(SimpleMessageListenerContainer.class.getClassLoader()); SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer( this.connectionFactory); listenerContainer.setAcknowledgeMode(properties.getAcknowledgeMode(this.defaultAcknowledgeMode)); listenerContainer.setChannelTransacted(properties.getTransacted(this.defaultChannelTransacted)); listenerContainer .setDefaultRequeueRejected(properties.getRequeueRejected(this.defaultDefaultRequeueRejected)); if (!isPubSub) { int concurrency = properties.getConcurrency(this.defaultConcurrency); concurrency = concurrency > 0 ? concurrency : 1; listenerContainer.setConcurrentConsumers(concurrency); int maxConcurrency = properties.getMaxConcurrency(this.defaultMaxConcurrency); if (maxConcurrency > concurrency) { listenerContainer.setMaxConcurrentConsumers(maxConcurrency); } } listenerContainer.setPrefetchCount(properties.getPrefetchCount(this.defaultPrefetchCount)); listenerContainer.setTxSize(properties.getTxSize(this.defaultTxSize)); listenerContainer.setTaskExecutor(new SimpleAsyncTaskExecutor(queue.getName() + "-")); listenerContainer.setQueues(queue); int maxAttempts = properties.getMaxAttempts(this.defaultMaxAttempts); if (maxAttempts > 1) { RetryOperationsInterceptor retryInterceptor = RetryInterceptorBuilder.stateless() .maxAttempts(maxAttempts) .backOffOptions(properties.getBackOffInitialInterval(this.defaultBackOffInitialInterval), properties.getBackOffMultiplier(this.defaultBackOffMultiplier), properties.getBackOffMaxInterval(this.defaultBackOffMaxInterval)) .recoverer(new RejectAndDontRequeueRecoverer()).build(); listenerContainer.setAdviceChain(new Advice[] { retryInterceptor }); } listenerContainer.setAfterReceivePostProcessors(this.decompressingPostProcessor); listenerContainer.setMessagePropertiesConverter(RabbitMessageBus.inboundMessagePropertiesConverter); listenerContainer.afterPropertiesSet(); AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer); adapter.setBeanFactory(this.getBeanFactory()); DirectChannel bridgeToModuleChannel = new DirectChannel(); bridgeToModuleChannel.setBeanFactory(this.getBeanFactory()); bridgeToModuleChannel.setBeanName(name + ".bridge"); adapter.setOutputChannel(bridgeToModuleChannel); adapter.setBeanName("inbound." + name); DefaultAmqpHeaderMapper mapper = new DefaultAmqpHeaderMapper(); mapper.setRequestHeaderNames(properties.getRequestHeaderPattens(this.defaultRequestHeaderPatterns)); mapper.setReplyHeaderNames(properties.getReplyHeaderPattens(this.defaultReplyHeaderPatterns)); adapter.setHeaderMapper(mapper); adapter.afterPropertiesSet(); Binding consumerBinding = Binding.forConsumer(name, adapter, moduleInputChannel, properties); addBinding(consumerBinding); ReceivingHandler convertingBridge = new ReceivingHandler(); convertingBridge.setOutputChannel(moduleInputChannel); convertingBridge.setBeanName(name + ".convert.bridge"); convertingBridge.afterPropertiesSet(); bridgeToModuleChannel.subscribe(convertingBridge); consumerBinding.start(); } finally { Thread.currentThread().setContextClassLoader(originalClassloader); } }