Anurag
Anurag

Reputation: 88

How to get the queue messageid inside the queue trigger function

I am trying to get the message Id of the currently processing message in a Queue in Azure web job. Couldn't find any proper documentation on how to get that.

public static void ProcessQueueMessage([QueueTrigger("%testingQueue%")] TestingMessageModel testMessage, TextWriter log)
{
   // want to do some logging for this particular triggered message using the messageid. How to get that?
}

Adding the TestingMessageModel as a reference, it doesn't have any guid. I want to use the GUID that azure creates when a message is put into the queue.

public class TestingMessageModel
{
  public int FromOrg {get; set;}
  public DateTime BatchDate {get; set;}
  public Payments[] payments {get; set;}
}

Upvotes: 3

Views: 2828

Answers (2)

Maicon Heck
Maicon Heck

Reputation: 2377

The queue trigger provides several metadata properties (including the message id).

These properties can be used as part of binding expressions in other bindings or as parameters in your code:

enter image description here

See https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=csharp#message-metadata

Upvotes: 3

George Chen
George Chen

Reputation: 14334

It supports to bind the id directly, you could check my code.

public static void ProcessQueueMessage([QueueTrigger("myqueue")] string message,ILogger logger, string id)
        {
            logger.LogInformation(message);
            logger.LogInformation($"{message}id={id}");
        }

enter image description here

enter image description here

Hope this could help you.

Upvotes: 8

Related Questions