예제 #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (!await _queue.Ensure(stoppingToken).ConfigureAwait(false))
            {
                _logger.LogError("Couldn't ensure that Queue is there.");
                return;
            }

            if (!await _database.Verify(stoppingToken).ConfigureAwait(true))
            {
                _logger.LogError("Couldn't verify database connection.");
                return;
            }

            while (!stoppingToken.IsCancellationRequested)
            {
                var changes = _database.GetChanges(stoppingToken).ConfigureAwait(false);

                await foreach (var change in changes.WithCancellation(stoppingToken))
                {
                    _logger.LogInformation("Create Message for Entity ID: {entityId} Mutation ID {mutationId}", change.EntityId, change.MutationId);
                    await _queue.AddMessage(change, stoppingToken).ConfigureAwait(false);
                }

                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                await Task.Delay(500, stoppingToken).ConfigureAwait(false);
            }
        }
예제 #2
0
        public async Task <ActionResult> Add(MessageDto message)
        {
            Message mm = new Message()
            {
                Id          = Guid.NewGuid(),
                Type        = message.Type,
                Handled     = false,
                JsonContent = message.JsonContent,
                AddAt       = DateTime.Now
            };

            if (await _queueRepository.AddMessage(mm))
            {
                return(OK("A new message was added successfully"));
            }
            return(BadRequest("Added wrong way"));
        }
예제 #3
0
        public async Task <ActionResult> Add(MessageDTO message)
        {
            Message mes = new Message()
            {
                Id          = Guid.NewGuid(),
                Type        = message.Type,
                Handled     = false,
                JsonContent = message.JsonContent,
                AddedAt     = DateTime.Now
            };

            if (await _repository.AddMessage(mes))
            {
                return(Ok("A new message was added succesfully!"));
            }
            return(BadRequest("Error"));
        }
예제 #4
0
        public async Task <ActionResult> Add(MessageDTO msg)
        {
            Message m = new Message()
            {
                Id          = Guid.NewGuid(),
                Type        = msg.Type,
                Handled     = false,
                JsonContent = msg.JsonContent,
                AddTime     = DateTime.Now
            };

            if (await _queueRepository.AddMessage(m))
            {
                return(Ok("New message added"));
            }

            return(BadRequest("ERROR!"));
        }
예제 #5
0
        public async Task <IActionResult> AddMessage(MessageDTO message)
        {
            Message msg = new Message()
            {
                Id          = Guid.NewGuid(),
                Type        = message.Type,
                Handled     = false,
                JsonContent = message.JsonContent,
                AddedAt     = DateTime.Now
            };

            if (await _queueRepository.AddMessage(msg))
            {
                return(Ok("A new message was added successfully!"));
            }

            return(BadRequest("Oops, something went wrong!"));
        }