Пример #1
0
        public void Listen()
        {
            var config = new Dictionary <string, object>
            {
                { "group.id", "booking_consumer" },
                { "bootstrap.servers", "localhost:9092" },
                { "enable.auto.commit", "false" }
            };

            using (var consumer = new Consumer <Null, string>(config, null, new StringDeserializer(Encoding.UTF8)))
            {
                consumer.Subscribe("timemanagement_booking");
                logger("Subscribed");

                consumer.OnMessage += (_, msg) => {
                    bookingStream.Publish(new BookingMessage {
                        Message = msg.Value
                    });
                };
                logger("OnMessage attached");

                while (true)
                {
                    consumer.Poll(100);
                }
            }
        }
 public void Listen()
 {
     while (true)
     {
         bookingStream.Publish(new BookingMessage {
             Message = DateTime.Now.ToShortTimeString()
         });
     }
 }
 public void Listen()
 {
     #region MyRegion New Style
     var config = new ConsumerConfig
     {
         GroupId          = "booking",
         BootstrapServers = "localhost:9092",
         EnableAutoCommit = false
     };
     using var consumer = new ConsumerBuilder <Ignore, string>(config).Build();
     consumer.Subscribe("booking");
     var cts = new CancellationTokenSource();
     Console.CancelKeyPress += (_, e) =>
     {
         e.Cancel = true;
         cts.Cancel();
     };
     try
     {
         while (true)
         {
             var cr = consumer.Consume(cts.Token);
             bookingStream.Publish(new Model.BookingMessage {
                 Message = cr.Message.Value
             });
         }
     }
     catch (OperationCanceledException)
     {
     }
     finally
     {
         consumer.Close();
     }
     #endregion
 }