azure function service bus output message properties

人盡茶涼 提交于 2019-12-21 12:41:27

问题


I'm trying to set metadata for service bus messages in a JavaScript Azure Function using the service bus binding output. Unfortunately, it appears that the binding only supports the body.

Looking at the docs, I see that you can access this information in service bus triggers via context.bindingData but I don't see any corresponding interface for service bus output.

Is there some way to send a full brokered message and set the message properties (ContentType) and message custom properties?


回答1:


There is an open issue for this at https://github.com/Azure/Azure-Functions/issues/454

Some customers seemed to have found a workaround. Perhaps you can try their approach mentioned here https://github.com/Azure/Azure-Functions/issues/454#issuecomment-375154151




回答2:


@l--''''''---------'''''''''''' You need to access the Microsoft.Azure.ServiceBus.Message class. Let's say you have some json called messageBody

and you have some list of properties that you want to add to the message. You can achive it like the below example.

Make sure you add using Microsoft.Azure.ServiceBus;

var myCustomProperties = new List<Dictionary<string,string>>();
var message = new Message(Encoding.UTF8.GetBytes(messageBody));
foreach (var userProperty in myCustomProperties)
{
  message.UserProperties.Add(userProperty.Key, userProperty.Value);
}


来源:https://stackoverflow.com/questions/52901360/azure-function-service-bus-output-message-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!