Use Case: Automating Mobile Recharge Through Messaging Queues
In this article
- 1 Problem
- 2 Solution
- 2.1.1 Understanding the Solution
- 2.1.1.1 Create Azure Service Bus Namespace
- 2.1.1.2 Create Queue
- 2.1.1.3 Add a Message in the queue
- 2.1.1.4 Read messages from the queue
- 2.1.1.5 Acknowledge the message
- 2.1.1 Understanding the Solution
- 2.2 Downloads
Problem
A mobile service provider wants to automate mobile recharge for its customers through messaging. Typically, the user sends an SMS in a predefined format and the application parses the message and does the recharge accordingly. However, the application encounters a problem when it receives several recharge requests during peak hours and is unable to process each request simultaneously.
Solution
Using the Azure Service Bus Snap Pack, you can automate the mobile recharge process. When an SMS message is received, the mobile recharge application adds it to the queue, and the receiver application processes the message in first-in-first-out order. The benefit of using an ASB queue is, it creates decoupling between sender and receiver, because the messages are stored in a queue, the sender and receiver both need not be available at the same time.
Download the Azure Service Bus solution.
Understanding the Solution
Create Azure Service Bus Namespace
You must create a Namespace in the Azure portal to work with Azure Service Bus (ASB) Snap Pack. For more information, see Configuration in Azure Portal for Azure Service Bus account.
Log in to the Azure portal.
Click Create a resource in the left navigation pane.
Navigate to Integration>Service Bus.
Enter a name for a Namespace. For example,
mobilrecharge
.Choose a Pricing tier. For this use case, we use Basic.
Leave the Resource group as-is.
Select the location and click Create.
Once you create a namespace, you can view the details of the namespace from the dashboard.
Click Shared access policies in the left panel.
Click
RootManageSharedAccessKey
to explore keys and connection strings which you will use later in the Azure Service Bus account.
Note: You can also create your own access key policy with Read/Write/Manage access levels.
Create Queue
Click
Mobilrecharge
namespace on Dashboard.Click +Queues.
Enter a name for the queue and click Create. Leave the other settings as is.
Click Queues.
The list of queues appear. You can find the recently createdrecharge
queue.
Add a Message in the queue
In this step, we configure the JSON Generator Snap to create a JSON file with this message format (sender phone#, reload amount($), DateTime
).
Next, configure the ASB Producer Snap to parse the message and write the JSON request to the ASB queue. We define the queue and message value and set the messages properties as follows.
Read messages from the queue
In this step, we configure the ASB Consumer Snap to read the messages from the upstream Producer Snap.
Next, we configure the Mapper Snap to parse the message body, ID, sequence number, and lock token from the message.
We also create an additional field, currentBalance
using the JSON Generator Snap.
We use the Join Snap to combine the inputs from Mapper and JSON Generator Snaps.
After validating the Snap, the combined output from Mapper and JSON Generator Snaps is as follows.
Acknowledge the message
Finally, we configure the ASB Acknowledge Snap to acknowledge the sender’s request.
We configure the second Mapper Snap to pull the message from the queue and send a message (as a plain text or JSON) back with this message content, 'Success! Your recharge is complete. Your new balance is ' + ($original.currentBalance + $original.messageValue.reloadAmount) + '.'
Downloads
Download and import the Pipeline into SnapLogic.
Configure Snap accounts as applicable.
Provide Pipeline parameters as applicable.