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.

[FEATURE REQ] Azure Service Bus Enforce mandatory processor arguments on CreateProcessor

See original GitHub issue

Right now I can do the following

await using var receiver = serviceBusClient.CreateProcessor(destination, optionalOptions);
receiver.ProcessMessageAsync += async processMessagesEventArgs =>
{
    // processing logic
};

but if I try to start this I get a runtime exception telling me

Unhandled exception. System.InvalidOperationException: Cannot begin processing without ProcessErrorAsync handler set.
   at Azure.Messaging.ServiceBus.ServiceBusProcessor.ValidateErrorHandler()
   at Azure.Messaging.ServiceBus.ServiceBusProcessor.StartProcessingAsync(CancellationToken cancellationToken)

given that only ever one handler can be assigned, which is enforced by

https://github.com/Azure/azure-sdk-for-net/blob/6e4c8ea877c94adf7279c0c8ca458dd69ccadee6/sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs#L289

why not enforce the two required handler parameters as input to CreateProcessor? How useful is it that those two are exposed as “event handler delegate” that are not really event handler delegates (because normally you could have multiple, here you can’t) and in all the cases you always have to set both?

I think a similar API to the following would be more intention revealing and avoid runtime errors:

public ServiceBusProcessor CreateProcessor(otherMandatoryParams..., Func<ProcessMessageEventArgs, Task> messageHandler, Func<ProcessErrorEventArgs> errorHandler, ServiceBusSessionReceiverOptions options = default)

Once you have that signature it becomes clear for me as a user of the API that I always have to specify both. Then it might also become an option to rename the parameter from *EventArgs so something different because really those handlers are not real multicast .NET events.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
danielmarbachcommented, Mar 1, 2021

Thanks for sharing the background info. Learned a ton.

1reaction
danielmarbachcommented, Mar 1, 2021

Fair enough. This is my personal feedback from my fiddling around with the new API. That certainly doesn’t invalidate all the previous user studies. Mine is just an opinion I wanted to share. Happy to close after seeing the explanation.

My mind was kind of caught up in finding a solution that would lead me to use it the proper way without having to be told with a runtime exception

Read more comments on GitHub >

github_iconTop Results From Across the Web

ServiceBusClient.CreateProcessor Method
Creates a ServiceBusProcessor instance that can be used to process messages using event handlers that are set on the processor.
Read more >
Best practices for improving performance using Azure ...
Describes how to use Service Bus to optimize performance when exchanging brokered messages.
Read more >
Quickstart - Use Azure Service Bus queues from .NET app
This quickstart shows you how to send messages to and receive messages from Azure Service Bus queues using the .NET programming language.
Read more >
Azure Service Bus client library for .NET
It offers automatic completion of processed messages, automatic message lock renewal, and concurrent execution of user specified event handlers.
Read more >
ServiceBusProcessor Class (Azure.Messaging.ServiceBus)
It is constructed by calling CreateProcessor(String, ServiceBusProcessorOptions). The message handler is specified with the ProcessMessageAsync property.
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