下面是我的设置:
JmsListener
侦听SQS队列的Spring Boot应用程序版本:
当我使用Number
MessageAttribute将消息发布到SNS Topic(通过AWS控制台)时,到达SQS。但是,我的JMS侦听器代码没有收到消息-即,当从SQS收到带有Number
MessageAttribute的消息时,代码根本不会被触发。
示例:
Number
MessageAttribute ==>的情况下收到的SQS消息将触发JmsListener
Number
MessageAttribute ==>收到的JmsListener
@JmsListener(destination = "sqs.queue.name")
public void processAccountMessage(TextMessage msg) throws JMSException {
logger.info("msg: {}", msg);
}
和JmsListenerContainerFactory
代码如下:
@Configuration
@EnableJms
public class MessageConfig {
@Inject
private ClientFactory<AmazonSQS> sqsClientFactory;
@Value("${aws.region}")
private String awsRegion;
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() throws Exception {
DefaultJmsListenerContainerFactory factory =
new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(new SQSConnectionFactory(new ProviderConfiguration(), this.sqsClientFactory.getClient(AmazonSQS.class, this.awsRegion)));
factory.setDestinationResolver(new DynamicDestinationResolver());
factory.setConcurrency("1");
factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
return factory;
}