question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Service Bus Extension] Support binding to ServiceBusReceivedMessage and POCO in the same function

See original GitHub issue

Library name and version

Microsoft.Azure.WebJobs.Extensions.ServiceBus 5.3.0

Query/Question

I have code that was written using Microsoft.Azure.WebJobs.Extensions.ServiceBus v4.3.0 that was dead lettering the message if it didn’t pass validation:

    internal sealed class ProcessEventFunction
    {
        private readonly MyEventValidator eventValidator;

        public ProcessEventFunction(MyEventValidator? eventValidator)
        {
            this.eventValidator = eventValidator ?? throw new ArgumentNullException(nameof(eventValidator));
        }

        [Disable("DisableFunctions")]
        [FunctionName(nameof(ProcessEventAsync))]
        public Task ProcessEventAsync(
            [ServiceBusTrigger("%EventTopicName%", "%SubscriptionName%", Connection = "ServiceBusConnection")]
                MyEvent myEvent,
            MessageReceiver messageReceiver, 
            string lockToken
        )
        {
                    ValidationResult validationResult = eventValidator.Validate(myEvent);

                    if (!validationResult.IsValid)
                    {
                        await messageReceiver.DeadLetterAsync(lockToken);
                        return;
                    }

                    // Process event
        }
    }

Note the use of the strongly typed message.

I am struggling to figure out how to migrate this to v5.3.0 while also still using strongly typed messages.

As #26564 rightly points out, there is currently nothing in the migration document that mentions sending messages to the Dead Letter Queue.

I did manage to find the Message Settlement section within the package’s readme file. Unfortunately, the mentioned ServiceBusMessageActions DeadLetterMessageAsync() method seems to only take a ServiceBusReceivedMessage and not a strongly typed message.

Can you please provide guidance on how to send a strongly typed message to the Dead Letter Queue using the v5.3.0 package?

Environment

Win64 Azure Function using .NET 6 in process model Visual Studio 17.1.3

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
schneidenbachcommented, Dec 10, 2022

Sorry, to clarify, manual dead lettering is only currently supported for in process functions. Adding support for isolated functions is actively being investigated.

Along the same lines, binding to the ServiceBusReceivedMessage is only available right now for in-process, but is also being investigated for isolated functions.

@JoshLove-msft consider this a vote for support for SDK types in Isolated Functions.

2reactions
Dmo16commented, Aug 27, 2022

Hey Josh,

Thanks for the tip, and for commenting on the weekend, much appreciated!

That did fix the in process function for me and I’m now able to dead letter just fine.

I tried the same thing with the isolated function though, to see if I could figure out why the message was null and I received this error:

Exception: Microsoft.Azure.Functions.Worker.FunctionInputConverterException: Error converting 1 input parameters for Function 'CreateSeasonTrigger': Cannot convert input parameter 'message' to type 'Azure.Messaging.ServiceBus.ServiceBusReceivedMessage' from type 'System.String'.

I’ll need to scour the docs again to find the right way to handle this with isolated functions as we will be migrating to them with .NET 7 this fall.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Service Bus bindings for Azure Functions
The Service Bus extension supports parameter types according to the table below. Binding scenario, Parameter types. Service Bus trigger (single ...
Read more >
Azure Service Bus trigger for Azure Functions
Use the Service Bus trigger to respond to messages from a Service Bus queue or topic. Starting with extension version 3.1.0, you can...
Read more >
Perform MessageActions on Messages for .Net 6 Isolated ...
I'd like to bind to the equivalent of a BrokeredMessage/Message/ServiceBusReceivedMessage. Strings and pocos only it seems? Seems like binding ...
Read more >
Azure WebJobs Service Bus client library for .NET
The Service Bus Output Binding allows a function to send Service Bus messages. Please follow the Azure Service Bus output binding to learn...
Read more >
Azure Service Bus SDK - sfeldman.NET
Message sent from the client-side, ServiceBusMessage is not the type received. Received messages are of the type ServiceBusReceivedMessage . It's an "extension" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found