端点pretfetchcount

问题描述 投票:0回答:1

我们正在寻找一种使用.NET配置和配置密钥的消费者名称的每个端点,以配置所有端点的所有端点的预摘要计数。

我们现在有类似的东西,它使用反射,但希望改进并简化此代码。

services.AddMassTransit(x => { var endpointSettingServices = x.Where(x => x.Lifetime == ServiceLifetime.Singleton && x.ImplementationInstance is not null && x.ServiceType.IsGenericType && x.ServiceType.GetGenericTypeDefinition() == typeof(IEndpointSettings<>)).ToList(); foreach (var service in endpointSettingServices) { var setting = service.ImplementationInstance; var consumerType = service.ServiceType.GetGenericArguments()[0].GetGenericArguments()[0]; var consumerName = consumerType.Name; var prefetchCount = configuration.GetValue<int?>($"EndpointSettings:{consumerName}:PrefetchCount", null); if (prefetchCount.HasValue) { setting.GetType().GetProperty(nameof(EndpointSettings<object>.PrefetchCount)).SetValue(setting, prefetchCount.Value); } } });
因此,我们想知道如何以一种更简单,更简单的方式做到这一点。
    

您可以在总线上设置
c# publish-subscribe messaging masstransit
1个回答
0
投票

,该设置将用作所有接收端点的默认值。然后,您可以在个人接收端点上覆盖该设置。


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.