DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Kafka JDBC Source Connector for Large Data
  • Make Your Integration Seamless By Using Ballerina Client Connectors
  • How to Integrate a Distributed Database With Event Streaming
  • Configuring a Shopify MuleSoft Connector

Trending

  • How Clojure Shapes Teams and Products
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • Scalability 101: How to Build, Measure, and Improve It
  • Fixing Common Oracle Database Problems

Creating an Amazon SNS SQS Publish-Subscribe Model in Mule 4

Follow this step-by-step tutorial for creating an Amazon SNS SQS publish-subscribe model using Mulesoft's Mule 4.

By 
Kunal Thakur user avatar
Kunal Thakur
·
Oct. 26, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
16.9K Views

Join the DZone community and get the full member experience.

Join For Free

MuleSoft — SNS Connector

Anypoint Connector for Amazon SNS (Amazon SNS Connector) provides connectivity to the Amazon Simple Notification Service (Amazon SNS) API, enabling you to build distributed web-enabled applications. Mule apps can use Amazon SNS Connector to easily push real-time notification messages to interested subscribers over multiple delivery protocols. 

MuleSoft — SQS Connector 

Anypoint Connector for Amazon SQS (Amazon SQS Connector) provides an easy way to interface with the Amazon Simple Queue Service (Amazon SQS) API, enabling Mule users to manage SQS queueing services without having to interact with the API directly. 

Prerequisites

Before using an Amazon SNS/SQS connector we need the following:

  • An AWS account with access to the Amazon SNS/SQS.
  • AWS identity and access management (IAM) credentials. These credentials include an access key and secret key.

Chart showing Amazon SNS-SQS Publish-Subscribe model in Mule 4.

Demo SNS SQS Pub/Sub Application

We have to follow the below steps:

  1. Create SQS Queues and SNS Topic.
  2. Subscribe the SNS Topic to the SQS Queues.
  3. Add permissions to Queues to receive messages from Topic.
  4. Publish a message to Topic.
  5. Retrieve messages from Queue.

We are using an HTTP listener to invoke functionalities like creating Queues, creating Topic, and publishing messages to the Topic. We are further using SQS create queue, SNS create topic, SNS Publish, and SQS Retrieve connector. Below are the steps in detail:

Step 1: Create SQS Queues To Be Subscribed and SNS Topic

Screenshot showing SQS Queues and SNS Topic.

PFB the configurations for SNS and SQS:

Configurations for SQS.

Configurations for SNS.

Make sure that the test connection is successful.

We have to send queueName and topic to be created in the Uri parameter. 

We'll create three target queues: targetQueue1, targetQueue2 and targetQueue3. PFB the create queue request-response. Please copy the queue URL received as a response. We will use it for further requests.

Screenshot showing create-queue function.

We'll create SNS Topic — DemoTopic. PFB the create topic request-response. Please copy the topic ARN received as a response. We will use it for further requests.

Screenshot showing create-topic function.

We've successfully created the queues and topic so far.

Step 2: Subscribe the SNS Topic to the SQS Queues

Screenshot showing subscribe topic flow.

Subscribe to SNS Topic Config.

Screenshot showing subscription to SNS Topic.

We will subscribe to the topic DemoTopic for all the target queues. We need to provide topic ARN and queue ARN in the request payload. We can get the queue ARN from the queue URL. PFB the postman request-response.

Screenshot of subscribe-topic configurations.

Step 3: Add Permissions to Queues To Receive Messages From Topic

We need to provide the permissions to the SQS Queue to receive messages from a subscribed topic. In order to do this, we need to add the topic to the access policy of the queue. We will do the same for all the target or subscriber queues.

Screenshot of sqs-set-attributes-flow.

Request payload will have topic ARN, queue ARN, and queue URL. We will store the queue URL from the payload to a variable, as we'll need to pass it to the Set queue attributes connector at the end of the flow. 

Set Access Policy Transform.

Screenshot of output application.

Convert to String Transform:

Screenshot of the output text.

We need to convert the policy to text and then send it to the SQS set attribute connector. 

Set queue attributes.

Screenshot of queue attributes.

PFB the postman request-response for reference.

Screenshot of sqs-set-attributes configurations.

Now we are all set to publish a message to the SNS Topic.

Step 4: Publish a Message to SNS Topic

Screenshot of sns-publish-flow chart.

Payload to String Transform:

Screenshot of output text command.

We need to convert the payload to text/plain format and then publish it. PFB the postman request-response for reference.

Screenshot of publish-to-topic configurations.

The message is published successfully to the SNS Topic.

Step 5: Retrieve Messages From Queue

Screenshot of sns-sqsFlow chart.

This flow will receive the message published to the Topic as a subscriber queue is configured at Receive messages connector.

Receive messages config:

Configuration settings for "Receive messages."

Notification Message to JSON Transform:

Screenshot of output application command.

Log Notification console output:

Screenshot of console ouput.

Message Transform:

Screenshot showing message transform command.

Log Message console output:

Screenshot of console ouput.

Now we have successfully created an Amazon SNS SQS Publish-Subscribe Model in Mule 4.

Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Related

  • Kafka JDBC Source Connector for Large Data
  • Make Your Integration Seamless By Using Ballerina Client Connectors
  • How to Integrate a Distributed Database With Event Streaming
  • Configuring a Shopify MuleSoft Connector

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!