I have an AWS SQS Queue with no retry (MaxReceiveCount is set 1). I have setup a DeadLetter Queue for the same.
I am using spring-cloud-aws-messaging, below is my listener class
@Component
public class MyListener implements ProcessingFinaliser {
private final String sourceQueue;
private final MyProcessor myProcessor;
private SimpleMessageListenerContainer simpleMessageListenerContainer;
public Mylistener(@Value("${my.queue}") String sourceQueue,
MyProcessor myProcessor,
SimpleMessageListenerContainer simpleMessageListenerContainer) {
this.sourceQueue = sourceQueue;
this.myProcessor = myProcessor;
this.simpleMessageListenerContainer = simpleMessageListenerContainer;
}
@SqsListener("${my.queue}")
public void doWork(String message) throws MyCustomException {
this.processor.processMessage(messge);
}
// Called when shutdown signal is called
@Override
public void finaliseProcessing() {
simpleMessageListenerContainer.stop(sourceQueue);
}
}
SimpleMessageListenerContainerFactory#waitTimeOut is set to 20 seconds
simpleMessageListenerContainerFactory.setWaitTimeOut(20);
The problem I am facing is that when simpleMessageListenerContainer.stop(sourceQueue) the doWork method still picks up a new message and goes to DeadLetter Queue as the container dies. Looks like the underlying PollingThread in SimpleMessageListenerContainer does not stop straight away.
By default the SimpleMessageContainerListener#queueStopTimeout is set to 10 seconds, would setting this to 0 be the right thing to do?
Can someone explain please?