Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
        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();
            }));
        }
Exemplo n.º 3
0
    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);
    }