Created
December 2, 2021 08:01
-
-
Save irfan-yusanif/99edbdc1953a12d2518df144628b738c to your computer and use it in GitHub Desktop.
Send message
This file contains 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 HomeController : Controller | |
{ | |
static int messagesSent; | |
private readonly ILogger<HomeController> _log; | |
private readonly IMessageSession _messageSession; | |
public HomeController(IMessageSession messageSession, ILogger<HomeController> logger) | |
{ | |
_messageSession = messageSession; | |
_log = logger; | |
} | |
[HttpPost] | |
public async Task<ActionResult> PlaceOrder() | |
{ | |
string orderId = Guid.NewGuid().ToString().Substring(0, 8); | |
var command = new PlaceOrder { OrderId = orderId }; | |
// Send the command | |
await _messageSession.Send(command) | |
.ConfigureAwait(false); | |
_log.LogInformation($"Sending PlaceOrder, OrderId = {orderId}"); | |
dynamic model = new ExpandoObject(); | |
model.OrderId = orderId; | |
model.MessagesSent = Interlocked.Increment(ref messagesSent); | |
return View(model); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment