0

We use spring integration to transfer messages from one broker (amqp | jms) to another.

We would like to slow down the consumption of messages from the input channel: <int-amqp: inbound-channel-adapter> or <int-jms: message-driven-channel-adapter (by adding a tempo for example) so as not to saturate the remote queue, to give it time to process messages.

Another constraint is to respect the order of the messages on the output Queue.

Thanks for your advices

Regards,

Eric

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Eric NICOLAS
  • 27
  • 1
  • 6

1 Answers1

0

You can simply add a <int:service-activator .../> to the flow right after the inbound adapter, where the method is

public Message<?> delayer(Message<?> in) throws InterruptedException {
    Thread.sleep(100);
    return in;
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks for the advice. How to pass as a parameter the number of milliseconds to the method? – Eric NICOLAS Dec 22 '20 at 17:35
  • Is the use of `header-enricher` the only method to send parameters to the method? – Eric NICOLAS Dec 22 '20 at 17:49
  • Yes, if you want the delay to be variable for each message. Or you could put the logic from the header enricher into the service method itself. – Gary Russell Dec 22 '20 at 18:15
  • @GaryRussell If one were to use `Jms.inboundAdapter` backed by a `Poller`, then I assume that the message GET would be committed (i.e., not on the queue anymore) and be held in the `Delayer` - which I assume could be lost if the application is restarted. Is it possible in Spring SI to have a selector on the queue read to only process messages over a certain age? If yes, I will guess that I will be asking a new "How do I?" question shortly ;-) – lafual Nov 09 '22 at 14:54
  • You can make the poller transactional and the removal from the queue will not be committed until the thread has finished its work. – Gary Russell Nov 09 '22 at 15:28