I have the following code retrieving messages from a SQS queue. I am using a AmazonSQSBufferedAsyncClient
to retrieve the message from Queue. A fixed delay SingleThreadedExecutor
wakes up every 5 mins calling receiveMessage
. Long polling is enabled in the Queue
@Service
public class AmazonQueueService
implements QueueService<String> {
@Autowired
private AmazonSQSBufferedAsyncClient sqsAsyncClient;
@Value("${aws.sqs.queueUrl}")
private String queueUrl;
@Override
public List<Message<String>> receiveMessage() {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl);
ReceiveMessageResult result = sqsAsyncClient.receiveMessage(receiveMessageRequest);
LOG.debug("Size=" + result.getMessages().size());
return Lists.transform(result.getMessages(), ......);
}
.....
}
The problem is when I check AWS console, the message is always in-flight, but it is never received in the application (Size is always printed as 0) . Looks like the AmazonSQSBufferedAsyncClient
is reading the message from queue but not returning in the receiveMessage
call.
Any ideas?
AmazonSQSBufferedAsyncClient
configured (timeouts, threads, etc)? And how is the queue configured, regarding the visibility timeout of the messages? Or are you specifying a visibility timeout when sending the messages? – Tele@Autowired
). Could you possibly be creating multiple instances ofAmazonSQSBufferedAsyncClient
instead of a single instance, a singleton, that is shared among all the instances of your classAmazonQueueService
? If this is the case, they would be competing for the messages. You could try printing the.hashCode()
of theAmazonSQSBufferedAsyncClient
just to ensure that you have a single instance... – Tele