Watz D Occasion

Occasions Party Center


>>Learn how to use Azure
SignalR Service with Event Grid in this episode
of Azure Tips and Tricks. Using Azure SignalR service
in a serverless mode provides a lot of advantages like automatic
scaling and cost savings, but cuts out some functionality. For instance with a
serverless SignalR service, you can’t get the client events
that tell you when a client is connected or disconnected
from the SignalR service. We can solve this by
using Azure Event Grid. Let’s start by creating
an Azure SignalR service, there it is. Let’s create it. First, I’ll select an
existing resource group, and now I’ll give the
SignalR service a name. Okay. The free pricing tier
is fine for this example, and this is the important part. I’ll select the serverless
mode. That’s it. Let’s create it, and I’ll
skip to when it is done. Here it is. This is the
Azure SignalR service. Now, let’s create an
Azure function that will receive the SignalR events
from Azure Event Grid. Here it is, and let’s create it. Okay. I’ll fill in the function
app name like this, and that’s it. I’ll leave the rest
as it is and create. Again, I’ll skip ahead. Okay. This is the function app. It has no Azure Functions image yet, so let’s create one. Here we go. I’ll select in portal as I
want to create it right here, and I want to see the rest
of the templates. All right. I want to use an Azure Event
Grid template, this one. For this, I need to install the Event Grid extension
into the function app. It is installing, and
now it needs a name. I’ll leave it like this. Okay. This is the Azure function. This will be triggered
by Azure Event Grid and I need to set up its
Event Grid subscription. Let’s do it. All right. Here we go. I’ll give the subscription a name, and here I select SignalR service, and I’ll drill down into these until
I have the SignalR service. Okay. That’s it, and
here you can see that this subscription will push these SignalR events
types to the client, which is the Azure function. Let’s create it. Here we go. It is ready to go. One last thing. Let me
add a line of code here. This will tell us which events
type triggered the function app. Save it and okay. Now, to test this out, I will do that with simple
applications from this GitHub repo. You should clone or download it to
get this to your local machine. Once you have the code, you need the latest .NET core run time
to run the sample apps. You can download it from here. All right. Here we go. I’ve opened a command prompt in
the directory of the samples, and I’ve navigated to the
negotiations server sample app. Now, I need to set the
SignalR connection string. You can find the connection string in the keys menu of the SignalR
surface in the Azure portal, and now run the app. Okay. The negotiation
server is running. Now, I’ll open another command prompt and navigate to the
SignalR client app. This will connect to the
SignalR hub and should trigger an event that Event Grid
will publish. Here we go. Okay. Let’s take a look in the
logs of the Azure function. Here it is, a client
connection connected event. Azure Event Grid triggered
the Azure function, it worked, and let’s go back. What happens when I close
this app? Let’s see. There it is, a client connection
disconnected event. See it works. Azure Event Grid can publish
SignalR events to clients like Azure functions even if the SignalR service runs
in serverless mode. Go and check it out.

Leave a Reply

Your email address will not be published. Required fields are marked *