1
我想只允许在给定的时间正在处理的sqs队列中的一个项目。目前它只会提取一个队列中的单个消息,但它会继续在每次调查时都会这样做。Aws整合弹簧:保证只有一个项目从平方
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(10);
executor.setThreadNamePrefix("test-");
executor.initialize();
return executor;
new SqsMessageDrivenChannelAdapter(amazon));
adapter.setMaxNumberOfMessages(1);
adapter.setSendTimeout(2000);
adapter.setVisibilityTimeout(1200);
adapter.setWaitTimeOut(20);
adapter.setTaskExecutor(this.asyncTaskExecutor());
这个问题似乎是在ThreadPoolTaskExecutor和我的理解。由于队列大小为10,它每次都会提升,直到满满为止?
设置maxPoolSize到1导致的
Caused by: java.util.concurrent.RejectedExecutionException: Task org.springframework.cloud.aws.messaging.[email protected]406354e5 rejected from [email protected][Running, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369)
at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:293)
... 6 common frames omitted
这是我的第一个想法,这不起作用见上文。 @Gandalf – user101010101
可能需要更多的代码来解决这个问题。 GitHub的? – Gandalf