/** * 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; }
@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) { channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } }); return container; }
/** * 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; }
/** * Create an initial {@link AmqpInboundGatewaySpec}. * @param connectionFactory the connectionFactory. * @param queues the queues. * @return the AmqpInboundGatewaySpec. */ public static AmqpInboundGatewaySMLCSpec inboundGateway(ConnectionFactory connectionFactory, Queue... queues) { SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory); listenerContainer.setQueues(queues); return inboundGateway(listenerContainer); }
/** * Create an initial AmqpInboundChannelAdapterSpec using a * {@link SimpleMessageListenerContainer}. * @param connectionFactory the connectionFactory. * @param queues the queues. * @return the AmqpInboundChannelAdapterSpec. */ public static AmqpInboundChannelAdapterSMLCSpec inboundAdapter(ConnectionFactory connectionFactory, Queue... queues) { SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory); listenerContainer.setQueues(queues); return new AmqpInboundChannelAdapterSMLCSpec(listenerContainer); }
/** * Create an initial {@link AmqpInboundGatewaySpec}. * @param connectionFactory the connectionFactory. * @param amqpTemplate the {@link AmqpTemplate} to use. * @param queues the queues. * @return the AmqpInboundGatewaySpec. */ public static AmqpInboundGatewaySMLCSpec inboundGateway(ConnectionFactory connectionFactory, AmqpTemplate amqpTemplate, Queue... queues) { SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory); listenerContainer.setQueues(queues); return inboundGateway(listenerContainer, amqpTemplate); }
@Bean public SimpleMessageListenerContainer container() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory()); container.setQueues(queue()); container.setAcknowledgeMode(AcknowledgeMode.MANUAL); container.setAutoStartup(false); return container; }
/** * Create an initial {@link AmqpInboundGatewaySpec}. * @param connectionFactory the connectionFactory. * @param queues the queues. * @return the AmqpInboundGatewaySpec. */ public static AmqpInboundGatewaySMLCSpec inboundGateway(ConnectionFactory connectionFactory, Queue... queues) { SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory); listenerContainer.setQueues(queues); return inboundGateway(listenerContainer); }
/** * Create an initial {@link AmqpInboundGatewaySpec}. * @param connectionFactory the connectionFactory. * @param queues the queues. * @return the AmqpInboundGatewaySpec. */ public static AmqpInboundGatewaySpec inboundGateway(ConnectionFactory connectionFactory, Queue... queues) { SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory); listenerContainer.setQueues(queues); return (AmqpInboundGatewaySpec) inboundGateway(listenerContainer); }
/** * Create an initial AmqpInboundChannelAdapterSpec. * @param connectionFactory the connectionFactory. * @param queues the queues. * @return the AmqpInboundChannelAdapterSpec. */ public static AmqpInboundChannelAdapterSpec inboundAdapter(ConnectionFactory connectionFactory, Queue... queues) { SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory); listenerContainer.setQueues(queues); return (AmqpInboundChannelAdapterSpec) inboundAdapter(listenerContainer); }
private SimpleMessageListenerContainer createContainer(MessageListener listener, Queue queue) { SimpleMessageListenerContainer container = doCreateContainer(listener); container.setQueues(queue); return container; }
@Bean public SimpleMessageListenerContainer replyListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(pushConnectionFactory()); container.setQueues(pushQueue()); container.setMessageListener(pushListener()); Advice[] adviceChain = new Advice[] { retryAdvice() }; container.setAdviceChain(adviceChain); return container; }
@Test public void testMultipleQueues() { doTest(1, container -> container.setQueues(queue1, queue2)); }
@Bean @Scope(BeanDefinition.SCOPE_PROTOTYPE) public SimpleMessageListenerContainer listenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory()); container.setQueues(testQueue()); // container.setMessageListener(testListener(4)); container.setAutoStartup(false); container.setAcknowledgeMode(AcknowledgeMode.AUTO); return container; }
/** * @return The reply listener container - the rabbit template is the listener. */ @Bean public SimpleMessageListenerContainer replyListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(rabbitConnectionFactory()); container.setQueues(replyQueue()); container.setMessageListener(fixedReplyQRabbitTemplate()); return container; }
/** * @return The reply listener container - the rabbit template is the listener. */ @Bean public SimpleMessageListenerContainer replyListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(rabbitConnectionFactory()); container.setQueues(replyQueue()); container.setMessageListener(fixedReplyQRabbitTemplate()); return container; }
/** * @return The listener container that handles the dead letter. */ @Bean public SimpleMessageListenerContainer dlListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(rabbitConnectionFactory()); container.setQueues(dlq()); container.setMessageListener(new MessageListenerAdapter(deadListener())); return container; }
/** * @return The reply listener container - the rabbit template with the wrong queue is the listener. */ @Bean public SimpleMessageListenerContainer replyListenerContainerWrongQueue() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(rabbitConnectionFactory()); container.setQueues(replyQueue()); container.setMessageListener(fixedReplyQRabbitTemplateWrongQueue()); container.setAutoStartup(false); return container; }
/** * @return The listener container that handles the request and returns the reply. */ @Bean public SimpleMessageListenerContainer serviceListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(rabbitConnectionFactory()); container.setQueues(requestQueue()); container.setMessageListener(new MessageListenerAdapter(new PojoListener())); return container; }
/** * @return The listener container that handles the request and returns the reply. */ @Bean public SimpleMessageListenerContainer serviceListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(rabbitConnectionFactory()); container.setQueues(requestQueue()); container.setMessageListener(new MessageListenerAdapter(new PojoListener())); return container; }