Home > Mobile >  Why does my service activator poll multiple messages?
Why does my service activator poll multiple messages?

Time:10-27

Given the setup https://gist.github.com/gel-hidden/0a8627cf93f5396d6b73c2a6e71aad3e, I would expect when I send a message that the ServiceActivator would be called with a delay of 10 000 between messages.

The first channel takes in a list, then split the messages and then call another QueueChannel. But for some reason each pull polls all the split messages. I know I am missing something stupid, or I'm just too stupid to understand whats happening.

Related test case: https://gist.github.com/gel-hidden/de7975fffd0853ec8ce49f9d6fa6531d

Output:

2022-10-26 15:22:02.708  INFO 78647 --- [   scheduling-1] com.example.demo.DemoApplicationTests    : Received message Hello
2022-10-26 15:22:02.708  INFO 78647 --- [   scheduling-1] com.example.demo.UpdateLocationFlow      : Doing some work for model with id 2
2022-10-26 15:22:03.009  INFO 78647 --- [   scheduling-1] com.example.demo.UpdateLocationFlow      : Completed some work for model with id 2
2022-10-26 15:22:03.017  INFO 78647 --- [   scheduling-1] com.example.demo.DemoApplicationTests    : Received message World
2022-10-26 15:22:03.018  INFO 78647 --- [   scheduling-1] com.example.demo.UpdateLocationFlow      : Doing some work for model with id 3
2022-10-26 15:22:03.319  INFO 78647 --- [   scheduling-1] com.example.demo.UpdateLocationFlow      : Completed some work for model with id 3
2022-10-26 15:22:04.322  INFO 78647 --- [   scheduling-1] o.s.i.a.AggregatingMessageHandler        : Expiring MessageGroup with correlationKey[1]

My thoughts is that the messages should be something like:

  • 00:01 Doing some work for model with id 2
  • 00:02 Completed some work for model with id 2
  • 00:12 Doing some work for model with id 3
  • 00:13 Completed some work for model it id 3

CodePudding user response:

So, it is a bug in the Spring Integration around lifecycle management for the IntegrationFlowAdapter management. It just starts twice.

As a workaround I suggest to pull your @ServiceActivator handle() into an individual component with its own @Poller configuration and an inputChannel and outputChannel. In other words int must go outside of your UpdateLocationFlow. This way the IntegrationFlowAdapter won't have a control for its lifecycle and won't start it twice.

Meanwhile I'm looking how to fix it.

Thank you for reporting this!

  • Related