Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

azure function service bus output message properties

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

like image 574
tonjohn Avatar asked Oct 20 '18 00:10

tonjohn


People also ask

Does Azure Service Bus store messages?

What is an Azure Service Bus queue? A Service Bus queue is an entity in which messages are stored. Queues are useful when you have multiple applications, or multiple parts of a distributed application that need to communicate with each other.

How do I check messages on Azure Service Bus queue?

To peek messages, select Peek Mode in the Service Bus Explorer dropdown. Check the metrics to see if there are Active Messages or Dead-lettered Messages to peek and select either Queue / Subscription or DeadLetter sub-queue. Select the Peek from start button.


2 Answers

@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);
}
like image 82
HariHaran Avatar answered Oct 22 '22 03:10

HariHaran


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

like image 20
Ling Toh Avatar answered Oct 22 '22 02:10

Ling Toh