0

I've got a function with a CosmosDBTrigger and I want to pipe notifications out to SignalR clients. The Cosmos trigger gives you an IEnumerable of items, which may belong to multiple different clients, I've tried returning a List<SignalRMessageAction> but I get a serialization error. Is it possible to return multiple items from a function using [SignalROutput] ?

public class UpdatesAvailableFunction
{
    [Function(nameof(UpdatesAvailableFunction))]
    [SignalROutput(HubName = "serverless", ConnectionStringSetting = "AzureSignalRConnectionString")]
    public List<SignalRMessageAction> UpdatesAvailable(
        [CosmosDBTrigger(
            databaseName: "%DatabaseName%",
            collectionName: "%ContainerName%",
            ConnectionStringSetting = "ConnectionString",
            LeaseCollectionName = "leases",
            LeaseCollectionPrefix = "UpdatesAvailable")]
        IReadOnlyList<BrowserFeedNotification> input)
    {
        return input.Select(x => new SignalRMessageAction("updatesAvailable")
        {
            UserId = x.UserId
        }).ToList();
    }
}

The error message I'm getting is

[2022-11-04T11:01:32.319Z] Executed 'Functions.UpdatesAvailableFunction' (Failed, Id=b7ebfc4a-40cc-48ef-9f31-52c7c414daf3, Duration=15342ms) [2022-11-04T11:01:32.320Z] System.Private.CoreLib: Exception while executing function: Functions.UpdatesAvailableFunction. Microsoft.Azure.WebJobs.Extensions.SignalRService: Unable to convert JObject to valid output binding type, check parameters.

Greg B
  • 14,597
  • 18
  • 87
  • 141
  • Try creating new list and assign those values https://github.com/John-ltf/IoT-app/blob/b3d90e1222c97eb0245a64aef100c82c8cd2cce1/IoT-functions/IoTTelemetryData.cs#L293 – Sajeetharan Nov 04 '22 at 12:20
  • @Sajeetharan thanks for your comment. That's basically what I'm doing with the call to `ToList()` at the end of the return line. The consumer (in this case, Azure Functions) doesn't know or care how the list was created, just that it's being given a list. – Greg B Nov 05 '22 at 08:31
  • Another way is described here: https://weblogs.asp.net/sfeldman/functions-isolated-worker-sending-multiple-messages – Caveman74 Nov 16 '22 at 09:50

0 Answers0