Can I run SignalR hub through Azure API Management?
Asked Answered
A

4

9

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.

Achitophel answered 12/6, 2015 at 6:37 Comment(0)
M
1

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.)

Mikkanen answered 10/3, 2023 at 15:3 Comment(1)
That's good to know. Unfortunately, it requires setting up a separate WebSocket API endpoint in API Management. AFAIK, this will not be a solution if you use SignalR embedded in your API (i.e. have a single operation like /hub on the same api).Howling
S
5

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

Seclusion answered 15/6, 2015 at 18:0 Comment(1)
Done: feedback.azure.com/forums/248703-api-management/suggestions/…. Thanks.Achitophel
P
3

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

Pyrophyllite answered 21/10, 2020 at 23:33 Comment(2)
websockets are now supported in APIM: learn.microsoft.com/en-us/azure/api-management/websocket-api. Does that mean we should be able to leverage APIM to establish connections with signalR service?Spikelet
@Spikelet yes, we have already moved to itPyrophyllite
S
2

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.

Schwinn answered 26/5, 2020 at 19:46 Comment(0)
M
1

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.)

Mikkanen answered 10/3, 2023 at 15:3 Comment(1)
That's good to know. Unfortunately, it requires setting up a separate WebSocket API endpoint in API Management. AFAIK, this will not be a solution if you use SignalR embedded in your API (i.e. have a single operation like /hub on the same api).Howling

© 2022 - 2024 — McMap. All rights reserved.