Azure / azure-service-bus-dotnet

☁️ .NET Standard client library for Azure Service Bus
https://azure.microsoft.com/services/service-bus
Other
235 stars 120 forks source link

OnMessageCallback functionality missing in Microsoft.Azure.ServiceBus #634

Closed james-novino closed 5 years ago

james-novino commented 5 years ago

We have legacy code that subscribes to a queue on Azure Service Bus that was written using the WindowsAzure.ServiceBus library. We are developing new code in .Net Core aganist Microsoft.Azure.ServiceBus to send and consume from topics. However, there doesn't seem to be any corresponding functionality in Microsoft.Azure.ServiceBus for something like this :

member x.ConcurrentMessageRetrieval<'In, 'Out> 
        (decoder: Message -> Async<'In>,
         handler: 'In -> Async<'Out>, 
         beforeMessageComplete: 'Out -> Async<unit>,
         duringMessageComplete: 'Out -> Async<unit>,
         afterMessageComplete: bool -> 'Out -> Async<unit>,
         maxConcurrency: int) =

        receiveClient.OnMessageAsync(
            Func<BrokeredMessage, Task> (
                x.OnMessageCallback 
                    decoder 
                    handler 
                    beforeMessageComplete
                    duringMessageComplete
                    afterMessageComplete),
            new OnMessageOptions(AutoComplete = false, MaxConcurrentCalls = maxConcurrency) 
        )

We have an implemention that is heavily reliant on the fact that we can execute callbacks both before, during and after message completion.

I had noted there were some issues with earlier versions of the .Net Core library but it wasn't clear if a workaround existed or not (particularly that didn't require rework of legacy code).

Actual Behavior

  1. Unable to register callbacks for message completions
  2. Insufficient examples for how to deal with concurrent consumption of Service Bus Queues

Expected Behavior

  1. The ability or corresponding functionality to the OnMessageAsync functionality in WindowsAzure.ServiceBus
  2. Improved examples for consuming from queues concurrently or in Batches

Versions

SeanFeldman commented 5 years ago

@james-novino RegisterMessageHandler on both QueueClient and SubscriptionClient does exactly that. Have you examined it?

Readme.md calls has a section for samples. Two of those do exactly what you ask.

Except certain things that I didn't quite understand how you've achieved with the old client. Specifically: decoder and before/during/after. That feels to me like your in-house customization.

james-novino commented 5 years ago

I was able to figure out how to do it using the RegisterMessageHandler, after some additional investigation. Thank you, @SeanFeldman.