Path parameters in Web PubSub Service

Martin Body 20 Reputation points
2024-12-09T08:38:50.2233333+00:00

Hello,

I am trying to setup event handlers in Azure PubSub which reads and forwards path parameters, but I didn't find a way how to do it. Does it support such a scenario?

pubsub wss:

wss://mysite.webpubsub.azure.com/client/hubs/hubname/{pathParam}

 

event handler:

https://event-handler.net/api/connect/{pathParam}

 

Thank you.

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
79 questions
{count} votes

Accepted answer
  1. Laxman Reddy Revuri 1,130 Reputation points Microsoft Vendor
    2024-12-19T01:00:07.24+00:00

    Hi @Martin Body
    The current approach with query parameters (?stationId=Station01) works but requires reconnecting if the stationId changes. It's simple but limited in flexibility.  Web PubSub does not natively support extracting stationId from path parameters (/Station01).

    When utilizing path parameters, one must have an additional layer such as Azure Functions or Azure API Management to:

    Extract the stationId from the URL path.

    Pass it on as a query parameter or metadata to Web PubSub.

    Azure Functions:

    A physical charging station connects to the Azure Function Websocket endpoint against the format, for instance, wss://.azurewebsites.net/Station01.

    The Azure Function removes Station01 from the path and sends this connection to Web Pub Sub composed of the stationId in the query string or the metadata.

    If you want a serverless, easy-to-maintain approach, Azure API Management is likely the best choice since it requires minimal logic changes and no custom gateway code. If you need more control or advanced logic, go with Azure Functions.

    I hope this information is helpful.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.