1

I was following an example that targeted v1 Functions and what I want from it I haven't been able to replicate in v2.

I want the BrokeredMessage in the signature of the Azure Function.

public static async Task WhatIsTheTime(
            [ServiceBusTrigger(queueName: QueueName, Connection = ConnectionStringKey)]
            BrokeredMessage message, 
            ILogger log)
{
     var myObj = message.GetBody<MyType>();
     // whatever
}

primarily because it includes lots of handy metadata and I cba to change the signature every time I decide I want something different. Also because as the above example shows, its pretty easy to get the body.

However it seems like whatever out-of-the-box setup I have is furious at this idea. What it wants me to do is:

    public static async Task WhatIsTheTime(
            [ServiceBusTrigger(queueName: QueueName, Connection = ConnectionStringKey)]
            MyType myObj, 
            ILogger log)
{
    // whatever
}

and do that first step for me.
If I do this, everything is happy and we can all go home. However I don't want this, I'd rather the full BrokeredMessage.

No matter how I tried packaging the content of the body it failed miserably prior to my code executing giving me a host of different errors (depending on how I packaged it) but tellingly; this one:

Exception while executing function: Exception binding parameter Expecting element 'BrokeredMessage'   

Where its trying to deserialize the BODY of a BrokeredMessage into a BrokeredMessage!
What gives? I've read articles that state putting BrokeredMessage in the signature makes this stuff easy. Am I missing a configuration option or smth?

Quibblesome
  • 25,225
  • 10
  • 61
  • 100
  • This thread helped me with my issue. https://stackoverflow.com/questions/50710568/azure-servicebus-message-serialization-deserialization/50711229 – ezennnn Mar 06 '20 at 03:16
  • 1
    This helped me with the issue. https://stackoverflow.com/questions/50710568/azure-servicebus-message-serialization-deserialization/50711229 – ezennnn Mar 06 '20 at 03:17

3 Answers3

3

Azure Functions v2 doesn't use BrokeredMessage any more, it uses Microsoft.Azure.ServiceBus.Message instead.

MarkXA
  • 4,294
  • 20
  • 22
3

Here is the information from Azure Functions Service Bus Trigger documentation saying that the Service Bus message in Azure Functions V2 supports Meessage instead of BrokeredMessage.

Arunprabhu
  • 1,454
  • 9
  • 15
0

This has to do with the broken wire compatibility issue. If your original code is constructing BrokeredMessage using a constructor that takes an object rather than stream, this will cause the new .NET Standard client to fail. Unless an extension method is used to retrieve the body, which I presume Azure Functions doesn't do.

In case you have an option to update and re-deploy your senders/publishers, you could change how you construct your messages by sending a MemoryStream with bytes for the Function to be able to process it.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80