-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaceOrderHandler.cs
44 lines (36 loc) · 1.23 KB
/
PlaceOrderHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Threading.Tasks;
using Messages;
using NServiceBus;
using NServiceBus.Logging;
namespace Sales
{
public class PlaceOrderHandler :
IHandleMessages<PlaceOrder>
{
static readonly ILog log = LogManager.GetLogger<PlaceOrderHandler>();
static readonly Random random = new Random();
public Task Handle(PlaceOrder message, IMessageHandlerContext context)
{
log.Info($"Received PlaceOrder, OrderId = {message.OrderId}");
// This is normally where some business logic would occur
#region ThrowTransientException
// Uncomment to test throwing transient exceptions
//if (random.Next(0, 5) == 0)
//{
// throw new Exception("Oops");
//}
#endregion
#region ThrowFatalException
// Uncomment to test throwing fatal exceptions
//throw new Exception("BOOM");
#endregion
var orderPlaced = new OrderPlaced
{
OrderId = message.OrderId
};
log.Info($"Publishing OrderPlaced, OrderId = {message.OrderId}");
return context.Publish(orderPlaced);
}
}
}