spring-batchspring-integrationspring-integration-amqp

Spring Batch Integration consuming RabbitMq Message


I am currently using an IntegrationFlow to trigger a Job execution when RabbitMq messages arrive in a queue. Both the IntegrationFlow's AmqpInboundChannelAdapter and the job's first step's ItemReader are configured to read messages from the same queue.

The issue that I am having is that the IntegrationFlow's AmqpInboundChannelAdapter reads the RabbitMQ message, and the ItemReader then can no longer find that message. Probably because the IntegrationFlow acknowledges the message before the Job launches.

Is there a way to keep the IntegrationFlow from consuming/acknowledging the message, leaving it in the queue so that the ItemReader can work as intendend? I tried configuring the AmqpInboundChannelAdapter to requeue the Message, but that simply caused an infinite loop of the Adapter re-reading it's own message.

This question describes my problem somewhat, except that I am doing no processing, I am simply trying to use the IntegrationFlow as a JobLaunching trigger. So the solution seems like an anti-pattern.

Spring Batch Integration - pass data b/w integration and batch

Any help would be greatly appreciated


Solution

  • If the batch job only needs information from that one message, I would suggest binding a second queue, with the same routing key; one queue for the trigger and one for the item reader.

    If the first message is a trigger and the item reader then reads multiple messages, you could add the message contents to the JobParameters. You would also need to set the adapter's prefetch to 1 so it doesn't get sent any other messages while this one is being processed.