コード例 #1
0
        public async Task <IActionResult> CreateTodo(string todoDescription)
        {
            Devon4NetLogger.Debug("Executing CreateTodo from controller RabbitMqController");

            if (RabbitMqOptions?.Hosts == null || !RabbitMqOptions.Hosts.Any())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "No RabbitMq instance set up"));
            }

            if (string.IsNullOrEmpty(todoDescription))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Please provide a valid description for the TO-DO"));
            }

            var todoCommand = new TodoCommand {
                Description = todoDescription
            };
            var published = await TodoRabbitMqHandler.Publish(todoCommand).ConfigureAwait(false);

            return(Ok(published));
        }
コード例 #2
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="todoRabbitMqHandler">The main handler injected via DI</param>
 /// <param name="rabbitMqOptions">The RabbitMq options to check if there is any instance set up</param>
 public RabbitMqController(TodoRabbitMqHandler todoRabbitMqHandler, IOptions <RabbitMqOptions> rabbitMqOptions)
 {
     TodoRabbitMqHandler = todoRabbitMqHandler;
     RabbitMqOptions     = rabbitMqOptions?.Value;
 }