我正在尝试让SpringCloud AWS SQS与自定义一起使用,SimpleMessageListenerContainerFactory以便我可以设置超时和最大消息数。没有使用SQS中很好的拾取消息SimpleMessageListenerContainerFactory注释的自定义方法@SqsListener。但是,当我尝试配置自定义标签时SimpleMessageListenerContainerFactory,注释将停止工作。
SimpleMessageListenerContainerFactory
@SqsListener
@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。
@EnaqbleSqs
SqsConfiguration
@Autowired
@Bean