コード例 #1
0
 public MessagesContainer(GRPCLogConsumer grpcLogConsumer, ILogger <MessagesContainer> logger)
 {
     _logger    = logger;
     _consumers = new List <ILogConsumer>();
     AddConsumer(grpcLogConsumer);
     AddConsumer(new AnalogyConsumer());
     messages  = new BlockingCollection <AnalogyGRPCLogMessage>();
     _consumer = Task.Factory.StartNew(async() =>
     {
         foreach (var msg in messages.GetConsumingEnumerable())
         {
             try
             {
                 await _semaphoreSlim.WaitAsync();
                 await Task.WhenAll(_consumers.Select(c => c.ConsumeLog(msg)).ToArray());
             }
             catch (Exception e)
             {
                 _logger.LogError(e, "Error publishing message");
             }
             finally
             {
                 _semaphoreSlim.Release();
             }
         }
     });
 }
コード例 #2
0
 public GreeterService(MessagesContainer messageContainer, GRPCLogConsumer grpcLogConsumer, ILogger <GreeterService> logger)
 {
     _grpcLogConsumer = grpcLogConsumer;
     Logger           = logger;
     MessageContainer = messageContainer;
 }