コード例 #1
0
ファイル: Producer.cs プロジェクト: scroyston/kafka
        /// <summary>
        /// Initializes a new instance of the <see cref="Producer&lt;TKey, TData&gt;"/> class.
        /// </summary>
        /// <param name="config">The config object.</param>
        /// <param name="partitioner">The partitioner that implements <see cref="IPartitioner&lt;TKey&gt;" />
        /// used to supply a custom partitioning strategy based on the message key.</param>
        /// <param name="producerPool">Pool of producers, one per broker.</param>
        /// <param name="populateProducerPool">if set to <c>true</c>, producers should be populated.</param>
        /// <remarks>
        /// Should be used for testing purpose only.
        /// </remarks>
        internal Producer(
            ProducerConfiguration config,
            IPartitioner <TKey> partitioner,
            IProducerPool <TData> producerPool,
            bool populateProducerPool = true)
        {
            Guard.NotNull(config, "config");
            Guard.NotNull(producerPool, "producerPool");

            this.config               = config;
            this.partitioner          = partitioner ?? new DefaultPartitioner <TKey>();
            this.populateProducerPool = populateProducerPool;
            this.producerPool         = producerPool;
            if (this.config.IsZooKeeperEnabled)
            {
                this.brokerPartitionInfo = new ZKBrokerPartitionInfo(this.config, this.Callback);
            }
            else
            {
                this.brokerPartitionInfo = new ConfigBrokerPartitionInfo(this.config);
            }

            if (this.populateProducerPool)
            {
                IDictionary <int, Broker> allBrokers = this.brokerPartitionInfo.GetAllBrokerInfo();
                foreach (var broker in allBrokers)
                {
                    this.producerPool.AddProducer(
                        new Broker(broker.Key, broker.Value.Host, broker.Value.Host, broker.Value.Port));
                }
            }
        }
コード例 #2
0
    public KafkaDistributedEventBus(
        IServiceScopeFactory serviceScopeFactory,
        ICurrentTenant currentTenant,
        IUnitOfWorkManager unitOfWorkManager,
        IOptions <AbpKafkaEventBusOptions> abpKafkaEventBusOptions,
        IKafkaMessageConsumerFactory messageConsumerFactory,
        IOptions <AbpDistributedEventBusOptions> abpDistributedEventBusOptions,
        IKafkaSerializer serializer,
        IProducerPool producerPool,
        IGuidGenerator guidGenerator,
        IClock clock,
        IEventHandlerInvoker eventHandlerInvoker)
        : base(
            serviceScopeFactory,
            currentTenant,
            unitOfWorkManager,
            abpDistributedEventBusOptions,
            guidGenerator,
            clock,
            eventHandlerInvoker)
    {
        AbpKafkaEventBusOptions = abpKafkaEventBusOptions.Value;
        MessageConsumerFactory  = messageConsumerFactory;
        Serializer   = serializer;
        ProducerPool = producerPool;

        HandlerFactories = new ConcurrentDictionary <Type, List <IEventHandlerFactory> >();
        EventTypes       = new ConcurrentDictionary <string, Type>();
    }
コード例 #3
0
        public KafkaDistributedEventBus(
            IServiceScopeFactory serviceScopeFactory,
            ICurrentTenant currentTenant,
            IUnitOfWorkManager unitOfWorkManager,
            IOptions <AbpKafkaEventBusOptions> abpKafkaEventBusOptions,
            IKafkaMessageConsumerFactory messageConsumerFactory,
            IOptions <AbpDistributedEventBusOptions> abpDistributedEventBusOptions,
            IKafkaSerializer serializer,
            IProducerPool producerPool,
            IEventErrorHandler errorHandler,
            IOptions <AbpEventBusOptions> abpEventBusOptions)
            : base(serviceScopeFactory, currentTenant, unitOfWorkManager, errorHandler)
        {
            AbpKafkaEventBusOptions       = abpKafkaEventBusOptions.Value;
            AbpDistributedEventBusOptions = abpDistributedEventBusOptions.Value;
            AbpEventBusOptions            = abpEventBusOptions.Value;
            MessageConsumerFactory        = messageConsumerFactory;
            Serializer          = serializer;
            ProducerPool        = producerPool;
            DeadLetterTopicName =
                AbpEventBusOptions.DeadLetterName ?? AbpKafkaEventBusOptions.TopicName + "_dead_letter";

            HandlerFactories = new ConcurrentDictionary <Type, List <IEventHandlerFactory> >();
            EventTypes       = new ConcurrentDictionary <string, Type>();
        }
コード例 #4
0
        public KafkaMessageConsumer(
            IConsumerPool consumerPool,
            IExceptionNotifier exceptionNotifier,
            IOptions <AbpKafkaOptions> options,
            IProducerPool producerPool)
        {
            ConsumerPool      = consumerPool;
            ExceptionNotifier = exceptionNotifier;
            ProducerPool      = producerPool;
            Options           = options.Value;
            Logger            = NullLogger <KafkaMessageConsumer> .Instance;

            Callbacks = new ConcurrentBag <Func <Message <string, byte[]>, Task> >();
        }
コード例 #5
0
        public KafkaDistributedEventBus(
            IServiceScopeFactory serviceScopeFactory,
            ICurrentTenant currentTenant,
            IOptions <AbpKafkaEventBusOptions> abpKafkaEventBusOptions,
            IKafkaMessageConsumerFactory messageConsumerFactory,
            IOptions <AbpDistributedEventBusOptions> abpDistributedEventBusOptions,
            IKafkaSerializer serializer,
            IProducerPool producerPool)
            : base(serviceScopeFactory, currentTenant)
        {
            AbpKafkaEventBusOptions       = abpKafkaEventBusOptions.Value;
            AbpDistributedEventBusOptions = abpDistributedEventBusOptions.Value;
            MessageConsumerFactory        = messageConsumerFactory;
            Serializer   = serializer;
            ProducerPool = producerPool;

            HandlerFactories = new ConcurrentDictionary <Type, List <IEventHandlerFactory> >();
            EventTypes       = new ConcurrentDictionary <string, Type>();
        }
コード例 #6
0
    public KafkaMessageConsumer(
        IConsumerPool consumerPool,
        IExceptionNotifier exceptionNotifier,
        IOptions <AbpKafkaOptions> options,
        IProducerPool producerPool,
        AbpAsyncTimer timer)
    {
        ConsumerPool      = consumerPool;
        ExceptionNotifier = exceptionNotifier;
        ProducerPool      = producerPool;
        Timer             = timer;
        Options           = options.Value;
        Logger            = NullLogger <KafkaMessageConsumer> .Instance;

        Callbacks = new ConcurrentBag <Func <Message <string, byte[]>, Task> >();

        Timer.Period     = 5000; //5 sec.
        Timer.Elapsed    = Timer_Elapsed;
        Timer.RunOnStart = true;
    }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Producer"/> class.
 /// </summary>
 /// <param name="config">The config object.</param>
 /// <param name="partitioner">The partitioner that implements <see cref="IPartitioner&lt;String&gt;" />
 /// used to supply a custom partitioning strategy based on the message key.</param>
 /// <param name="producerPool">Pool of producers, one per broker.</param>
 /// <param name="populateProducerPool">if set to <c>true</c>, producers should be populated.</param>
 /// <remarks>
 /// Should be used for testing purpose only.
 /// </remarks>
 internal Producer(ProducerConfiguration config, IPartitioner <string> partitioner, IProducerPool <Message> producerPool, bool populateProducerPool)
     : base(config, partitioner, producerPool, populateProducerPool)
 {
 }