Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created March 25, 2025 19:49
Show Gist options
  • Save dcomartin/bbfe16301ddc1153bf6a09cef37eb8f6 to your computer and use it in GitHub Desktop.
Save dcomartin/bbfe16301ddc1153bf6a09cef37eb8f6 to your computer and use it in GitHub Desktop.
public class PlaceOrderHandler(ILogger<PlaceOrderHandler> logger) :
IHandleMessages<PlaceOrder>
{
public Task Handle(PlaceOrder message, IMessageHandlerContext context)
{
logger.LogInformation("Received PlaceOrder, OrderId = {message.OrderId}", message.OrderId);
// This is normally where some business logic would occur
// Uncomment to test throwing a systemic exception
//throw new Exception("BOOM");
// Uncomment to test throwing a transient exception
//if (Random.Shared.Next(0, 5) == 0)
//{
// throw new Exception("Oops");
//}
var orderPlaced = new OrderPlaced
{
OrderId = message.OrderId
};
return context.Publish(orderPlaced);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment