Ruslan Stelmachenko
Ruslan Stelmachenko

Reputation: 5420

Spring Integration listen on queue without poller

I want to implement the HTTP endpoint using Spring Integration, which listen to the http requests, sends the request data as messages to the channel and another endpoint should listen messages on this channel and process them.

Sounds simple. But what I want to achieve is:

  1. Messages should be processed in order.
  2. Messages should be processed asap (without delay after http request, if the queue is already empty).
  3. The http request should be responded as soon as message is received, not after it is processed, so the sender will know only that message is received for processing.
  4. I don't want to use external queues, like RabbitMQ.

So I need a QueueChannel for this. But if I understand correctly, the only way to receive messages from the queue is the poller. So the point 2 will not be satisfied. There will be small delay after message received and before poller sees it.

So the question is: is there any simple way to achieve this in Spring Integration which I don't see?

Of course I can implement it myself. For example creating SmartLifeCycle component, which listen on DirectChannel and just put the messages into java.util.concurrent.BlockingQueue, and also starts a dedicated thread which will wait on this queue and send the message into another DirectChannel for processing. So there will be no delay because thread will be unblocked as soon as BlockingQueue is not empty.

This all sounds like a "pattern" - some queue between two direct channels based on dedicated thread.

Maybe there is a simplier way, already implemented in Spring Integration, which I just don't see because of absense of expirience in this area?

Upvotes: 2

Views: 1675

Answers (1)

Gary Russell
Gary Russell

Reputation: 174544

Point 2 can be satisfied, even with a poller - just set the fixed-delay to 0 and/or increase the receive timeout (default 1 second); the poller thread will block in the queue until a message arrives; then immediately wait again.

You can also use an executor channel (the http thread hands off to the executor thread).

Upvotes: 2

Related Questions