问题
I am learning to how use SimpleMessageListenerContainer to receive rabbitmq messages. My listener container has prefetchCount = 1000. However my listener worker implements the MessageListener interface which only receive one message at a time. Is there an interface to receive a list of messages? If there is not, how can I do to receive a list of messages? I don't want to process one message at a time but rather a list of them so I can do batch insert/update. I also want to acknowledge once for all of the messages that were delivered to me.
Thanks,
Sean Nguyen
回答1:
There is no such API; even the low-level rabbit client consumer delivers each prefetched message one at a time (via handleDelivery).
You will have to accumulate them into a list yourself.
Use the txSize property (set it the same as prefetch) to send a single ack after 1000 deliveries.
来源:https://stackoverflow.com/questions/27896778/how-to-receive-all-the-prefetch-rabbitmq-messages-using-spring-framework