Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                IEventArgs workItem =
                    await _queue.DequeueAsync(stoppingToken);

                if (workItem != null)
                {
                    switch (workItem.GetType().Name)
                    {
                    case nameof(RandomEventArgs):
                        var result = await _mediator.Send(new GetRandomNumberCommand(), stoppingToken);

                        if (result.IsSuccess)
                        {
                            _logger.LogInformation($"{workItem.RequestDateTime.ToLocalTime()} : {result.Value}");
                        }
                        else
                        {
                            _logger.LogError(result.Error);
                        }
                        break;

                    default:
                        _logger.LogError($"Unhandled Event Type {workItem.GetType().Name}");
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            var queues = await _eventQueue.GetQueuesAsync();

            if (queues.Count > 0)
            {
                await queues.Select(async q =>
                {
                    var @event = await _eventQueue.DequeueAsync(q);
                    if (null != @event)
                    {
                        var handlers = _eventHandlerFactory.GetHandlers(@event.GetType());
                        if (handlers.Count > 0)
                        {
                            await handlers
                            .Select(h => h.Handle(@event))
                            .WhenAll()
                            ;
                        }
                    }
                })
                .WhenAll()
                ;
            }

            await Task.Delay(1000, stoppingToken);
        }
    }
Ejemplo n.º 3
0
        public async Task ProcessQueueAsync(
            CancellationToken cancellationToken)
        {
            _logger.LogProcessingQueue();
            var @event = await _eventQueue.DequeueAsync(cancellationToken);

            if (@event != null)
            {
                _logger.LogEventHasBeenDequeued(@event?.EventType ?? string.Empty);
                await ReactToEventAsync(@event);
            }

            _logger.LogProcessedQueue();
        }
Ejemplo n.º 4
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var options = _options.Value;

            while (!stoppingToken.IsCancellationRequested)
            {
                var item = await _eventQueue.DequeueAsync(stoppingToken);

                var applicationId = item.ApplicationId ?? options.CurrentApplicationId;
                var id            = await _identityGenerator.GenerateAsync();

                if (_memoryCache.TryGetValue(MonitorSettings.GetCacheKey(item.Level), out MonitorSettings settings))
                {
                    var connections = settings.GetConnections(applicationId);
                    if (connections.Any())
                    {
                        await _hubContext.Clients.Clients(connections.ToList()).ReceiveEvent(new EventViewModel
                        {
                            Id            = id,
                            Level         = item.Level.ToLower(),
                            Category      = item.Category,
                            Message       = item.Message,
                            ApplicationId = applicationId,
                            EventId       = item.EventId,
                            EventType     = item.EventType,
                            Timestamp     = item.Timestamp
                        });
                    }
                }

                var evt = new Event
                {
                    Id            = id,
                    GlobalId      = id,
                    ApplicationId = applicationId,
                    Category      = item.Category,
                    Level         = item.Level.ToLower(),
                    EventId       = item.EventId,
                    EventType     = item.EventType,
                    Message       = item.Message,
                    Exception     = item.Exception?.SerializeToJson(),
                    ProcessId     = item.ProcessId,
                    TimeStamp     = item.Timestamp
                };
                _storeQueue.Enqueue(evt);
            }
        }
Ejemplo n.º 5
0
 public static Task <IEventBase?> DequeueAsync(this IEventQueue eventQueue)
 {
     return(eventQueue.DequeueAsync(DefaultQueueName));
 }