org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener Java Examples
The following examples show how to use
org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener.
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: SpringAmqpStubMessages.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
@Override public void send(Message message, String destination) { final String routingKey = message.getMessageProperties().getReceivedRoutingKey(); List<SimpleMessageListenerContainer> listenerContainers = this.messageListenerAccessor .getListenerContainersForDestination(destination, routingKey); if (listenerContainers.isEmpty()) { throw new IllegalStateException( "no listeners found for destination " + destination); } for (SimpleMessageListenerContainer listenerContainer : listenerContainers) { Object messageListener = listenerContainer.getMessageListener(); if (isChannelAwareListener(listenerContainer, messageListener)) { try { ((ChannelAwareMessageListener) messageListener).onMessage(message, createChannel(listenerContainer, transactionalChannel())); } catch (Exception e) { throw new RuntimeException(e); } } else { ((MessageListener) messageListener).onMessage(message); } } }
Example #5
Source File: SpringAmqpStubMessages.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
boolean isChannelAwareListener(SimpleMessageListenerContainer listenerContainer, Object messageListener) { return messageListener instanceof ChannelAwareMessageListener && listenerContainer.getConnectionFactory() != null; }