webPubSubTrigger Disconnected doesn't trigger Azure function

RCDev 20 Reputation points
2023-10-27T10:21:44.7+00:00

An Azure function is started when the webPubSubTrigger "Disconnected" triggers. This does work when Clients disconnect by using webSocket.Abort(). It does not trigger when using the below within an Azure function:

actions.AddAsync(WebPubSubAction.CreateCloseAllConnectionsAction())

Another odd part of this is that clients are still receiving group messages but don't receive any messages send to them specifically using SendToUserAction. This creates a lot of issues for clients. I don't know how to detect this state if "Disconnected" doesn't trigger. How can I solve this?

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
60 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,286 questions
0 comments No comments
{count} votes

Accepted answer
  1. Deepanshu katara 4,905 Reputation points
    2023-10-27T10:35:11.31+00:00

    Hi, hope doing well

    To address your question , please check below

    In Azure Web PubSub, the "Disconnected" trigger is designed to be invoked when clients explicitly disconnect from a Web PubSub service, such as when they call webSocket.Abort(). However, the trigger won't be fired if you use the WebPubSubAction.CreateCloseAllConnectionsAction() to close all connections since this action is executed on the service side and doesn't involve a client-initiated disconnection. This is why the "Disconnected" trigger is not being triggered.

    To handle scenarios where you close all connections using this action and you still need to perform additional actions, you might consider an alternative approach:

    Custom Tracking: You can implement custom tracking within your Azure Functions. For instance, you can maintain a record of all connected clients and their statuses. When you use WebPubSubAction.CreateCloseAllConnectionsAction(), you can also update your tracking system to mark clients as disconnected. This would require some additional bookkeeping.

    Custom Actions: Implement custom actions to close connections and perform any additional actions you need. You can send a message to clients to instruct them to disconnect gracefully, and then close their connections when they acknowledge this message.

    Regarding the issue of clients not receiving messages sent specifically using SendToUserAction, this could be due to a variety of reasons:

    • Make sure the user identifiers are correctly specified.
    • Verify that the users are indeed connected when you send messages to them.
    • Ensure that there are no issues with the format or content of the messages being sent.
    • Check for any custom authorization rules that might restrict the delivery of messages to certain users.

    If you can provide more specific details about your Azure Functions and how you're using Web PubSub, I can offer more targeted assistance. Additionally, consulting the Azure Web PubSub documentation and monitoring the service for logs and diagnostics may help pinpoint the issues more precisely.

    Please accept answer if it has helped , Thanks!


0 additional answers

Sort by: Most helpful