Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

c# - Send Azure SignalR message from Azure Function with CosmosDB Trigger

I’m developing a app that used CosmosDB to store data and then when anyone updates the data i want the clients to be updated. For this i have decided to use the changefeed and then Azure Functions and Azure SignalR.

I have set up 2 functions. A negotiate function (This one works and the clients connect correctly to the SignalR server) And a OnDocumentsChanged function, and my problem is getting the function to actually sending the message, when something is changed.

I have the following function:

[FunctionName("OnDocumentsChanged")]
    public static async Task Run(
        [CosmosDBTrigger(
        databaseName: "NewOrder",
        collectionName: "NewOrder",
        CreateLeaseCollectionIfNotExists = true,
        ConnectionStringSetting = "myserver_DOCUMENTDB",
        LeaseCollectionName = "leases")]
            IReadOnlyList<Document> updatedNewOrder,
        [SignalR(ConnectionStringSetting = "AzureSignalRConnectionString",  HubName = "NewOrder")] IAsyncCollector<SignalRMessage> signalRMessages,
        ILogger log)
    {
        if (updatedNewOrder != null && updatedNewOrder.Count > 0)
        {
            foreach (var Orders in updatedNewOrder)
            {
                await signalRMessages.AddAsync(new SignalRMessage
                {
                    Target = "NewOrderUpdated",
                    Arguments = new[] { Orders.Id }
                });
            }
            
        }

    }

I can see that it is correctly triggered when a change is made to the database, but no messages are send.

I guess I’m missing a out part that actually send the SignalRMessages I’m just not sure how to implement.

Thanks.

question from:https://stackoverflow.com/questions/65898323/send-azure-signalr-message-from-azure-function-with-cosmosdb-trigger

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...