Spring AMQP: would like to send a message to the queue and immediately send the ACK

I wrote a Java application that sends messages to RabbitMQ. Flume then selects messages from the RabbitMQ queue. I'm curious that no one is pulling messages out of the queue except the tray.

My application uses the Spring AMQP Java plugin.

Problem:

With the code below, the message enters the RabbitMQ queue and remains "Unknowledges" forever. As I understand it, RabbitMQ is waiting for an ACK from a MessageListener, but a MessageListener will never be an ACK. Does anyone know how to fix this?

The code:

public class MyAmqpConfiguration { @Autowired ConnectionFactory connectionFactory; @Bean public SimpleMessageListenerContainer messageListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueues(activityLogsQueue()); container.setMessageListener(MyMessageListener()); container.setConcurrentConsumers(3); return container; } @Bean(name="myTemplate") public RabbitTemplate rabbitTemplate() { RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setMessageConverter(MyMessageConverter()); return template; } } public class MyMessageListener implements MessageListener { public MyMessageListener(MessageConverter converter, MyMessageHandler<MyObject> messageHandler) { this.converter = converter; this.messageHandler = messageHandler; } @Override public void onMessage(Message message) { this.messageHandler.doThings(); } } public class MyMessageHandler { @Autowired @Qualifier("myTemplate") RabbitTemplate template; @Override public void handleMessage(MyObject thing) { template.convertAndSend(exchange, routingKey, thing); } } public class MyMessageConverter extends JsonMessageConverter { @Override protected Message createMessage(Object object, MessageProperties messageProperties) { //do things } @Override public Object fromMessage(Message message) throws MessageConversionException { throw new UnsupportedOperationException("fromMessage is not supported in "+this.getClass().getName()); } } 
+4
source share
2 answers

If you do not want to have an ACK for each message, you can set AcknowledgeMode to SimpleMessageListenerContainer by doing

 container.setAcknowledgeMode(AcknowledgeMode.NONE); 

check out the API link for more information.

Update: Must be AcknowledgeMode.NONE

Set the value AcknowledgeMode.NONE to inform the broker that he does not expect any confirmations, and suppose that all messages will be confirmed as soon as they are sent (this is "autoack" in the broker's own conditions). If AcknowledgeMode.NONE, then the channel cannot be transactional (so the container will crash at startup if this flag is accidentally set).

+4
source

All Articles