Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.38 KB

File metadata and controls

49 lines (33 loc) · 1.38 KB

Step 5: Notify user about generated invoice

Once invoice is generated, user should receive an SMS text message about it.

Add dependency to Spring Cloud AWS SNS integration

Add a dependency to build.gradle:

implementation 'io.awspring.cloud:spring-cloud-aws-starter-sns'

Send SMS

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");

Fan-Out from SNS to SQS

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) {
    ...
}

Next