Is it possible to consume message from AWS SNS without creating Subscription like ActiveMQ?

3.3k Views Asked by At

When any message publishes to AWS SNS Topic then the listener (java code) can consume the message from SNS Topic without creating any subscriber. I want to achieve a publish-subscriber pattern like ActiveMQ using AWS SNS.

3

There are 3 best solutions below

1
Osama Bin Saleem On

You can configure an AWS lambda function using java as its runtime environment to get triggered using AWS SNS. More info can be found here.

0
bjrnt On

In general, pub/sub systems always require subscriptions to receive messages.

However, Amazon SNS supports delivering messages to platform application endpoints (for delivering push notifications) and phone numbers (for sending SMS) without creating subscriptions. All other types of destinations will require a subscription.

0
paulsm4 On

AWS has two "messaging" services:

  • SNS (Simple Notification Service): Send "notifications" to an "endpoint"
  • SQS (Simple Queue Service): a fully managed message queuing service

If you WANTED pub/sub (analogous to ActiveMQ sub/sub), then you'd probably use SQS.

To answer your question: No, you DON'T need to create a "subscriber".

Strictly speaking, you don't even need to create an SNS Topic: just fire off a "message" to an "endpoint". Per the documentation:

https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html

SNS topic is a logical access point that acts as a communication channel. A topic lets you group multiple endpoints (such as AWS Lambda, Amazon SQS, HTTP/S, or an email address).

Your challenge is how to get an external Java app to "listen" for the notification. This AWS example, Working with Amazon Simple Notification Service creates a topic and assigns a subscriber. It's a good solution ... but there are plenty of other alternatives. It all depends on your application, the application's platform... and your personal preference.