private static void Main(string[] args) { var routingSlip = new RoutingSlip(new WorkItem[] { new WorkItem <ReserveCarActivity>(new WorkItemArguments { { "vehicleType", "Compact" } }), new WorkItem <ReserveHotelActivity>(new WorkItemArguments { { "roomType", "Suite" } }), new WorkItem <ReserveFlightActivity>(new WorkItemArguments { { "destination", "DUS" } }) }); // imagine these being completely separate processes with queues between them _processes = new ActivityHost[] { new ActivityHost <ReserveCarActivity>(Send), new ActivityHost <ReserveHotelActivity>(Send), new ActivityHost <ReserveFlightActivity>(Send) }; // hand off to the first address Send(routingSlip.ProgressUri, routingSlip); Console.ReadLine(); }
public override bool Compensate(WorkLog item, RoutingSlip routingSlip) { var reservationId = item.Result["reservationId"]; Console.WriteLine("Cancelled flight {0}", reservationId); return(true); }
private static void Send(Uri uri, RoutingSlip routingSlip) { // this is effectively the network dispatch foreach (var process in _processes) { if (process.AcceptMessage(uri, routingSlip)) { break; } } }
public void ProcessBackwardMessage(RoutingSlip routingSlip) { if (!routingSlip.IsInProgress) { return; } // UndoLast can put new work on the routing slip // and return false to go back on the forward // path if (routingSlip.UndoLast()) { // recursion stands for passing context via message // the routing slip can be fully serialized and passed // between systems this._send(routingSlip.CompensationUri, routingSlip); } else { this._send(routingSlip.ProgressUri, routingSlip); } }
public void ProcessForwardMessage(RoutingSlip routingSlip) { if (routingSlip.IsCompleted) { return; } // if the current step is successful, proceed // otherwise go to the Unwind path if (routingSlip.ProcessNext()) { // recursion stands for passing context via message // the routing slip can be fully serialized and passed // between systems. this._send(routingSlip.ProgressUri, routingSlip); } else { // pass message to unwind message route this._send(routingSlip.CompensationUri, routingSlip); } }
public abstract bool Compensate(WorkLog item, RoutingSlip routingSlip);
public abstract bool AcceptMessage(Uri uri, RoutingSlip routingSlip);