MassTransit - 有什么方法可以将参数设置从 appsettings 注入 ConfigureConsumer?
MassTransit - Any way to inject parametric settings from appsettings to ConfigureConsumer?
如 here 所述,我想从 appSettings.json 设置批处理设置。有没有办法使用 DI 的 ConfigureConsumer 来做到这一点?
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator,
IConsumerConfigurator<OrderAuditConsumer> consumerConfigurator)
{
consumerConfigurator.Options<BatchOptions>(options => options
.SetMessageLimit(100)
.SetTimeLimit(1000)
.SetConcurrencyLimit(10));
}
您可以将依赖项添加到 ConsumerDefinition
的构造函数(具有问题中显示的方法的 class ),因为定义是在总线配置期间从容器解析的。这是一个非常常见的用例,并且可以轻松处理。
The extensions IOptions
types are good for this, which are part of .NET (Microsoft.Extensions.Configuration
I think).
如 here 所述,我想从 appSettings.json 设置批处理设置。有没有办法使用 DI 的 ConfigureConsumer 来做到这一点?
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator,
IConsumerConfigurator<OrderAuditConsumer> consumerConfigurator)
{
consumerConfigurator.Options<BatchOptions>(options => options
.SetMessageLimit(100)
.SetTimeLimit(1000)
.SetConcurrencyLimit(10));
}
您可以将依赖项添加到 ConsumerDefinition
的构造函数(具有问题中显示的方法的 class ),因为定义是在总线配置期间从容器解析的。这是一个非常常见的用例,并且可以轻松处理。
The extensions
IOptions
types are good for this, which are part of .NET (Microsoft.Extensions.Configuration
I think).