Skip to content

Instantly share code, notes, and snippets.

@irfan-yusanif
Created December 2, 2021 08:01
Show Gist options
  • Save irfan-yusanif/99edbdc1953a12d2518df144628b738c to your computer and use it in GitHub Desktop.
Save irfan-yusanif/99edbdc1953a12d2518df144628b738c to your computer and use it in GitHub Desktop.
Send message
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