Java Code Examples for org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setMaxConcurrentConsumers()
The following examples show how to use
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setMaxConcurrentConsumers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmqpConfig.java From myth with Apache License 2.0 | 6 votes |
/** * Message container simple message listener container. * * @return the simple message listener container */ @Bean @ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host") public SimpleMessageListenerContainer messageContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueues(queue()); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(2); container.setConcurrentConsumers(1); //设置确认模式手工确认 container.setAcknowledgeMode(AcknowledgeMode.MANUAL); container.setMessageListener((ChannelAwareMessageListener) (message, channel) -> { byte[] messageBody = message.getBody(); LOGGER.debug("motan 框架接收到的消息"); //确认消息成功消费 final Boolean success = mythMqReceiveService.processMessage(messageBody); if (success) { channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } }); return container; }
Example 2
Source File: AmqpConfig.java From myth with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host") public SimpleMessageListenerContainer messageContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueues(queue()); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(1); container.setConcurrentConsumers(1); //设置确认模式手工确认 container.setAcknowledgeMode(AcknowledgeMode.MANUAL); container.setMessageListener((ChannelAwareMessageListener) (message, channel) -> { byte[] messageBody = message.getBody(); //确认消息成功消费 final Boolean success = mythMqReceiveService.processMessage(messageBody); if (success) { try { channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } catch (IOException e) { e.printStackTrace(); } } }); return container; }
Example 3
Source File: AmqpConfig.java From myth with Apache License 2.0 | 6 votes |
/** * Message container simple message listener container. * * @return the simple message listener container */ @Bean @ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host") public SimpleMessageListenerContainer messageContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueues(queue()); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(3); container.setConcurrentConsumers(1); //设置确认模式手工确认 container.setAcknowledgeMode(AcknowledgeMode.MANUAL); container.setMessageListener((ChannelAwareMessageListener) (message, channel) -> { byte[] messageBody = message.getBody(); LogUtil.debug(LOGGER, () -> "springcloud account服务 amqp接收消息"); //确认消息成功消费 final Boolean success = mythMqReceiveService.processMessage(messageBody); if (success) { channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } }); return container; }
Example 4
Source File: RabbitMQConfig.java From jim-framework with Apache License 2.0 | 6 votes |
@Bean public SimpleMessageListenerContainer messageContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory()); container.setQueues(queue()); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(1); container.setConcurrentConsumers(1); container.setAcknowledgeMode(AcknowledgeMode.MANUAL); container.setMessageListener(new ChannelAwareMessageListener() { public void onMessage(Message message, com.rabbitmq.client.Channel channel) throws Exception { byte[] body = message.getBody(); logger.info("消费端接收到消息 : " + new String(body)); channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } }); return container; }
Example 5
Source File: RabbitConfigurer.java From bird-java with MIT License | 6 votes |
@Bean @ConditionalOnProperty(value = EventbusConstant.Rabbit.LISTENER_PACKAGES) public SimpleMessageListenerContainer messageContainer(Queue queue, EventDispatcher eventDispatcher) { for (String topic : eventDispatcher.getAllTopics()) { this.initExchange(topic,queue); } SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory()); container.setQueues(queue); container.setMessageConverter(messageConverter()); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(1); container.setConcurrentConsumers(1); container.setAcknowledgeMode(AcknowledgeMode.MANUAL); //设置确认模式手工确认 RabbitEventArgListener listener = new RabbitEventArgListener(eventDispatcher); container.setMessageListener(listener); return container; }
Example 6
Source File: RabbitMessageChannelBinder.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 6 votes |
private void setSMLCProperties( ExtendedConsumerProperties<RabbitConsumerProperties> properties, SimpleMessageListenerContainer listenerContainer, int concurrency) { listenerContainer.setConcurrentConsumers(concurrency); int maxConcurrency = properties.getExtension().getMaxConcurrency(); if (maxConcurrency > concurrency) { listenerContainer.setMaxConcurrentConsumers(maxConcurrency); } listenerContainer.setDeBatchingEnabled(!properties.isBatchMode()); listenerContainer.setBatchSize(properties.getExtension().getBatchSize()); if (properties.getExtension().getQueueDeclarationRetries() != null) { listenerContainer.setDeclarationRetries( properties.getExtension().getQueueDeclarationRetries()); } }
Example 7
Source File: AmqpConfiguration.java From SkyEye with GNU General Public License v3.0 | 5 votes |
@Bean public SimpleMessageListenerContainer messageContainer(ConnectionFactory connectionFactory, MessageListenerAdapter messageListenerAdapter) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueues(this.queue); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(this.maxConcurrentConsumers); container.setConcurrentConsumers(this.concurrentConsumers); container.setAcknowledgeMode(AcknowledgeMode.AUTO); container.setMessageListener(messageListenerAdapter); return container; }
Example 8
Source File: AmqpConfig.java From demo_springboot_rabbitmq with Apache License 2.0 | 5 votes |
@Bean public SimpleMessageListenerContainer messageListenerContainer(MessageListenerAdapter listenerAdapter) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory()); container.setQueueNames(AmqpConfig.QUEUE_NAME); container.setExposeListenerChannel(true); container.setMaxConcurrentConsumers(1); container.setConcurrentConsumers(1); container.setAcknowledgeMode(AcknowledgeMode.MANUAL); //设置确认模式手工确认 container.setMessageListener(listenerAdapter); return container; }
Example 9
Source File: OrderConsumer.java From SpringBoot-Course with MIT License | 4 votes |
@Bean public SimpleMessageListenerContainer simpleMessageListenerContainer(ConnectionFactory connectionFactory) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); // 监听队列,可以同时设置多个 container.setQueues(orderDirectQueue()); // 设置当前的消费者数量 container.setConcurrentConsumers(2); // 设置最大的消费者数量 container.setMaxConcurrentConsumers(10); // 设置重回队列,false 不会重回队列 container.setDefaultRequeueRejected(false); // 设置签收模式为手动签收,自动签收为 AcknowledgeMode.AUTO // container.setAcknowledgeMode(AcknowledgeMode.MANUAL); // 手动签收 container.setAcknowledgeMode(AcknowledgeMode.AUTO); // 监听消费端方法一 OrderConsumerMessage orderConsumerMessage = new OrderConsumerMessage(); container.setMessageListener(orderConsumerMessage); // 监听消费端方法二 // container.setMessageListener(new ChannelAwareMessageListener() { // @Override // public void onMessage(Message message, Channel channel) throws Exception { // String msg = new String(message.getBody()); // // System.out.println("----------- Message -----------"); // System.out.println(msg); // } // }); // 监听消费端方法三 | 一 // 适配器方式 // MessageListenerAdapter adapter = new MessageListenerAdapter(new OrderConsumerMessageDelegate()); // adapter.setDefaultListenerMethod("orderConsumerMsg"); // 自定义适配器方法名 // container.setMessageListener(adapter); // 监听消费端方法三 | 二 // 适配器方式 // MessageListenerAdapter adapter = new MessageListenerAdapter(new OrderConsumerMessageDelegate()); // adapter.setDefaultListenerMethod("jsonOrderConsumerMsg"); // 自定义适配器方法名 // // Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter(); // adapter.setMessageConverter(jackson2JsonMessageConverter); // 消息转为 json // // container.setMessageListener(adapter); System.out.println("消费端重启成功"); return container; }