コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 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;
 }
コード例 #6
0
        public void MutateIncoming(TransportMessage message)
        {
            string routingSlipJson;

            if (_bus.CurrentMessageContext.Headers.TryGetValue(Router.RoutingSlipHeaderKey, out routingSlipJson))
            {
                _routingSlip = JsonConvert.DeserializeObject <RoutingSlip>(routingSlipJson);
            }
        }
コード例 #7
0
        public void MutateIncoming(TransportMessage message)
        {
            string routingSlipJson;

            if (_bus.CurrentMessageContext.Headers.TryGetValue(Router.RoutingSlipHeaderKey, out routingSlipJson))
            {
                _routingSlip = JsonConvert.DeserializeObject<RoutingSlip>(routingSlipJson);
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #14
0
        public void End(Exception ex)
        {
            if (_routingSlip == null)
                return;

            try
            {
                _router.SendToNextStep(ex, _routingSlip);
            }
            finally
            {
                _routingSlip = null;
            }
        }
コード例 #15
0
        public void End(Exception ex)
        {
            if (_routingSlip == null)
            {
                return;
            }

            try
            {
                _router.SendToNextStep(ex, _routingSlip);
            }
            finally
            {
                _routingSlip = null;
            }
        }
コード例 #16
0
        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");
        }
コード例 #17
0
        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));
        }