Azure function WebPubSubTrigger never fired

Ning Zhu 131 Reputation points
2022-01-06T16:14:35.553+00:00

I am learning WebPubSub, and tried an azure function as following

    [FunctionName("Function1")]
    public static async Task Run(
        [WebPubSubTrigger("NewsHub2", WebPubSubEventType.User, "message")] 
        UserEventRequest request, BinaryData data, WebPubSubDataType dataType,
        ILogger log)
    {
        log.LogInformation(request.DataType.ToString());
        log.LogInformation(request.Data.ToString());
    }

I have added nuget package and WebPubSubConnectionString, the function starts up in debug without any errors, however, it will never fired, as I sending message using another console app

    static async Task Main(string[] args)
    {
        // Console.WriteLine("Hello World!");

        var connectionString = "Endpoint=https://XXXXXXXXXXXXXXXXX";
        var hub = "NewsHub2";
        var message = $"Test Info {DateTime.UtcNow}";

        // Either generate the token or fetch it from server or fetch a temp one from the portal
        var serviceClient = new WebPubSubServiceClient(connectionString, hub);
        await serviceClient.SendToAllAsync(message);
    }

From other client, I can clear see the message has been sent to everyone ...

Any help is highly appreciated!

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
75 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,029 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jialin Xin 1 Reputation point Microsoft Employee
    2022-01-11T06:07:46.727+00:00

    How do you configure the Event Handler in Web PubSub service side? The function will be triggered when there's client message through client WebSocket connection.
    Client --> Service -->(Event Handler) --> Server/Function -->(REST API) Service --> Clients

    See HERE to work with function bi-direction communication sample. And another simpler notification sample doesn't need event handler can be checked HERE which is doing similar things like your console app.

    Your second console app is working as a server that directly sends messages through Rest API. So event handler is not needed.
    Server --> Service --> Clients

    Besides, there's general Reference Doc about Function extensions. Please take a look to understand how's it working.

    0 comments No comments

  2. Ning Zhu 131 Reputation points
    2022-02-09T12:15:04.577+00:00

    I figured out later, the message is for point to point communication and will NOT fire azure function, in order to fire azure function you will need event not message, and then in the azure function you can capture specific event name with metadata associated with it.

    0 comments No comments

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.