gpt4 book ai didi

spring-boot - 如何配置自定义 Spring Cloud AWS SimpleMessageListenerContainerFactory 以便它继续与 @SqsListener 一起工作

转载 作者:行者123 更新时间:2023-12-04 03:14:36 25 4
gpt4 key购买 nike

我试图让 SpringCloud AWS SQS 使用自定义 SimpleMessageListenerContainerFactory所以我可以设置超时和最大消息数。无定制SimpleMessageListenerContainerFactory@SqsListener 注释的方法很好地拾取 SQS 中的消息。但是当我尝试配置自定义 SimpleMessageListenerContainerFactory注释停止工作。

@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(AmazonSQSAsync amazonSqs) {
SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
factory.setAmazonSqs(amazonSqs);
factory.setAutoStartup(true);
factory.setMaxNumberOfMessages(10);
factory.setWaitTimeOut(2000);
return factory;
}

定义自定义 SimpleMessageListenerContainerFactory 时如何获得正常的 @SqsListener 行为?
@Component
public class SqsMessageConsumer {
@SqsListener("incoming-data")
private void doSomething(String payload) {
System.out.println("data = " + payload);
}
}

最佳答案

不确定您错过了什么,但有一个针对此类用例的测试:

@EnableSqs
@Configuration
public static class ConfigurationWithCustomContainerFactory {


@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory() {
SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
factory.setAmazonSqs(amazonSQS());
...
return factory;
}

@Bean
public AmazonSQSAsync amazonSQS() {
return AMAZON_SQS;
}

}

所以, @EnaqbleSqs还在这里和 SqsConfiguration@Autowired与您的定制 SimpleMessageListenerContainerFactory @Bean .

关于spring-boot - 如何配置自定义 Spring Cloud AWS SimpleMessageListenerContainerFactory 以便它继续与 @SqsListener 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40092518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com