Home Azure Functions.- Message Queue Messsage Properties
Post
Cancel

Azure Functions.- Message Queue Messsage Properties

Message Properties on a Message Queue Azure Function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[Function("Function1")]
public void Run([ServiceBusTrigger("myqueue", Connection = "sbconnectionstring")] string myQueueItem, FunctionContext context)
{
    _logger.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

    var bindingData = context.BindingContext.BindingData;
    _logger.LogInformation($"Body: {myQueueItem} context: {string.Join(',', bindingData.Keys)}");
    foreach (var key in bindingData.Keys)
    {
        _logger.LogInformation($"Key: {key}, Type: {bindingData[key]?.GetType()} Value: {bindingData[key]}");
    }

    context.BindingContext.BindingData.TryGetValue("UserProperties", out var appProperties);
    if (appProperties is string properties)
    {
        var dict = JsonSerializer.Deserialize<Dictionary<string, object>>(properties);
        if (dict != null)
        {
            _logger.LogInformation($"Sender: {dict["Sender"]}");
            _logger.LogInformation($"Number: {dict["Number"]}");
        }
    }
}
This post is licensed under CC BY 4.0 by the author.