public virtual IProducer <string, byte[]> Get(string connectionName = null) { connectionName ??= KafkaConnections.DefaultConnectionName; return(Producers.GetOrAdd( connectionName, connection => new Lazy <IProducer <string, byte[]> >(() => { var producerConfig = new ProducerConfig(Options.Connections.GetOrDefault(connection)); Options.ConfigureProducer?.Invoke(producerConfig); return new ProducerBuilder <string, byte[]>(producerConfig).Build(); })).Value); }
public virtual IProducer <string, byte[]> Get(string connectionName = null) { connectionName ??= KafkaConnections.DefaultConnectionName; return(Producers.GetOrAdd( connectionName, connection => { var config = Options.Connections.GetOrDefault(connection); Options.ConfigureProducer?.Invoke(new ProducerConfig(config)); return new ProducerBuilder <string, byte[]>(config).Build(); })); }
public virtual IProducer <string, byte[]> Get(string connectionName = null) { connectionName ??= KafkaConnections.DefaultConnectionName; return(Producers.GetOrAdd( connectionName, connection => new Lazy <IProducer <string, byte[]> >(() => { var producerConfig = new ProducerConfig(Options.Connections.GetOrDefault(connection)); Options.ConfigureProducer?.Invoke(producerConfig); if (producerConfig.TransactionalId.IsNullOrWhiteSpace()) { producerConfig.TransactionalId = Guid.NewGuid().ToString(); } var producer = new ProducerBuilder <string, byte[]>(producerConfig).Build(); producer.InitTransactions(DefaultTransactionsWaitDuration); return producer; })).Value); }