Last active
May 31, 2020 22:54
-
-
Save changhuixu/49e77be917fd4ec5c41a8d44b62872fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OrdersController : ControllerBase | |
| { | |
| private readonly ILogger<OrdersController> _logger; | |
| private readonly IRabbitMQClient _rabbitMqClient; | |
| public OrdersController(ILogger<OrdersController> logger, IRabbitMQClient rabbitMqClient) | |
| { | |
| _logger = logger; | |
| _rabbitMqClient = rabbitMqClient; | |
| } | |
| // ... | |
| [HttpPost] | |
| public IActionResult Post(NewOrderRequest request) | |
| { | |
| var newOrder = new Order | |
| { | |
| //... | |
| }; | |
| Orders.Add(newOrder); | |
| var payload = JsonSerializer.Serialize(newOrder); | |
| _rabbitMqClient.Publish("ordering", "order.created", payload); | |
| return CreatedAtAction(nameof(GetById), new { id = newOrder.Id }, newOrder); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment