Once invoice is generated, user should receive an SMS text message about it.
Add a dependency to build.gradle:
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sns'
Spring Cloud AWS comes with a high level SnsSmsOperations for sending text messages.
Update OrderListener class to send a text message. Watch LocalStack logs to see if the integration works.
snsSmsOperations.send("+48555444333", "invoice ready");To support hypothetical other listeners for OrderCreated event, instead of publishing a message directly to SQS queue, publish it instead to order-created-topic with SnsOperations.
Solution
snsOperations.sendNotification("order-created-topic", SnsNotification.of(new OrderCreated(order.getOrderId())));On the listener side, to tell the framework that this message comes with SNS, annotate event argument in OrderListener#handle with @SnsNotificationMessage and change the queue name to order-created-queue.
Solution
@SqsListener(queueNames = "order-created-queue")
void handle(@SnsNotificationMessage OrderCreated event) {
...
}