我正在尝试为独立队列实例化多个SimpleMessageListenerContainer
并定义自定义,此设置的原因是我不想创建一个共享线程池配置在所有消息侦听器队列之间共享的位置。TaskExecutor
MessageListener
SimpleMessageListenerContainer
你能提供一个建议吗?我尝试遵循一些 spring-messaging-aws 测试用例方法,但似乎不起作用?
@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory() {
SimpleMessageListenerContainerFactory msgListenerContainerFactory = new SimpleMessageListenerContainerFactory();
msgListenerContainerFactory.setAmazonSqs(amazonSQSClient());
return msgListenerContainerFactory;
}
@Bean
public SimpleMessageListenerContainer uplinkMessageListenerContainer() throws Exception {
SimpleMessageListenerContainer msgListenerContainer = simpleMessageListenerContainerFactory().createSimpleMessageListenerContainer();
msgListenerContainer.setAmazonSqs(amazonSQSClient());
QueueMessageHandler messageHandler = new QueueMessageHandler();
msgListenerContainer.setMessageHandler(messageHandler);
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("uplinkMessageListener", UplinkMessageListener.class);
messageHandler.setApplicationContext(applicationContext);
msgListenerContainer.setBeanName("testContainerName");
messageHandler.afterPropertiesSet();
msgListenerContainer.setMaxNumberOfMessages(maxNumberOfmessages);
msgListenerContainer.setWaitTimeOut(waitTimeout);
msgListenerContainer.setBackOffTime(backOfTime);
msgListenerContainer.setAutoStartup(sqsAutoStartup);
msgListenerContainer.setVisibilityTimeout(visibilityTimeout);
msgListenerContainer.setTaskExecutor(createDefaultTaskExecutor("MPSQSUplinkMessageListener", 2, 10));
msgListenerContainer.afterPropertiesSet();
msgListenerContainer.start();
return msgListenerContainer;
}