Samantha Catania
Samantha Catania

Reputation: 5316

Spring Integration - Wait for Condition Before Processing Message

I need to implement a spring integration flow where certain messages can only be processed when a certain condition becomes true i.e. these messages need to wait. However, I do not want to block the flow. Is there a component that does this?

Upvotes: 0

Views: 1745

Answers (2)

Augusto
Augusto

Reputation: 29887

Not without the risk of loosing the data if the instance goes down, as the data will be kept in memory (you could try to store it temporarily and re-inject it in case of a VM crash).

There's an integration pattern that spring implements called Aggregator which can be used for exact this purpose (link to pattern and spring docs)

You'll need to implement a CorrelationStrategy that tells spring how different messages are related to each other and a ReleaseStrategy that can tell spring when all the items required have arrived, and as such, they can continue.

I'll repeat this again, all of the in-flight data is kept in memory, so you'll have to figure out how to store and re-inject data after a shutdown/crash.

Upvotes: 1

Gary Russell
Gary Russell

Reputation: 174544

You can start/stop a polling consumer on a QueueChannel - while the poller is stopped, messages will accumulate in the channel and then consumed when the consumer is started.

You can either get a reference to the consumer by bean name and start/stop it or you can use a control-bus and send messages to it "foo.start()".

The messages would be held in memory by default. If you need persistence you can add a message store or use a channel backed by JMS, RabbitMQ etc.

Upvotes: 1

Related Questions