spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
589 stars 376 forks source link

Can not receive sqs message after the application has been running for a few days #742

Open vitahlin opened 3 years ago

vitahlin commented 3 years ago

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();
    }
sreekanth-tf commented 3 years ago

Any updates, please?

edudar commented 2 years ago

I believe I might be experiencing the same issue. In my case, it's a matter of hours. I have multiple message listener containers and some of them randomly stop receiving messages. THere are no visible exceptions or errors. They just quietly quit.

maciejwalkowiak commented 2 years ago

Have you tried to use the latest version of Spring Cloud AWS 2.3.1? Please note that Spring Cloud AWS moved to https://github.com/awspring/spring-cloud-aws, docs can be found at https://docs.awspring.io/spring-cloud-aws/docs/2.3.1/reference/html/index.html

edudar commented 2 years ago

I have not yet. It’s the plan but the move between packages made this a little bit bigger of a deal.