public async Task <IActionResult> KafkaTestMessage([FromBody] SendMessageModel messageModel)
        {
            _logger.Info($"{"MessageController:",-20} >>> {"KafkaTestMessage",-20} >>> {"Input Message:",-10} {JsonConvert.SerializeObject(messageModel)}.");
            var message = JsonConvert.SerializeObject(messageModel);

            var result = await _producer.Produce(new Message <Null, string> {
                Value = message
            });

            _logger.Debug($"Message: {JsonConvert.SerializeObject(result),20} >>> {"Result",10}{JsonConvert.SerializeObject(result), 20}");
            return(Ok(result));
        }
Beispiel #2
0
        public async Task <IActionResult> AddMessage(PostCreateRequest message)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var result = new PostCreateResponse {
                Succeeded = true
            };

            var user = _aspNetUser.GetUserEmail();

            var post = new Post(message.Message, user);

            if (!post.IsCommand())
            {
                var response = await _postService.PostMessage(post);

                if (!response.Succeeded)
                {
                    foreach (var error in response.ResponseResult.Errors.Messages)
                    {
                        AddOperationError(error);
                    }
                }
                result = response;
            }

            var posts = await _postService.GetPosts();

            await _hub.Clients.All.SendAsync("ReceiveMessage", posts);

            if (post.IsCommand())
            {
                _producerService.Produce(post).ConfigureAwait(false);
            }

            return(CustomResponse(result));
        }
 public async Task ProduceMessage(string message)
 {
     await _producer.Produce(new Message <Null, string> {
         Value = message
     });
 }