/// <summary> /// 使用KafkaMQ进行传输。 /// </summary> /// <param name="builder">服务构建者。</param> /// <returns>服务构建者。</returns> public static IServiceBuilder UseKafkaMQTransport(this IServiceBuilder builder, Action <KafkaOptions> options) { var kafkaOptions = new KafkaOptions(); var section = CPlatform.AppConfig.GetSection("Kafka"); if (section.Exists()) { kafkaOptions = section.Get <KafkaOptions>(); } else if (AppConfig.Configuration != null) { kafkaOptions = AppConfig.Configuration.Get <KafkaOptions>(); } options.Invoke(kafkaOptions); AppConfig.KafkaConsumerConfig = kafkaOptions.GetConsumerConfig(); AppConfig.KafkaProducerConfig = kafkaOptions.GetProducerConfig(); var services = builder.Services; builder.Services.RegisterType(typeof(Implementation.EventBusKafka)).As(typeof(IEventBus)).SingleInstance(); builder.Services.RegisterType(typeof(DefaultConsumeConfigurator)).As(typeof(IConsumeConfigurator)).SingleInstance(); builder.Services.RegisterType(typeof(InMemoryEventBusSubscriptionsManager)).As(typeof(IEventBusSubscriptionsManager)).SingleInstance(); builder.Services.RegisterType(typeof(KafkaProducerPersistentConnection)) .Named(KafkaConnectionType.Producer.ToString(), typeof(IKafkaPersisterConnection)).SingleInstance(); builder.Services.RegisterType(typeof(KafkaConsumerPersistentConnection)) .Named(KafkaConnectionType.Consumer.ToString(), typeof(IKafkaPersisterConnection)).SingleInstance(); return(builder); }
public EventBusKafkaModule UseKafkaMQTransport(ContainerBuilderWrapper builder) { var kafkaOptions = new KafkaOptions(); var section = CPlatform.AppConfig.GetSection("EventBus_Kafka"); if (section.Exists()) { kafkaOptions = section.Get <KafkaOptions>(); } else if (AppConfig.Configuration != null) { kafkaOptions = AppConfig.Configuration.Get <KafkaOptions>(); } AppConfig.KafkaConsumerConfig = kafkaOptions.GetConsumerConfig(); AppConfig.KafkaProducerConfig = kafkaOptions.GetProducerConfig(); builder.RegisterType(typeof(Implementation.EventBusKafka)).As(typeof(IEventBus)).SingleInstance(); builder.RegisterType(typeof(DefaultConsumeConfigurator)).As(typeof(IConsumeConfigurator)).SingleInstance(); builder.RegisterType(typeof(InMemoryEventBusSubscriptionsManager)).As(typeof(IEventBusSubscriptionsManager)).SingleInstance(); builder.RegisterType(typeof(KafkaProducerPersistentConnection)) .Named(KafkaConnectionType.Producer.ToString(), typeof(IKafkaPersisterConnection)).SingleInstance(); builder.RegisterType(typeof(KafkaConsumerPersistentConnection)) .Named(KafkaConnectionType.Consumer.ToString(), typeof(IKafkaPersisterConnection)).SingleInstance(); return(this); }