问题描述
public class RequestSentConsumerDeFinition : ConsumerDeFinition<RequestSentConsumer>
{
protected override void ConfigureConsumer(
IReceiveEndpointConfigurator endpoint,IConsumerConfigurator<RequestSentConsumer> consumer)
{
var rabbitmq = endpoint as RabbitMqReceiveEndpointConfiguration;
rabbitmq.Lazy = true;
consumer.UseMessageRetry(retry => retry
.Incremental(3,TimeSpan.FromSeconds(1),TimeSpan.FromSeconds(1)));
}
}
是否有更优雅的方法来设置队列延迟?
也许在任何外部软件包中MT都具有RabbitMQConsumerDeFinition
或ConsumerDeFinition<RequestSentConsumer,RabbitMqReceiveEndpointConfiguration>
之类的东西?
解决方法
对于使用者定义中特定于传输的配置,您应该对接收端点配置器进行模式匹配,并根据需要应用特定于传输的配置。
protected override void ConfigureConsumer(
IReceiveEndpointConfigurator endpointConfigurator,IConsumerConfigurator<RequestSentConsumer> consumerConfigurator)
{
if(endpointConfigurator is IRabbitMqReceiveEndpointConfigurator rmq)
rmq.Lazy = true;
}