예제 #1
0
        public static IServiceCollection AddCKafkaServices(this IServiceCollection services, KafkaOptions options)
        {
            services.AddSingleton(options);
            AppConfig.KafkaConfig = options.GetConfig();

            return(CKafkaServices(services));
        }
예제 #2
0
        public static IServiceCollection AddCKafkaServices(this IServiceCollection services, IConfigurationRoot Configuration)
        {
            var options = new KafkaOptions()
            {
                Servers = Configuration.GetSection("KafkaConfig").GetValue <string>("BorkerList")
            };

            services.AddSingleton(options);
            AppConfig.KafkaConfig = options.GetConfig();

            return(CKafkaServices(services));
        }
예제 #3
0
        /// <summary>
        /// 使用KafkaMQ进行传输。
        /// </summary>
        /// <param name="builder">服务构建者。</param>
        /// <returns>服务构建者。</returns>
        public static IServiceBuilder UseKafkaMQTransport(this IServiceBuilder builder, Action <KafkaOptions> options)
        {
            var kafkaOptions = new KafkaOptions();

            options.Invoke(kafkaOptions);
            AppConfig.KafkaConfig = kafkaOptions.GetConfig();
            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);
        }