4

I'm facing issue to send a complete brokered message to an azure service bus output in azure function in javascript. The documentation only show a simple body message https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus without any customerProperties.

My attempts to create a full brokered message failed so far, everything goes into the body.

enter image description here enter image description here

var message = {'body' : 'test', 'customProperties' : {'fromsystem':'sap'}};
context.bindings.outputSbMsg = message;
context.done(null, res);
Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
camous
  • 998
  • 11
  • 27

1 Answers1

4

Unfortunately this is one of the limitations of node, as we lose some type information that we have in C#.

You could be trying to send a message with a body of test with custom properties, but you could also be trying to send the entire object as the body, with a body sub-property. Azure Functions make the assumption that everything that you return should go into the body.

As a workaround, you could:

  • ditch the output binding and use the ServiceBus sdk for node directly
  • instead of node, use C# or F# with the actual BrokeredMessage type
  • have your node function put the result into a queue, which then triggers a C# function to create the exact BrokeredMessage you want
Matt Mason
  • 2,676
  • 9
  • 22
  • sad :) the integration was really easy. I might fallback to C# as you suggested. I thought about a 4th solution with an intermediate queue + rule & a SET property, but it's only possible for subscribers, not queues. – camous Feb 08 '17 at 19:58
  • [C# approach] in order to add 'out BrokeredMessage outputSbMsg' in my Run method prototype, I had to switch from async to sync. I don't know if there is another way :/ but it's working :) – camous Feb 09 '17 at 21:00
  • You could use the type IAsyncCollector. Here are some other types you can use: https://jhaleyfiles2016.blob.core.windows.net/public/Azure%20WebJobs%20SDK%20Cheat%20Sheet%202014.pdf – Matt Mason Feb 09 '17 at 21:21
  • 2
    Please state this limitation clearly in the documentation, https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus#service-bus-output-binding. It took som googling, trial and error before I ended up here. – Jon Jun 26 '17 at 10:54
  • in order to be able to provide custom properties in an output binding, can we use this in c#? `IAsyncCollector` – Alex Gordon Aug 06 '19 at 22:44