猿问

我们如何向消息添加属性?

进行绑定时是否可以设置消息属性(我认为它们称为 UserProperties)?

在我的函数中,我正在将输出绑定到服务总线:

    [return: ServiceBus("%Detach:Done%", Connection = "Detach:ServiceBus", EntityType = EntityType.Topic)]

当我们绑定到ServiceBus时,我们如何设置消息属性?


MYYA
浏览 134回答 2
2回答

慕莱坞森

public static class Function7{&nbsp; &nbsp; [FunctionName("Function7")]&nbsp; &nbsp; [return: ServiceBus("test2",&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Connection = "AzureServiceBusConnectionString", EntityType = EntityType.Queue)]&nbsp;&nbsp; &nbsp; public static async Task<Message> Run([ServiceBusTrigger("test",&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Connection = "AzureServiceBusConnectionString")]string myQueueItem, ILogger log)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; log.LogInformation(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $"C# ServiceBus queue trigger function processed message: {myQueueItem}");&nbsp; &nbsp; &nbsp; &nbsp; var message = new Message(Encoding.UTF8.GetBytes("{}"));&nbsp; &nbsp; &nbsp; &nbsp; message.Label = "Hello";&nbsp; &nbsp; &nbsp; &nbsp; message.UserProperties.Add("abc", 123);&nbsp; &nbsp; &nbsp; &nbsp; return await Task.FromResult<Message>(message);&nbsp; &nbsp; }}

湖上湖

在异步函数中,使用返回值或IAsyncCollector代替out参数。对于 2.x,使用Message而不是像 BrokeredMessage 这样的IAsyncCollector<Message>。然后您可以设置MessageId消息的属性。var message = new Message() { MessageId = messageId};
随时随地看视频慕课网APP
我要回答