Beispiel #1
0
        public IActionResult Publish([FromBody] PublishInput input)
        {
            Logger.LogDebug($"PublishMessageController - Publish method called with this input: {input}");
            if (input == null)
            {
                return(BadRequest(new ApiValidationError(nameof(input), ErrorKeys.ParameterNull)));
            }

            if (input.Payload == null)
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Payload), ErrorKeys.ParameterNull)));
            }

            if (string.IsNullOrWhiteSpace(input.Category))
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Category), ErrorKeys.ParameterNull)));
            }

            if (!input.ValidateTags())
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Tags), ErrorKeys.ParameterNull)));
            }

            var result = _publishMessageLogic.ProduceMessage(input);

            if (!string.IsNullOrEmpty(result.Error))
            {
                return(BadRequest(new { Message = result.Error }));
            }

            return(Ok(ApiValidationResult.Ok()));
        }
        private void MessageReceived(object sender, Message <Null, string> message)
        {
            var publishInput = JsonConvert.DeserializeObject <PublishInput>(message.Value);

            if (!publishInput.ValidateTags())
            {
                _logger.LogInformation(
                    $"KafkaInputChannelConsumer_MessageReceived: Tags don't exist. publishInput: {publishInput}");
                return;
            }

            if (string.IsNullOrWhiteSpace(publishInput.Category))
            {
                _logger.LogInformation(
                    $"KafkaInputChannelConsumer_MessageReceived: Category doesn't exist. publishInput: {publishInput}");
                return;
            }

            var result = _publishMessageLogic.ProduceMessage(publishInput);

            _logger.LogInformation(
                $"KafkaInputChannelConsumer_MessageReceived: publishMessage logic called: publishInput: {publishInput}, result: {result}");
        }