Skip to content

Add batchReceiveTimeout in SimpleMessageListenerContainer #2601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
laststem opened this issue Jan 17, 2024 · 3 comments · Fixed by #2605
Closed

Add batchReceiveTimeout in SimpleMessageListenerContainer #2601

laststem opened this issue Jan 17, 2024 · 3 comments · Fixed by #2605

Comments

@laststem
Copy link
Contributor

Expected Behavior

receiveTimeout is The maximum time to wait for each message.
If there is batchReceiveTimeout, the time while waiting for the entire batchSize can be applied not each message.

Current Behavior

There is no batchReceiveTimeout.
so, receiveTimeout applies to individual messages.. wait for batchSize*receiveTimeout amount of time in worst case.

@artembilan
Copy link
Member

Sorry, the info you provide is not enough.
See doReceiveAndExecute(BlockingQueueConsumer consumer) logic in the SimpleMessageListenerContainer.
It really means that we would like to gather the whole batch before processing if you enable consumerBatchEnabled.
Therefore it feel natural to wait for each message for that receiveTimeout independently.
Otherwise we try to debatch a single message and break the loop.

I don't see how that extra new property can be helpful.

Please, elaborate.

@laststem
Copy link
Contributor Author

@artembilan Thanks for reply. and sorry for not enough explanation.

If it is not a batchlistener or batchSize is 1, it is natural to wait for each message for receiveTimeout.

But if batchSize is 1000 and receiveTimeout is 1000ms and consumer.nextMessage(this.receiveTimeout) waits for (receiveTimeout-1)ms to retrieve the message, the total waiting time(1000 * 1000ms) is too harsh.

This is that if messages are provided to BlockingQueueConsumer.queue every (receiveTimeout-1)ms.
As a result, in this situation, it waits for receiveTimeout to fetch one message, and this is repeated for as many times as batchSize, so the previously fetched messages have no choice but to wait a long time.

So, batchReceiveTimeout it can limit the time it waits to fill batchSize.
while accumulating waiting time through consumer.nextMessage(this.receiveTimeout), if batchReceiveTimeout is exceeded, the loop is stopped and executeWithList is called.

@artembilan
Copy link
Member

OK. So, your request is to emit the gathered batch not after the whole number, but when some timeout threshold is reached.
Like you said: we wait for each message for that receiveTimeout, but then before the next attempt we consult with this new batchReceiveTimeout and short-circuit if any.

If I understand your correctly, feel free to contribute the fix and I'm gladly review it: https://github.com/spring-projects/spring-amqp/blob/main/CONTRIBUTING.adoc

laststem added a commit to laststem/spring-amqp that referenced this issue Jan 22, 2024
Fixes spring-projects#2601

stop to waiting next message and execute listener when batchReceiveTimeout is timed out.
laststem added a commit to laststem/spring-amqp that referenced this issue Jan 22, 2024
Fixes spring-projects#2601

stop to waiting next message and execute listener when batchReceiveTimeout is timed out.
laststem added a commit to laststem/spring-amqp that referenced this issue Jan 22, 2024
Fixes spring-projects#2601

stop to waiting next message and execute listener when batchReceiveTimeout is timed out.
laststem added a commit to laststem/spring-amqp that referenced this issue Jan 23, 2024
Fixes spring-projects#2601

stop to waiting next message and execute listener when batchReceiveTimeout is timed out.
laststem added a commit to laststem/spring-amqp that referenced this issue Jan 24, 2024
Fixes spring-projects#2601

stop to waiting next message and execute listener when batchReceiveTimeout is timed out.
artembilan pushed a commit that referenced this issue Jan 25, 2024
Fixes: #2601

Stop to waiting next message and execute listener when `batchReceiveTimeout` is timed out.

* Add `batchReceiveTimeout` to the `SimpleMessageListenerContainer` configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants