This repository was archived by the owner on Jan 19, 2022. It is now read-only.
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
Can not receive sqs message after the application has been running for a few days #742
Open
Description
Type: Bug
Component:
SQS
Describe the bug
After the application runs for a few days, listener can not receive the message and I saw the count of messages in the queue growing in the Amazon admin. The application runs normally only sqs listener not receive message. After I restart application then it worked well again.
Spring Cloud Version:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-messaging</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
Sample
listener
:
@SqsListener(value = "merchant", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void receiveMerchantMsg(String data) throws InterruptedException, ExecutionException, IOException {
logger.info("SQS etsy_shop begin consume, msg={}", data);
MerchantMsgBo msg = JSON.parseObject(data, MerchantMsgBo.class);
logger.info("SQS shop consume success, shopName={}, msg={}", msg.getShopName(), data);
}
AwsConfig
:
@Bean
public AmazonSQSAsync getSqsAsync(AWSStaticCredentialsProvider awsStaticCredentialsProvider) {
return AmazonSQSAsyncClientBuilder.standard()
.withCredentials(awsStaticCredentialsProvider)
.withClientConfiguration(new ClientConfiguration().withConnectionTimeout(5000))
.withRegion(Regions.CN_NORTH_1)
.build();
}
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(
AmazonSQSAsync amazonSQSAsync,
QueueMessageHandler queueMessageHandler
) {
SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
simpleMessageListenerContainer.setAmazonSqs(amazonSQSAsync);
simpleMessageListenerContainer.setMessageHandler(queueMessageHandler);
simpleMessageListenerContainer.setMaxNumberOfMessages(10);
simpleMessageListenerContainer.setAutoStartup(true);
return simpleMessageListenerContainer;
}
@Bean
public QueueMessageHandler queueMessageHandler(AmazonSQSAsync amazonSQSAsync) {
QueueMessageHandlerFactory queueMessageHandlerFactory = new QueueMessageHandlerFactory();
queueMessageHandlerFactory.setAmazonSqs(amazonSQSAsync);
return queueMessageHandlerFactory.createQueueMessageHandler();
}