azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[FEATURE REQ] Support new RateLimiter API in ServiceBusProcessor

Open markrendle opened this issue 1 year ago • 4 comments

Library name

Azure.Messaging.ServiceBus

Please describe the feature.

Microsoft just announced the System.Threading.RateLimiting package for .NET 7, but which is also compatible with netstandard2.0 and net462, so should be usable in the ServiceBus package.

It looks like it could be a useful alternative to the very simplistic MaxConcurrentMessages property on ServiceBusProcessorOptions, allowing more intelligent throttling of messages coming off the bus.

Consumers could implement custom RateLimiter types to throttle based on domain-specific parameters and constraints.

Also, a single RateLimiter instance could be shared between multiple ServiceBusProcessor instances running in a single process.

Internally, the code could be refactored to using ConcurrencyRateLimiter when MaxConcurrentMessages is used, so everything uses RateLimiter to keep things simple.

markrendle avatar Jul 21 '22 15:07 markrendle

Hi @markrendle. Thank you for your suggestion; this is an interesting idea that I think we'd like to look into further.

jsquire avatar Jul 21 '22 19:07 jsquire

@JoshLove-msft, @tg-msft, @KrzysztofCwalina: I'd appreciate any thoughts that you may have.

jsquire avatar Jul 21 '22 19:07 jsquire

How does a customer observe backpressure? Are they forced to catch exceptions, spin while limiter.GetAvailablePermits() <= 0, or ...?

FWIW, I've always wanted an abstraction like https://github.com/Azure/azure-sdk/issues/3841#issuecomment-1029433201 which overlaps some of these scenarios. It'd be interesting to prototype with RateLimiter in a pipeline policy to explore benefits/use cases across the SDK. I'd also have no problem making use of this in SB if we're already implementing our own less configurable version.

tg-msft avatar Jul 25 '22 22:07 tg-msft

I think a sample showing how to implement a custom rate limiting policy would be great.

KrzysztofCwalina avatar Aug 08 '22 23:08 KrzysztofCwalina

After further team discussion, this is not something that we are planning to add currently, as there have been no further requests nor discussion/upvotes on the issue. We'd be happy to accept a submission for a sample and collaborate on the design for one, should there be an interest in doing so. I'm going to close this out.

jsquire avatar Jul 24 '23 19:07 jsquire