Reputation: 60751
Is it possible to set message properties (I think they are called UserProperties) when doing a binding?
Within my function I'm doing an output binding to servicebus:
[return: ServiceBus("%Detach:Done%", Connection = "Detach:ServiceBus", EntityType = EntityType.Topic)]
How do we set the message properties when we are binding to ServiceBus?
Upvotes: 1
Views: 2686
Reputation: 8235
public static class Function7
{
[FunctionName("Function7")]
[return: ServiceBus("test2",
Connection = "AzureServiceBusConnectionString", EntityType = EntityType.Queue)]
public static async Task<Message> Run([ServiceBusTrigger("test",
Connection = "AzureServiceBusConnectionString")]string myQueueItem, ILogger log)
{
log.LogInformation(
$"C# ServiceBus queue trigger function processed message: {myQueueItem}");
var message = new Message(Encoding.UTF8.GetBytes("{}"));
message.Label = "Hello";
message.UserProperties.Add("abc", 123);
return await Task.FromResult<Message>(message);
}
}
Upvotes: 4
Reputation: 20067
In async functions, use the return value or IAsyncCollector
instead of an out
parameter. For 2.x, use Message instead of BrokeredMessage like IAsyncCollector<Message>
.
Then you can set the MessageId
property on the message. Refer to this thread.
var message = new Message() { MessageId = messageId};
Upvotes: 2