Beispiel #1
0
        public async Task <bool> SendMessageAsync(string topic, string message)
        {
            var config = new ProducerConfig {
                BootstrapServers = $"{Server}:{Port}"
            };

            using (var p = new ProducerBuilder <Null, string>(config).Build())
            {
                try
                {
                    var msg = new KafkaMessageModel()
                    {
                        data = message, CreateTime = Tools.Tools.GetTimeStamp()
                    };
                    var dr = await p.ProduceAsync(topic, new Message <Null, string> {
                        Value = Tools.Tools.Parse2Json(msg)
                    });
                }
                catch (ProduceException <Null, string> e)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
        public async void Post([FromBody] KafkaMessageModel model)
        {
            await _producer.ProduceAsync(model.Topic, null, model.Message);

            //var dr = producer.ProduceAsync("foo", null, RandomString(10)).Result;
            //Console.WriteLine($"Delivered '{dr.Value}' to: {dr.TopicPartitionOffset}");
        }
Beispiel #3
0
 public static MessageModel FromKafkaMessage(KafkaMessageModel kafkaMessage, ValidatorResult result) => new MessageModel()
 {
     KafkaMessage = kafkaMessage,
     FoundInKafka = kafkaMessage != null,
     Result       = result,
     Event        = new EventModel(kafkaMessage)
 };
 public EventModel(KafkaMessageModel kafkaMessage) : this(kafkaMessage?.Value)
 {
 }