Пример #1
0
        public string Kafka(string message)
        {
            message = message ?? "";
            var producer = kafkaProducerFactory.Create();

            producer.Publish(message);

            return("success");
        }
Пример #2
0
        protected override async Task <bool> Publish(ProductAddedEvent domainEvent)
        {
            using (var producer = _kafkaProducerFactory.Create())
            {
                var deliveryResult = await producer.ProduceAsync("product_added", new Message <Null, string>()
                {
                    Value = JsonConvert.SerializeObject(domainEvent)
                });

                return(deliveryResult.TopicPartitionOffset.Offset.Value > 0);
            }
        }
Пример #3
0
 /// <summary>
 /// 创建客户端生产者
 /// </summary>
 /// <param name="kafkaProducerFactory"></param>
 /// <returns></returns>
 public static IKafkaClientProducer Create(this IKafkaProducerFactory kafkaProducerFactory)
 {
     return(kafkaProducerFactory.Create(Options.DefaultName));
 }
 private IAsyncCollector <KafkaEventData> BuildCollectorFromAttribute(KafkaAttribute attribute)
 {
     return(new KafkaAsyncCollector(attribute.Topic, kafkaProducerManager.Create(attribute)));
 }