Technology Uncategorized

Demo – Tutorial [in-order message processing]

Let’s start with a demo in this Azure opened.

The first thing that I’m going to do is create a service bus queue. I’m searching service bus queue in the search bar. I have already created a bus queue with the name spelled by Allied Consultants, I’ll go in to this.

Now I’m going to add a queue as shown in here, then I’ll add a name. Leave everything empty and make sure to enable sessions and disable partitioning. Then click on create. So, the file is created.

Let’s go back to our logic app by searching logic app in the search bar. Here I have already created a logic app with the name of business logic, let’s go into this and click on edit.

The logic app designer will be opened. The first thing here is HTTP request, this is used to receive the message that comes from the in order message processing logic app.

In the next step we are going into parse JASON peek-lock. Then we are going to evaluate a condition using a sequence number which is equal to 3.

If this is true then we’re going to send an email to the user and then to the winner.

If this is wrong then we’re going to send a failed email to the user where you’re not the winner. In the last step we’re going to refill the response and then save it

.

Now let’s go back into the logic app to create an in order process message logic app.

To do this click on add in the logic app, add the name, check users existing resource group, set location and then create.

Then click on refresh and you will see your logic app created. Inside it click on Create Blank Logic app template to create.

The next thing is to be done is to add a trigger. I’m going to search service bus in the search bar. You can see multiple icons here, select trigger service bus. Inside this you will see multiple triggers as shown and I will be needing, when a message is received in a queue (peek-lock).


Select the queue name and click on advanced options. Select session ID then set interval frequency and I’m setting it to 30 seconds. Then save it, as shown here,
After you’re done click on Next Step. Find the variable in the search bar. Inside variable click on initialize variable.

Inside Variable I’m going to set the name as Loop Count. Set the type and add value as 1.
Then in the next step, I’m going to add our business logic that we designed earlier. Search for logic apps in the search bar opened next. Click on azure logic apps.

You will see the business logic app in the azure and you just have to select it. So, it is expecting two parameters. The message schema and the sequence number.

In the message schema, select the Content of the message. In the sequence number I’m going to select a loop count. Click save to save it

.

Click on next step and search service bus queue to make a queue. Then select service bus. This time I’m selecting “complete the message” in a queue name and then paste the lock token. Click the advanced options and select the session ID and save this as well.


Just like that, we have built the process to trigger our logic app and create the co-relation process message as in order from our service bus queue. Now we need to build the logic to process the rest of the messages in that queue.

I’m going to add in next step and find until in the search bar. I’m going to add the loop count and add a value which is equal to 5. Then add an action.


I’m adding a service bus action because I want to read the message in a service bus queue.so, I’ll select service bus and go back to the trigger and I’ll select the same trigger that we’ve selected before, When a message is received in a queue’ (peek-lock). I’m going to name the queue. Go to advanced options and set the session ID. To add a custom value.

I’m going to select the session ID to be pasted. Once you’re done then add another Action to increment our variable. So, I’m going search for variables. I’m going to use increment variable. Here I’m going to enter the loop count and enter the value as 1.

After that I’m going to add another value in order to call our business logic in app. I’m going to select azure logic apps and then business logic.

Here I’m going to add the message schema. This time I’m going to make sure that I’m adding from the queue 2. Add content and the Loop count.

Then add an action again. I’m going go in to the service bus and this I’m going to use an action instead of a trigger. I’m going to select complete the message in a queue. I’m going to name the queue as winner, I’ll use a lock token and I’ll go to advanced options and add a session Id, I’m going to hit the save trigger.

Looks like the logic app is completed.

Now let’s see that how to run this set up. The first thing we need to do in order to run this is to set up our service bus queue inside a service bus explorer. We can post the messages in the queue.

Now let’s go and test our logic app, to test this we are going to use service bus explorer to post messages to the queue. I have already set up the service bus explorer to Allied consultant name placed inside of our service bus explorer.
Let’s go and see that how we post messages to our service bus explorer, as shown here.

Click on winner and then send messages. I’m going to place messages here in the format then I’ll click Start and the message is sent.

I’m changing the message name and the second message is sent as well.

I’m going to change the name again. The third one is probably our winner and I’m going to add two more, since we added 5 messages in the loop to complete the logic app.
Now inside of our logic app, we’ll click on refresh, as we can see there is a success message and we can click on it to see the details.

Now you can see that logic app has run successfully.

.
This is the Loop until that run 4 times as expected, if you want to check each of the results then you can click on next.

Let’s go to the email and check if everything is working fine.

I’ve got 5 emails here, the first one is you’re not the winner, the second one you’re not the winner and the third one as expected, you are the winner. Looks like the logic app is working fine and the emails are sent directly.

Author

Hassan Askari