Search code examples
websocketazure-api-management

API Management WebSocket Rate Limiting


In Azure API Management, We'd like to control users websocket connections and messages send over connections.

Is it possible to achieve below by utilizing WebSocket feature?

  • Rate limit the number of WebSocket connections each user (or API key) can have at a time.
  • Rate limit the number of messages in a WebSocket connection.
  • Extract (Logging) WebSocket messages (not onHandshake requests). For example, creating Policy which logs messages to EventHub.

Thank you


Solution

  • All the policies can be applied only on the onhandshake operation, once the connection is upgraded, the policies will no longer get executed.

    For example, if you add a rate-limit or quota policy on the onhandshake, it will be applied only once during the websocket handshake, so in theory, you may restrict the client to not make more websocket connections but once the quota/rate-limit counter gets rest, the client will be able to make more connections regardless if the others are still active or not, unless your backend websocket service periodically recycles connections.

    So, in short, there is currently no way to limit the number of messages on APIM nor play with the message content.