2

I am using C# to create an Azure function using a QueueMessage trigger. I want to get the insertion time of the queue message.

In the code that runs the the function I have access to the message body as a string, as per the standard signature from the template in Visual Studio:

[QueueTrigger("url-content-300", Connection = "AzureWebJobsStorage")]string myQueueItem

However I want to get the insertion time of the message.

In the Python template it gives me the whole message queue object like the following:

msg: func.QueueMessage

which I can then deserialise as a Json Object:

result = json.dumps({
    'id': msg.id,
    'body': msg.get_body().decode('utf-8'),
    'expiration_time': (msg.expiration_time.isoformat()
                        if msg.expiration_time else None),
    'insertion_time': (msg.insertion_time.isoformat()
                       if msg.insertion_time else None),
    'time_next_visible': (msg.time_next_visible.isoformat()
                          if msg.time_next_visible else None),
    'pop_receipt': msg.pop_receipt,
    'dequeue_count': msg.dequeue_count
})
insertionTime = result.insertion_time

How do I do that in C# ?

1 Answer 1

4

Instead of retrieving it as a string you can retrieve it as a CloudQueueMessage which will contain the metadata you are after. E.g.

[QueueTrigger("...", Connection = "...")]CloudQueueMessage inputQueueItem
//...
var content = inputQueueItem.AsString;
var insertionTime = inputQueueItem.InsertionTime;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.