Beispiel #1
0
        /// <summary>
        /// 注入Kafka服务
        /// </summary>
        /// <param name="cissyConfigBuilder"></param>
        /// <returns></returns>
        public static CissyConfigBuilder AddKafkaConfig(this CissyConfigBuilder cissyConfigBuilder)
        {
            ICissyConfig cissyConfig = cissyConfigBuilder.CissyConfig;

            if (cissyConfig.IsNotNull())
            {
                KafkaConfig kafkaConfig = cissyConfig.GetConfig <KafkaConfig>();
                if (kafkaConfig.IsNotNull())
                {
                    DefaultKafkaFactory factory = new DefaultKafkaFactory();
                    factory.Config = kafkaConfig;
                    cissyConfigBuilder.ServiceCollection.AddSingleton(typeof(IKafakaFactory), factory);
                }
            }
            return(cissyConfigBuilder);
        }
Beispiel #2
0
        /// <summary>
        /// 注入kafka常驻内存服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cissyConfigBuilder"></param>
        /// <returns></returns>
        public static CissyConfigBuilder AddKafkaHostService <T>(this CissyConfigBuilder cissyConfigBuilder) where T : KafkaHostService, new()
        {
            ICissyConfig cissyConfig = cissyConfigBuilder.CissyConfig;

            if (cissyConfig.IsNotNull())
            {
                KafkaConfig kafkaConfig = cissyConfig.GetConfig <KafkaConfig>();
                if (kafkaConfig.IsNotNull())
                {
                    DefaultKafkaFactory factory = new DefaultKafkaFactory();
                    T service = new T();
                    service.InitService(factory, kafkaConfig);
                    cissyConfigBuilder.ServiceCollection.AddSingleton(typeof(IHostedService), service);
                }
            }
            return(cissyConfigBuilder);
        }
Beispiel #3
0
 public void InitService(IKafakaFactory KafakaFactory, KafkaConfig config)
 {
     _KafakaFactory = KafakaFactory;
     _config        = config;
 }