예제 #1
0
    public static IServiceCollection AddKafkaConsumer(this IServiceCollection serviceCollection, string brokers,
                                                      string groupId, bool allowAutoCreateTopics = true, bool isAsync = true)
    {
        if (string.IsNullOrEmpty(brokers))
        {
            throw new ArgumentNullException(nameof(brokers));
        }
        var consumer = new KafkaConsumerConnection(brokers, groupId, allowAutoCreateTopics);

        serviceCollection.AddSingleton <IKafkaConsumerConnection>(factory => consumer);
        return(serviceCollection);
    }
예제 #2
0
        public static IServiceCollection AddKafkaConsumer(this IServiceCollection serviceCollection, string brokers,
                                                          string groupId, bool allowAutoCreateTopics = true)
        {
            if (string.IsNullOrEmpty(brokers))
            {
                throw new ArgumentNullException(nameof(brokers));
            }


            var consumer = new KafkaConsumerConnection(brokers, groupId);

            consumer.Config.AllowAutoCreateTopics = allowAutoCreateTopics;
            serviceCollection.AddSingleton <IKafkaConsumerConnection>(factory => consumer);

            // serviceCollection.AddSingleton<IEventBusDispatcher, KafkaEventBusDispatcher>();

            return(serviceCollection);
        }