Пример #1
0
        private static ProducerSyncSender <TKey, TValue> GetResendProducerSender <TKey, TValue>(ConsumerConnectionBuilder <TKey, TValue> cb, IServiceBusLogger logger)
        {
            // Cria o produtor com o mesmo endereço do consumidor (isso pode melhorar)
            var produtorBuilder = new ProducerConnectionBuilder <TKey, TValue>(cb.CaPath);
            var producer        = produtorBuilder
                                  .WithBootstrapServers(cb.GetConsumerConfig().BootstrapServers)
                                  .WithAsyncProducer()
                                  .WithJsonSerializer()
                                  .Build();

            var producerSender = new ProducerSyncSender <TKey, TValue>(producer, new NullProducerClient <TKey, TValue>(logger), logger);

            return(producerSender);
        }
Пример #2
0
        public async void Send(
            [FromBody] PublisherRequest request,
            [FromServices] IServiceBusLogger logger
            )
        {
            // Set message properties
            request.Message.Id       = Guid.NewGuid();
            request.Message.SendDate = DateTime.Now;

            // Create producer
            var builder  = new ProducerConnectionBuilder <Guid, EventMessage>(request.Settings.IgnoreSsl ? null :this._appConfiguration.Kafka.CertificatePath);
            var producer = builder
                           .WithBootstrapServers(request.Settings.BootstrapServers)
                           .WithAsyncProducer()
                           .WithJsonSerializer()
                           .Build();
            var producerSender = new ProducerAsyncSender <Guid, EventMessage>(
                producer,
                null,
                logger
                );

            await producerSender.SendAsync(request.Message.Id, request.Message, request.Settings.Topic);
        }