I have developed a standard SQS consumer in Micronaut application (Java). There will be only one consumer instance for this queue. Producer can produce n
number of messages at any moment. But I want to process those messages from SQS in sequential manner, then how can I achieve that?
Below is the code for JMS listener which listens the standard SQS queue:
@Requires(property = SqsConfigurationProperties.PREFIX + ".enabled", value = "true")
@Singleton
@JMSListener(CONNECTION_FACTORY_BEAN_NAME)
public class SQSEventListener {
@Queue(value = "${aws.sqs.name}", concurrency = "1-1")
public void listen(@MessageBody String body) {
...
}
}
Here as you can see I have set the concurrency
as 1-1
. This seems to be working, but then it throws below error if there are more than one messages in the queue:
io.micronaut.messaging.exceptions.MessageListenerException: Task java.util.concurrent.FutureTask@16ff5a1a[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@7e8de0e1[Wrapped task = io.micronaut.jms.configuration.AbstractJMSListenerMethodProcessor$$Lambda$728/0x0000000800c07c40@397e8c27]] rejected from java.util.concurrent.ThreadPoolExecutor@51c6d79a[Running, pool size = 1, active threads = 1, queued tasks = 1, completed tasks = 6]
at io.micronaut.jms.listener.JMSListenerContainer.lambda$registerListener$1(JMSListenerContainer.java:186)
at com.amazon.sqs.javamessaging.SQSSessionCallbackScheduler.run(SQSSessionCallbackScheduler.java:150)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@16ff5a1a[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@7e8de0e1[Wrapped task = io.micronaut.jms.configuration.AbstractJMSListenerMethodProcessor$$Lambda$728/0x0000000800c07c40@397e8c27]] rejected from java.util.concurrent.ThreadPoolExecutor@51c6d79a[Running, pool size = 1, active threads = 1, queued tasks = 1, completed tasks = 6]
at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.reject(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.execute(Unknown Source)
at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at io.micronaut.jms.configuration.AbstractJMSListenerMethodProcessor.lambda$generateAndBindListener$4(AbstractJMSListenerMethodProcessor.java:115)
at io.micronaut.jms.listener.JMSListenerContainer.lambda$registerListener$1(JMSListenerContainer.java:173)
... 4 common frames omitted
02:55:55.574 [SessionCallBackSchedulerThread-1] INFO c.a.s.j.SQSSessionCallbackScheduler - Exception thrown from onMessage callback for message
The above exception also keeps read count increasing on the SQS queue.
How can we fix this error, or is there any other way to achieve sequentially processing of standard SQS messages in Micronaut (Java) application?