rabbitmq / rabbitmq-dotnet-client

RabbitMQ .NET client for .NET Standard 2.0+ and .NET 4.6.2+
https://www.rabbitmq.com/dotnet.html
Other
2.07k stars 579 forks source link

Expose ConnectionFactory.DispatchConsumersAsync as a ReadOnly property on IConnection #1610

Closed luizcarlosfaria closed 3 months ago

luizcarlosfaria commented 3 months ago

Is your feature request related to a problem? Please describe.

Assuming that the user code create a Connectionfactory instance, directly or using .NET Aspire, my code (library) need to check (to verify during worker startup) when user use DispatchConsumersAsync = false, but try to use a asynchronous consumer.

Describe the solution you'd like

RabbitMQ.Client.ConnectionConfig is created with a DispatchConsumersAsync boolean property copy during ConnectionFactory.CreateConnectionAsync() call.

ConnectionConfig is forward to both, AutorecoveringConnection or Connection, constructors.

But today IConnection does not have a property to expose this.

Possible Solution

On RabbitMQ.Client.IConnection Interface

bool DispatchConsumersAsync { get; }

On RabbitMQ.Client.Framing.Impl.AutorecoveringConnection Class

bool DispatchConsumersAsync => this._config.DispatchConsumersAsync;

On RabbitMQ.Client.Framing.Impl.Connection Class

bool DispatchConsumersAsync => this._config.DispatchConsumersAsync;

Describe alternatives you've considered

Throw an exception itself when call Channel.BasicConsume() method with a synchronous consumer when ConnectionFactory is set to work with asynchronous dispatch. And vice-versa.

Additional context

No response

lukebakken commented 3 months ago

Please note that using the wrong combination of DispatchConsumersAsync and a consumer class will throw an exception:

https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/main/projects/RabbitMQ.Client/client/impl/ChannelBase.cs#L976-L982

lukebakken commented 3 months ago

See #1615

lukebakken commented 3 months ago

Fixed by #1615