我正在尝试使用spring boot和spring-cloud-aws-messaging将通知消息发送到aws中的SNS-Topic。 我的AWS配置如下-:
@Bean
public AmazonSNS amazonSNS(){
if(Objects.nonNull(snsClient)){
final AWSCredentials awsCredentials = new BasicAWSCredentials(awsConfig.getAccessKey(),
awsConfig.getSecretKey());
snsClient = AmazonSNSClientBuilder.standard()
.withRegion(awsConfig.getRegion())
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
return snsClient;
}
@Bean
public NotificationMessagingTemplate notificationMessagingTemplate(){
return new NotificationMessagingTemplate(amazonSNS());
}
我的休息控制器代码如下
@Autowired
NotificationMessagingTemplate messagingTemplate;
@GetMapping("/postMessage")
public void sendMessage(){
System.out.println("Sending Message");
messagingTemplate.sendNotification("example-topic-arn", "Test Message","Test Subject");
}
我收到此例外-:
[Request processing failed; nested exception is org.springframework.messaging.MessageDeliveryException: Failed to send message to TopicMessageChannel[TopicMessageChannel@2a7a4044]; nested exception is java.lang.NullPointerException, failedMessage=GenericMessage [payload=Test Message, headers={NOTIFICATION_SUBJECT_HEADER=Test Message, id=96817d20-fb5d-7e07-76e2-e3492986df0b, contentType=text/plain;charset=UTF-8, timestamp=1573384357842}]] with root cause
我是aws的新手,请帮忙。