Пример #1
0
        public void TestConsumeFromLatest()
        {
            const int P = 1235;

            _client.ConsumeFromLatest(Topic, P);

            VerifyConsume(Topic, P, Offsets.Latest);
        }
Пример #2
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     _cluster.ConsumeFromLatest("twitterraw");
     _cluster.MessageReceived += record =>
     {
         _logger.LogInformation($"Recevid: {Encoding.UTF8.GetString(record.Value as byte[])}");
     };
     return(Task.CompletedTask);
 }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            var scope = scopeFactory.CreateScope();

            Models.Payment p = new Models.Payment();
            _cluster.ConsumeFromLatest("demo");
            _cluster.MessageReceived += record =>
            {
                _cluster.Produce("demo", p);
                _logger.LogInformation($"Received: {Encoding.UTF8.GetString(record.Value as byte[])}");
                var dbContext = scope.ServiceProvider.GetRequiredService <PaymentContext>();
                dbContext.Add(p);
                dbContext.SaveChanges();
            };


            //paymentContext.Payments.Add(p);
            //paymentContext.SaveChanges();

            return(Task.CompletedTask);
        }
Пример #4
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            /*
             * CancellationTokenSource cts = new CancellationTokenSource();
             * Console.CancelKeyPress += (_, e) =>
             * {
             *  e.Cancel = true;
             *  cts.Cancel();
             * };
             *
             * using (var c = new ConsumerBuilder<Ignore, string>(_config).Build())
             * {
             *  while (!cancellationToken.IsCancellationRequested)
             *  {
             *      var cr = c.Consume(cts.Token);
             *  }
             * }
             */
            _cluster.ConsumeFromLatest(topic: "demo");
            _cluster.MessageReceived += _cluster_MessageReceived;

            return(Task.CompletedTask);
        }