/// <summary> /// Initializes a new instance of the <see cref="Producer<TKey, TData>"/> class. /// </summary> /// <param name="config">The config object.</param> /// <param name="partitioner">The partitioner that implements <see cref="IPartitioner<TKey>" /> /// 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)); } } }
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>(); }
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>(); }
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> >(); }
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>(); }
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; }
/// <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<String>" /> /// 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) { }