7

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?enter image description here

tonjohn
  • 255
  • 2
  • 14
  • My workaround: https://stackoverflow.com/questions/48338448/sending-message-to-azure-service-bus-as-a-string-using-azure-logic-app/53013123#53013123 – tonjohn Aug 07 '19 at 00:45

2 Answers2

3

@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);
}
HariHaran
  • 3,642
  • 2
  • 16
  • 33
2

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

Ling Toh
  • 2,404
  • 1
  • 16
  • 24
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259/165483) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Samuel Liew Aug 13 '19 at 23:39