Azure Service Bus Topics Publish Subscribe Example with C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video i'm going to show you how you can create a service bus topic on azure and create few subscriptions in it with filters and listen to those subscriptions with your csharp azure functions application so let's get started the first thing that we are going to do is creating the resources that we need on azure and i have prepared a small script for it first we are going to create the resource group and then the service bus namespace so i'm going to copy this one and paste it in my powershell window all right i have the resources ready now let's switch to my azure portal like this and go into the service bus namespace that we have created and as you can see on the left side we have queues and topics i'm going to click on topics and i'm going to create a new topic like this so what i'm going to call it is let's say this page created you can add whatever you want here in size i'm going to keep it as 1gb and ttl is going to be 14 days and i'm going to keep these things as default here and i'm going to click create now that we have our topic created let me click on it go to subscriptions as you can see it's on the left side of the menu and i'm going to click on create a subscription and here i'm going to create two subscriptions for this demo the reason that i'm creating two subscriptions is because um i want to show you that you can have multiple subscriptions for a single topic and you can subscribe from two functions on azure and you can listen to the topic and also you can apply filters to these subscriptions as well so let's see how it all works i'm going to name this subscription let's i'm going to call it function1 and i'm going to put delivery count as 10 and i'm going to keep all these oss default and then i'm going to create another subscription let me call it function2 and then i'm going to create it as well all right now that i have two functions let's go into visual studio and create a function app all right as you can see here i have created a sample function app and it's donated three point uh code 3.1 and that is the target framework question and i will right click here and add a new function and i'm going to call it f1 let's add it and this is going to be a service bus topic trigger so here i'm going to name this um the connection name i have to provide so i'm going to call it service bus connection like this and the topic that i've created is message created the topic name and subscription is function one so i'm going to enter these things here and i'm going to add the function as you can see they all got populated like message created and the function1 and this is the name that i have given to my subscription on azure and also you can see i have the connection name as well and i'm going to copy this connection name and i'm going to go into local settings file and insert it as a configuration here so like this now let's go back to my visual studio now let's go back to azure portal and go into the service bus namespace like this and go into this shared access policies and i'm going to go with the default key um if you want to revoke access for managing and sending for example you can just create a new shared access policy here and i'm going to copy this one i'm going back to my function app and pasting it here so that's done i'm going to close it and we are ready to receive messages from our topic and now we need a way to send messages to our topic so that we can test our function that we just wrote and for that i have just created a sample um azure logic cap so here as you can see uh if i go to the designer it's just [Music] as you can see here it's just sending a message to my topic i've just created so yeah it's i'm just passing in the message created the name of the topic and the message that i want uh my function app to receive so i'm going into the overview section of the uh the uh the workflow and let's run my application as you can see it's listening now and i'm going to trigger this from here yeah as you can see i am receiving um the message like this so let's close so let's stop this function execution and create another function i'm going to call it function2 and since i have created two functions on azure and this is what i want to demo as well because we're working with subscriptions so i have two functions now and i want to listen to function two topic um not the topic this is subscription and then what i'm going to do is um i'm going to keep all these as default but i'm going to change the log of this message of this function so i'm going to call it ff1 and here i'm going to call it f2 and now let's see what happens all right as you can see we have two functions to execute let's go back into my logic cap and run the trigger again all right as you can see we have two executions in our logic app because we have two functions now that we know how to create two subscriptions for one topic and we actually did it now let's look into filters on search box topics and now i'm in my resource group and i'm going to click on my service bus namespace i've just created i'm going to topics and and the message created topic and then if i go into the subscriptions section and click on the second subscription you can see here you can add filters there are few types of filters like correlation filters and sql filters and like that and there's a default filter called the sql filter right and basically what you can do is you can write filters for filtering out the messages that you receive for each subscriptions so here you can write expressions um that are that looks like sql for example if you go here this page contains the type of filters and actions that azure source first supports um if you go here to the example section you can write things like this so basically there are some system properties like sys dot and there are message properties like this basically these are the properties of the message so you can write this sql like code here but i'm not going into uh much deep you can come here and look into that so what i'm going to do is for this function to subscription i'm going to um now i'm going to add a new filter like this i'm going to call it disable it's going to be something like this it's one equals zero so basically i don't want any messages um for my this uh this sub function to subscription so i'm gonna save this as you can see i have just created that filter now let's go back to my uh visual studio project and run this function and i'm going into my resource group and the logic app i just created let's uh let's trigger this one again as you can see i'm getting this message only from function one that we wrote here but i'm not seeing a message from function and that is because we have created a filter for that function today we've learned what topics are and what subscriptions are and we wrote a function app to listen to those subscriptions as well and then we wrote a filter to filter our data if you have any questions or comments you can leave down below and if you want to be updated with future videos that i'm planning to do you can subscribe to my channel as well and thanks for watching you
Info
Channel: Meet Kamal Today - Cloud Mastery
Views: 952
Rating: undefined out of 5
Keywords: service bus topic trigger azure function, service bus topic, azure service bus topic, c# service bus topic, c# create service bus topic, create service bus topic in azure, azure service bus topic subscription filter, azure service bus topic filter, service bus topic filter, topic azure service bus, service bus topic sql filters, service bus topic correlation filters, service bus topic correlation filter, service bus topic sql filter, service bus topics, logic apps, service bus
Id: pCQnJHUz7tQ
Channel Id: undefined
Length: 9min 25sec (565 seconds)
Published: Wed Sep 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.