Jack
Jack

Reputation: 307

Getting Session Id in Azure Functions with ServiceBusTrigger

I'm having trouble setting up an Azure Function that reads from ServiceBus. I have a Service Bus Queue created and I'm adding messages with the Service Bus Explorer in Azure Portal. Here is my working function code.

    [Function("TestMessageIngester")]
    public static async void TestMessageIngester(
    [ServiceBusTrigger(queueName:"BatchTests", Connection = "MyServiceBus", IsSessionsEnabled = true)]
    string myQueueItem,
    string messageId,
    string label,
    //IMessageSession messageSession, 
    FunctionContext context)
    {
        var logger = context.GetLogger("TestMessageIngester");
        logger.LogInformation($"TestMessageIngester processed a message");
    }

This has no problem reading from the queue. I've had it working for JSON objects as well. However, I'm having an issue getting the session id. When I add MessageSession or IMessageSession, I get this:

Error converting 1 input parameters for Function 'TestMessageIngester': Cannot convert input parameter 'messageSession' to type 'Microsoft.Azure.ServiceBus.IMessageSession' from type 'System.String'.

I've also tried using the ServiceBusReceivedMessage type in Azure.Messaging.ServiceBus as a parameter, but it just comes in as null. The same for Microsoft.Azure.ServiceBus.Message. I'm going off the docs here but feel like I'm missing something, any help would be appreciated.

Edit: I should mention this is .NET 5 Isolated.

Edit2: I'm reading in the GitHub issues that it's not possible to bind to SDK types in .NET 5 Isolated. Still hoping there is some way to get the session id that I've missed.

Upvotes: 3

Views: 2147

Answers (1)

Josh Love
Josh Love

Reputation: 350

It doesn't look like this is included in the metadata bindings in either the V4 or V5 version of the trigger (which is in preview). Would you mind submitting a feature request to https://github.com/Azure/azure-sdk-for-net to get this added? I think it should be fairly straightforward to include the sessionId in the contract in https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/src/Triggers/ServiceBusTriggerBindingStrategy.cs#L77

Note that this repo specifically releases the V5 version of the trigger which is still in beta.

Upvotes: 3

Related Questions