【发布时间】:2020-05-20 19:49:25
【问题描述】:
我正在使用 spring-boot-2.2.1 以及 AWS SNS 和 SQS。我正在从 SNS 向 SQS 发布消息。我可以使用 String 接收消息,但 @NotificationMessage 返回 null 而不是消息正文。当我使用 spring-boot-1.5.19 时,相同的代码运行良好
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
</dependency>
主文件
@SpringBootApplication
public class AwsApplication {
public static void main(String[] args) {
SpringApplication.run(AwsApplication.class, args);
}
@Bean
public QueueMessagingTemplate queueMessagingTemplate(AmazonSQSAsync amazonSqs) {
return new QueueMessagingTemplate(amazonSqs);
}
@Bean
public NotificationMessagingTemplate notificationMessagingTemplate(
AmazonSNS amazonSNS) {
return new NotificationMessagingTemplate(amazonSNS);
}
@Bean
public IotClient getIotClient() {
return IotClient.builder()
.credentialsProvider(() -> AwsBasicCredentials.create(AWS_ACCESSKEY, AWS_SECRETKEY))
.credentialsProvider(() -> InstanceProfileCredentialsProvider.create().resolveCredentials())
.region(Region.US_EAST_2)
.build();
}
}
SQS 监听类
@SqsListener(value = "${sqs.consumer.name}")
public void receiveSnsSqs(String message, @NotificationMessage Employee employee) {
System.out.println("SNS Consumer received the message::"+message);
System.out.println("SNS Consumer received the notificationMessage::"+employee);
}
在上面的侦听器类中,我能够接收到消息,但员工却是 null。我直接从 AWS SNS 发送消息。
正如我提到的,它在将 Spring 版本迁移到 2.2.1 版本后停止工作之前工作正常。
任何帮助将不胜感激。
【问题讨论】:
标签: java spring spring-boot amazon-sqs amazon-sns