-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Do not block by default #8580
Do not block by default #8580
Conversation
Currently, many timeouts in the project are like `-1` or other negative value with a meaning to wait indefinitely. According to distributed systems design and bad demo developing experience it is not OK to block forever. * Rework most of the timeouts in the framework to be `30` seconds. Only one remained as `1` seconds is a `PollingConsumer` where it is better to not block even for those 30 seconds when no messages in the queue, but let the polling task be rescheduled. * Remove the `MessagingGatewaySupport.replyTimeout` propagation down to the `PollingConsumer` correlator where it was a `-1` before and blocked the polling thread on the `Queue.poll()`. This fixed the problem with a single thread in a pool for auto-configured `TaskScheduler`. Now with 1 seconds wait time we are able to switch to other scheduled tasks even with only 1 thread in the pool
Long timeout = requestTimeout.getValue(Long.class); | ||
if (timeout != null) { | ||
gateway.setRequestTimeout(timeout); | ||
if (requestTimeout != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need a null check here and use the default; GenericMessagingTemplate
has -1
as its default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! See MessagingGatewaySupport
:
private long replyTimeout = IntegrationContextUtils.DEFAULT_TIMEOUT;
...
template.setReceiveTimeout(this.replyTimeout);
So, if we don't call setReplyTimeout()
, then that default value is used in the GenericMessagingTemplate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - ok.
if (requestTimeout == null || gatewayAnnotation.requestTimeout() != Long.MIN_VALUE) { | ||
if (requestTimeout == null || | ||
gatewayAnnotation.requestTimeout() != IntegrationContextUtils.DEFAULT_TIMEOUT) { | ||
|
||
requestTimeout = new ValueExpression<>(gatewayAnnotation.requestTimeout()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in timeouts()
.
I addition some notes in the Migration Guide: https://github.com/spring-projects/spring-integration/wiki/Spring-Integration-6.0-to-6.1-Migration-Guide |
The default value of sendTimeout in MessagingTemplate was changed from -1 to 30000 in SI 6.1 Related to spring-projects/spring-integration#8580
Currently, many timeouts in the project are like
-1
or other negative value with a meaning to wait indefinitely.According to distributed systems design and bad demo developing experience it is not OK to block forever.
30
seconds. Only one remained as1
seconds is aPollingConsumer
where it is better to not block even for those 30 seconds when no messages in the queue, but let the polling task be rescheduled.MessagingGatewaySupport.replyTimeout
propagation down to thePollingConsumer
correlator where it was a-1
before and blocked the polling thread on theQueue.poll()
.This fixed the problem with a single thread in a pool for auto-configured
TaskScheduler
. Now with 1 seconds wait time we are able to switch to other scheduled tasks even with only 1 thread in the pool