Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Azure SignalR Service now supports Event Grid!

#1
Azure SignalR Service now supports Event Grid!

Avatar

Ken

Since we GA’ed Azure SignalR Service in last September, serverless has become a very popular use case in Azure SignalR Service and is used by many customers. Unlike the traditional SignalR application which requires a server to host the hub, in serverless scenario no server is needed, instead you can directly send messages to clients through REST APIs or our management SDK which can easily be used in serverless code like Azure Functions.

Though there is a huge benefit which saves you the cost of maintaining the app server, the feature set in serverless scenario is limited. Since there is no real hub, it’s not possible to respond to client activities like client invocations or connection events. Without client events serverless use cases will be limited and we hear a lot of customers asking about this support. Today we’re excited to announce a new feature that enables Azure SignalR Service to publish client events to Azure Event Grid so that you can subscribe and respond to them.

How does it work?


Let’s first revisit how serverless scenario in Azure SignalR Service works.

  1. In serverless scenario, even you don’t have an app server, you still need to have a negotiate API so SignalR client can do the negotiation to get the url to SignalR service and a corresponding access token. Usually this can be done using an Azure Function.

  2. Client will then use the url and access token to connect to SignalR service.

  3. After clients are connected, you can send message to clients using REST APIs or service management SDK. If you are using Azure Functions, our SignalR Service binding does the work for you so you only need to return the messages as an output binding.

This flow is illustrated as step 1-3 in the diagram below:

Serverless workflow

What’s missing here is that there is no equivalent of OnConnected() and OnDisconnected() in serverless APIs so there is no way for the Azure function to know whether a client is connected or disconnected.

Now with Event Grid you’ll be able to get such events through an Event Grid subscription (as step 4 and 5 in the above diagram):

  1. When a client is connected/disconnected to SignalR service, service will publish this event to Event Grid.

  2. In Azure function you can have an Event Grid trigger and subscribe to such events, then Event Grid will send those events to the function (through a webhook).

How to use it?


It’s very simple to make your serverless application subscribe to SignalR connection events. Let’s use Azure function as an example.

  1. First you need to make sure your SignalR Service instance is in serverless mode. (Create a SignalR Service instance if you haven’t done so.)

    Enable serverless mode

  2. Create an Event Grid trigger in your function app.

    Create Event Grid trigger

  3. In the Event Grid trigger, add an Event Grid subscription.

    Add Event Grid Subscription

    Then select your SignalR Service instance.

    Select SignalR Service instance

Now you’re all set! Your function app is now able to get connection events from SignalR Service.

To test it, you just need to open a SignalR connection to the service. You can use the SignalR client in our sample repo, which contains a simple negotiate API implementation.

  1. Clone AzureSignalR-samples repo.

  2. Start the sample negotiation server.

    cd samples\Management\NegotiationServer
    set Azure__SignalR__ConnectionString=<connection_string>
    dotnet run
  3. Run SignalR client.

    cd samples\Management\SignalRClient
    dotnet run

    Open the function logs in Azure portal and you’ll see a connected event is sent to the function:

    Azure Function output

    If you stop the client you’ll also see a disconnected event is received.

Try it now!


This feature is now in public preview so feel free to try it out and let us know your feedback by filing issues on Github.

For more information about how to use Event Grid with SignalR Service, you can read this article or try this sample.

Avatar
Ken Chen

Principal Software Engineering Manager

Follow Ken   



https://www.sickgaming.net/blog/2019/08/...vent-grid/
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

[-]
Discord

[-]
Active Threads
Are you still excited about the resurrec...
Last Post: Ulrica
Today 03:24 AM
» Replies: 0
» Views: 6
Can the player have two animal crossings...
Last Post: Sellen
Today 02:58 AM
» Replies: 0
» Views: 9
(Indie Deal) Cozy Grove, Iceberg, The Cr...
Last Post: xSicKxBot
Today 02:47 AM
» Replies: 0
» Views: 3
Microsoft - Aliens: Fireteam Elite avail...
Last Post: xSicKxBot
Today 02:47 AM
» Replies: 0
» Views: 2
News - GamesMaster: Episode 2 Heaps Prai...
Last Post: xSicKxBot
Today 02:47 AM
» Replies: 0
» Views: 2
News - Stardew Valley Patch 1.5.5 Adds E...
Last Post: xSicKxBot
Today 02:47 AM
» Replies: 0
» Views: 2
(Indie Deal) Tales of Arise, Paradox, Ko...
Last Post: xSicKxBot
Yesterday 11:09 PM
» Replies: 0
» Views: 14
News - Looks Like Pokémon GO’s Next Seas...
Last Post: xSicKxBot
Yesterday 11:09 PM
» Replies: 0
» Views: 3
[Tut] How to Deploy a Smart Contract on ...
Last Post: xSicKxBot
Yesterday 03:57 PM
» Replies: 0
» Views: 18
(Indie Deal) Anime Giveaways, Nerf Legen...
Last Post: xSicKxBot
Yesterday 03:57 PM
» Replies: 0
» Views: 4

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com



Discord Server © SickGaming.net 2012-2021