private static Task SendToNextStep(IInvokeHandlerContext context, RoutingSlip routingSlip) { var currentStep = routingSlip.Itinerary.First(); routingSlip.Itinerary.RemoveAt(0); var result = new ProcessingStepResult { Address = currentStep.Address }; routingSlip.Log.Add(result); var nextStep = routingSlip.Itinerary.FirstOrDefault(); if (nextStep == null) { return(Task.FromResult(0)); } var json = Serializer.Serialize(routingSlip); context.Headers[RoutingSlipHeaderKey] = json; return(context.ForwardCurrentMessageTo(nextStep.Address)); }
public void SendToNextStep(RoutingSlip routingSlip) { var currentStep = routingSlip.Itinerary.First(); routingSlip.Itinerary.RemoveAt(0); var result = new ProcessingStepResult { Address = currentStep.Address, }; routingSlip.Log.Add(result); var nextStep = routingSlip.Itinerary.FirstOrDefault(); if (nextStep == null) { return; } var json = JsonConvert.SerializeObject(routingSlip); _bus.CurrentMessageContext.Headers[RoutingSlipHeaderKey] = json; _bus.ForwardCurrentMessageTo(nextStep.Address); }
public void SendToNextStep(Exception ex, RoutingSlip routingSlip) { if (ex != null) return; var currentStep = routingSlip.Itinerary.First(); routingSlip.Itinerary.RemoveAt(0); var result = new ProcessingStepResult { Address = currentStep.Address, }; routingSlip.Log.Add(result); var nextStep = routingSlip.Itinerary.FirstOrDefault(); if (nextStep == null) return; var json = JsonConvert.SerializeObject(routingSlip); _bus.CurrentMessageContext.Headers[RoutingSlipHeaderKey] = json; _bus.ForwardCurrentMessageTo(nextStep.Address); }
public static void Route(this IBus bus, object message, Guid routingSlipId, params string[] destinations) { var routingSlip = new RoutingSlip(routingSlipId, destinations); var router = new Router(bus); router.SendToFirstStep(message, routingSlip); }
public RoutingSlip CreateRoutingSlip(Guid routingSlipId, params string[] destinations) { var routingSlip = new RoutingSlip { Id = routingSlipId }; foreach (var destination in destinations) { routingSlip.Itinerary.Add(new ProcessingStep { Address = destination}); } return routingSlip; }
public void MutateIncoming(TransportMessage message) { string routingSlipJson; if (_bus.CurrentMessageContext.Headers.TryGetValue(Router.RoutingSlipHeaderKey, out routingSlipJson)) { _routingSlip = JsonConvert.DeserializeObject <RoutingSlip>(routingSlipJson); } }
public void MutateIncoming(TransportMessage message) { string routingSlipJson; if (_bus.CurrentMessageContext.Headers.TryGetValue(Router.RoutingSlipHeaderKey, out routingSlipJson)) { _routingSlip = JsonConvert.DeserializeObject<RoutingSlip>(routingSlipJson); } }
public void SendToFirstStep(object message, RoutingSlip routingSlip) { var firstRouteDefinition = routingSlip.Itinerary.First(); var json = JsonConvert.SerializeObject(routingSlip); _bus.SetMessageHeader(message, RoutingSlipHeaderKey, json); _bus.Send(firstRouteDefinition.Address, message); }
private static SendOptions BuildSendOptions(Guid routingSlipId, string[] destinations) { var routingSlip = new RoutingSlip(routingSlipId, destinations); var firstRouteDefinition = routingSlip.Itinerary.First(); var json = JsonConvert.SerializeObject(routingSlip); var options = new SendOptions(); options.SetHeader(Router.RoutingSlipHeaderKey, json); options.SetDestination(firstRouteDefinition.Address); return options; }
private static SendOptions BuildSendOptions(Guid routingSlipId, string[] destinations) { var routingSlip = new RoutingSlip(routingSlipId, destinations); var firstRouteDefinition = routingSlip.Itinerary.First(); var json = JsonConvert.SerializeObject(routingSlip); var options = new SendOptions(); options.SetHeader(Router.RoutingSlipHeaderKey, json); options.SetDestination(firstRouteDefinition.Address); return(options); }
public RoutingSlip CreateRoutingSlip(Guid routingSlipId, params string[] destinations) { var routingSlip = new RoutingSlip { Id = routingSlipId }; foreach (var destination in destinations) { routingSlip.Itinerary.Add(new ProcessingStep { Address = destination }); } return(routingSlip); }
public static async Task Route(this IBusContext bus, object message, Guid routingSlipId, params string[] destinations) { var routingSlip = new RoutingSlip(routingSlipId, destinations); var firstRouteDefinition = routingSlip.Itinerary.First(); var json = JsonConvert.SerializeObject(routingSlip); var options = new SendOptions(); options.SetHeader(Router.RoutingSlipHeaderKey, json); options.SetDestination(firstRouteDefinition.Address); await bus.Send(message, options); }
public void End(Exception ex) { if (_routingSlip == null) return; try { _router.SendToNextStep(ex, _routingSlip); } finally { _routingSlip = null; } }
public void End(Exception ex) { if (_routingSlip == null) { return; } try { _router.SendToNextStep(ex, _routingSlip); } finally { _routingSlip = null; } }
public void Should_be_able_to_serialize() { var routingSlip = new RoutingSlip(Guid.NewGuid(), "foo", "bar"); routingSlip.Log.Add(new ProcessingStepResult { Address = "baz" }); var result = Serializer.Serialize(routingSlip); var deserialized = Serializer.Deserialize<RoutingSlip>(result); deserialized.Id.ShouldEqual(routingSlip.Id); deserialized.Itinerary.Count.ShouldEqual(2); deserialized.Itinerary[0].Address.ShouldEqual("foo"); deserialized.Itinerary[1].Address.ShouldEqual("bar"); deserialized.Log.Count.ShouldEqual(1); deserialized.Log[0].Address.ShouldEqual("baz"); }
private static Task SendToNextStep(IInvokeHandlerContext context, RoutingSlip routingSlip) { routingSlip.RecordStep(); var nextStep = routingSlip.Itinerary.FirstOrDefault(); if (nextStep == null) { return(TaskExtensions.CompletedTask); } var json = Serializer.Serialize(routingSlip); context.Headers[RoutingSlipHeaderKey] = json; return(context.ForwardCurrentMessageTo(nextStep.Address)); }