I'm using QueueMessagingTemplate to send and receive messages to/from an SQS queue. Receive happens in an infinite loop that regularly polls the queue. However, when there are no messages on the queue, a large amount of empty receives happens which increases costs. I set ReceiveMessageWaitTimeSeconds on the queue in order to benefit from the long polling funcitonality of SQS, but the situation didn't get better.
Please consider the following to make long polling possible:
Make the default timeout configurable instead of hard-coded 0
If timeout is not given, do not set it in the request (this way, the one set in the SQS queue itself will be used)
Alternatives considered
I tried using @SqsListener where ReceiveMessageWaitTimeSeconds could be set via SimpleMessageListenerContainerFactory, but the architecture of my application would require dynamic creation of the queue listener and preferably outside of Spring ApplicationContext. A similar flexible solution could be provided for QueueMessagingTemplate.
Background
I'm using
QueueMessagingTemplate
to send and receive messages to/from an SQS queue. Receive happens in an infinite loop that regularly polls the queue. However, when there are no messages on the queue, a large amount of empty receives happens which increases costs. I set ReceiveMessageWaitTimeSeconds on the queue in order to benefit from the long polling funcitonality of SQS, but the situation didn't get better.I realized that
QueueMessagingTemplate::receive
delegates toQueueMessageChannel::receive
without a parameter and then a hardcoded 0 value is then set in the ReceiveMessageRequest here: https://github.com/spring-cloud/spring-cloud-aws/blob/master/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/core/QueueMessageChannel.java#L220-L241. This overwrites the default setting and makes it impossible to use long polling.Suggestion
Please consider the following to make long polling possible:
Alternatives considered
I tried using
@SqsListener
where ReceiveMessageWaitTimeSeconds could be set viaSimpleMessageListenerContainerFactory
, but the architecture of my application would require dynamic creation of the queue listener and preferably outside of Spring ApplicationContext. A similar flexible solution could be provided forQueueMessagingTemplate
.