Can I run SignalR hub through Azure API Management?

5.5k views Asked by At

I have the same question as this guy: can I run my SignalR hub through the Azure API management service?

enter image description here

I cannot seem to configure it in the service: it only allows me to forward HTTP/HTTPS traffic. That matches the answer of the person in the forum post. I followed the link down to the Microsoft forum, but it seems the question wasn't followed up there. Since the response was from 2014, I thought - maybe it is possible now.

4

There are 4 answers

1
jasdefer On BEST ANSWER

API Management supports Web Sockets now.

  1. Navigate to the API Management instance in the Azure Portal
  2. Add Api
  3. Under Define a new API, select WebSocket
  4. In the dialog box, select Full and complete the required form fields
  5. Click create

https://learn.microsoft.com/en-us/azure/api-management/websocket-api?tabs=portal

(WebSocket APIs are not supported yet in the Consumption tier.)

1
Miao Jiang On

websocket is currently not supported in Azure API Management. Please feel free to raise a feature request: http://feedback.azure.com/forums/248703-api-management/filters/new

2
Roman Marusyk On

As we know, the Azure API Management still doesn't support WebSockets

Dec 6, 2016:
Rest assured we still have this request in mind and are continually reviewing it. Please keep your feedback coming!

If you are using Azure SignalR Service then you can follow the way described by @lazizanie because your SignalR service should only provide a negotiate endpoint:

enter image description here

Let's say you have the Hub named myHub in ASP.NET Core 3.1

app.UseEndpoints(endpoints => endpoints.MapHub<Hub>("/myHub"));

Then add operation in API management URL=POST /myHub/negotiate with negotiateVersion query param

or use JSON editor and add it to paths

"/myHub/negotiate": {
    "post": {
        "summary": "SignalR negotiate ",
        "operationId": "signalr-negotiate",
        "parameters": [{
            "name": "negotiateVersion",
            "in": "query",
            "schema": {
                "type": ""
            }
        }],
        "responses": {
            "200": {
                "description": null
            }
        }
    }
}

For the Backed set host of your SignalR service like https://myHubSignalR.westeurope.cloudapp.azure.com

0
lazizanie On

It depends, websockets are not supported, but if you use an azure signalr ressource, only the negotiate request,; which is a basic post to your hub, has to go through your APIM, and the rest of the coms (the websocket requests) will be directly with the azure signalr ressource.