Exemple #1
0
        public async Task ListenAndSaveAsync(string topic,
                                             DirectoryInfo directory,
                                             CancellationToken cancellationToken)
        {
            _logger.LogInformation("started listening for '{topic}'", topic);
            var ts           = DateTime.Now.ToString("s").Replace(":", "").Replace("-", "");
            var filepathText = Path.Combine(directory.FullName, $"{topic}-{ts}.txt");
            var filePath     = new FileInfo(filepathText);

            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    await _kafkaConsumer.ConsumeAsync(topic,
                                                      r => SaveAsync(r, filePath),
                                                      cancellationToken);
                }
                catch (TaskCanceledException) { }
                catch (Exception e)
                {
                    _logger.LogError("Error encountered while receiving posts: {error}", e.Message);
                    await Task.Delay(TimeSpan.FromSeconds(30));
                }
            }
        }
Exemple #2
0
 public async Task Listen(CancellationToken cancellationToken)
 {
     await _messageBrokerConsumer.ConsumeAsync(
         _registrationChannelName,
         ProcessRegistrationRequest,
         cancellationToken);
 }
 public Task ListenAsync(CancellationToken token)
 {
     _logger.TrackInfo("StartNewJob", "Starting listening",
                       new { channelName = _updateChannelName });
     while (true)
     {
         return(_messageBrokerConsumer.ConsumeAsync(
                    _updateChannelName,
                    ProcessJobConfigAsync,
                    token));
     }
 }