Use Case: Automating Mobile Recharge Through Messaging Queues

In this article

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 https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/2439676015.

  1. Log in to the Azure portal.

  2. Click Create a resource in the left navigation pane.

  3. Navigate to Integration>Service Bus.

  4. Enter a name for a Namespace. For example, mobilrecharge.

  5. Choose a Pricing tier. For this use case, we use Basic.

  6. Leave the Resource group as-is.

  7. Select the location and click Create.

  8. Once you create a namespace, you can view the details of the namespace from the dashboard.

  9. Click Shared access policies in the left panel.

  10. 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

  1. Click Mobilrecharge namespace on Dashboard.

  2. Click +Queues.

  3. Enter a name for the queue and click Create. Leave the other settings as is.

  4. Click Queues.
    The list of queues appear. You can find the recently created recharge 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

  1. Download and import the Pipeline into SnapLogic.

  2. Configure Snap accounts as applicable.

  3. Provide Pipeline parameters as applicable.

  File Modified

File Use_Case_ASB_Automating_Mobile_Recharge.slp

Dec 01, 2021 by Kalpana Malladi