azure-functions-powershell-worker icon indicating copy to clipboard operation
azure-functions-powershell-worker copied to clipboard

Unable to set custom properties on a ServiceBus message when using push-outputbinding

Open invisibleaxm opened this issue 5 years ago • 6 comments

When working with Azure Functions V2 (Powershell) ServiceBus output binding we are not able to add any user attributes to the servicebus message since the push-outputbinding cmdlet takes the object passed in "value" as the message body (it will serialize the object and submit that as the message text/body). ideally one could craft a Service Bus message of type Microsoft.Azure.ServiceBus.Message and use this object as the input for the push-outputbinding which will then :

  1. Use the $message.body value as the contents of the serviceBus message,
  2. Allow us to set any other $message attributes we need and honor them. For example the custom attribute is of upmost importance:
Import-Module .\modules\Microsoft.Azure.ServiceBus.dll
$Message = New-Object Microsoft.Azure.ServiceBus.Message
$Message.UserProperties.Add("name", "alex")
 # Should be able to send the message object out also and not just a string
Push-OutputBinding -Name demooutputSbMsg -Value $Message

Instead, when you call push-outputbinding, the whole $message object is processed as the actual body of the message, making it impossible to set custom attributes

see example: image

invisibleaxm avatar Aug 15 '19 18:08 invisibleaxm

Any update on this? This makes routing the messages really hard.

spaelling avatar Sep 12 '19 13:09 spaelling

Hi I am also facing same issue. please let us know when it iwll be fixed?

santoshdwivedi90 avatar Feb 04 '20 11:02 santoshdwivedi90

This would need to be updated in the Service Bus output binding code as it doesn't look like it currently supports it https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus?tabs=csharp#output

As an alternative, you can import the SDK and create the message and custom properties. I saw a sample on https://github.com/robotechredmond/Azure-PowerShell-Snippets/blob/master/Service%20Bus%20-%20Send%20to%20Queue.ps1 for doing this.

You can get the path to the to the servicebus dll from Split-path (Get-Module -ListAvailable -Name Az.ServiceBus | Select Path).Path

eamonoreilly avatar Feb 04 '20 18:02 eamonoreilly

Agreed that this would be very helpful. In addition to routing being difficult, it's also difficult to instrument application insights to track a request as it moves through queues.

I haven't looked at the Push-OutputBinding code, but seems having Push-OutputBinding detect a ServiceBus.Message object type and handles accordingly would be most helpful. Could also add a -ServiceBusMessage or -Message parameter in lieu of -Value or have a objecttype parameter in the bindings json.

burkasaurusrex avatar Jun 11 '20 22:06 burkasaurusrex

Hi!

Any update on this?

Currently using my own service bus client code for output, but it would be nice to be able to use simple bindings. Service Bus without custom props makes it impossible to do proper pubsub.

Thanks in advance!

mpriem avatar Nov 18 '20 05:11 mpriem

also running into this issue. has there been any updates from the team regarding passing userproperties/systemproperties?

gcmlpfaltaher avatar Sep 23 '21 22:09 gcmlpfaltaher