public static void RouteToLastStep(this RoutingSlip slip) { while (slip.Itinerary.Count > 2) { slip.RecordStep(); } }
public RoutingSlipEventPublisher(IBus bus, RoutingSlip routingSlip) { _sendEndpointProvider = bus; _publishEndpoint = bus; _routingSlip = routingSlip; _host = HostMetadataCache.Host; }
public async Task Should_send_to_next_destination_if_no_error() { var routingSlip = new RoutingSlip(Guid.NewGuid(), null, "foo", "bar"); var router = new Router(); var context = new TestableInvokeHandlerContext { MessageHeaders = { [Router.RoutingSlipHeaderKey] = Newtonsoft.Json.JsonConvert.SerializeObject(routingSlip) } }; await router.Invoke(context, () => Task.FromResult(0)); context.Extensions.TryGet(out routingSlip).ShouldBeTrue(); context.Headers[Router.RoutingSlipHeaderKey].ShouldNotBeNull(); routingSlip.Itinerary.Count.ShouldBe(1); routingSlip.Log.Count.ShouldBe(1); routingSlip.Log[0].Address.ShouldBe("foo"); context.ForwardedMessages.Length.ShouldBe(1); context.ForwardedMessages[0].ShouldBe("bar"); }
protected override async Task PublishActivityEvents(RoutingSlip routingSlip, RoutingSlipBuilder builder) { await base.PublishActivityEvents(routingSlip, builder); await Publisher.PublishRoutingSlipRevised(Context.ExecutionId, Context.Timestamp, Context.Elapsed, routingSlip.Variables, routingSlip.Itinerary, builder.SourceItinerary); }
public CompensatedWithVariablesCompensationResult(CompensateContext <TLog> compensateContext, IRoutingSlipEventPublisher publisher, CompensateLog compensateLog, RoutingSlip routingSlip, IDictionary <string, object> variables) : base(compensateContext, publisher, compensateLog, routingSlip) { _variables = variables; }
/// <summary> /// This is a temp workaround until I update MT /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bus"></param> /// <param name="routingSlip"></param> /// <returns></returns> public static async Task Execute <T>(this T bus, RoutingSlip routingSlip) where T : IPublishEndpoint, ISendEndpointProvider { var endpoint = await bus.GetSendEndpoint(routingSlip.GetNextExecuteAddress()); await endpoint.Send(routingSlip); }
public RoutingSlipEventPublisher(ExecuteContext executeContext, RoutingSlip routingSlip) { _sendEndpointProvider = executeContext; _publishEndpoint = executeContext; _routingSlip = routingSlip; _host = executeContext.Host; }
public RoutingSlipEventPublisher(CompensateContext compensateContext, RoutingSlip routingSlip) { _sendEndpointProvider = compensateContext; _publishEndpoint = compensateContext; _routingSlip = routingSlip; _host = compensateContext.Host; }
public RoutingSlipEventPublisher(ISendEndpointProvider sendEndpointProvider, IPublishEndpoint publishEndpoint, RoutingSlip routingSlip) { _sendEndpointProvider = sendEndpointProvider; _publishEndpoint = publishEndpoint; _routingSlip = routingSlip; _host = HostMetadataCache.Host; }
protected override async Task PublishActivityEvents(RoutingSlip routingSlip, RoutingSlipBuilder builder) { await base.PublishActivityEvents(routingSlip, builder).ConfigureAwait(false); await Publisher.PublishRoutingSlipTerminated(Context.ActivityName, Context.ExecutionId, Context.Timestamp, Context.Elapsed, routingSlip.Variables, builder.SourceItinerary).ConfigureAwait(false); }
public async Task RunAsync() { var routingSlip = new RoutingSlip <Order> { Steps = new List <Step> { new Step { Name = "new-order-step-a", Completed = false }, new Step { Name = "new-order-step-b", Completed = false }, new Step { Name = "new-order-step-c", Completed = false }, new Step { Name = "new-order-result", Completed = false }, }, Data = _order }; var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true"); var client = storageAccount.CreateCloudQueueClient(); var queue = client.GetQueueReference(routingSlip.Steps[0].Name); await queue.CreateIfNotExistsAsync(); var message = new CloudQueueMessage(null); message.SetMessageContent(JsonConvert.SerializeObject(routingSlip)); await queue.AddMessageAsync(message); }
public async Task <ActionResult> Test() { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("CreateGroup", new Uri("rabbitmq://localhost/vhost/operations.activities.accountinggroup.create_accounting_group")); builder.AddActivity("AssignOwnership", new Uri("rabbitmq://localhost/vhost/operations.activities.accountinggroup.assign_accounting_group_ownership")); builder.SetVariables(new { Id = Guid.NewGuid(), DisplayName = "Test", SaleStrategyId = Guid.Parse("{DDF6FE32-F6C7-42DA-0001-4FD368D0D8B9}"), OwnerUserId = Guid.Parse("{DDF6FE32-F6C7-42DA-0002-4FD368D0D8B9}") }); RoutingSlip routingSlip = builder.Build(); await _busControl.Publish <RoutingSlipCreated>(new { TrackingNumber = routingSlip.TrackingNumber, Timestamp = routingSlip.CreateTimestamp, }); await _busControl.Execute(routingSlip); return(new OkObjectResult(routingSlip.TrackingNumber)); }
public static void RunSagaEngineSample() { 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. s_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); }
public void Setup() { ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext secondActivity = GetActivityContext <SecondTestActivity>(); _completed = SubscribeHandler <RoutingSlipCompleted>(); _firstActivityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(testActivity.Name)); _secondActivityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(secondActivity.Name)); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", NullValue = (string)null, }); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); builder.AddVariable("Nothing", null); _routingSlip = builder.Build(); Bus.Execute(_routingSlip) .Wait(TestCancellationToken); }
public ReviseItineraryWithVariablesExecutionResult(ExecuteContext <TArguments> context, IRoutingSlipEventPublisher publisher, Activity activity, RoutingSlip routingSlip, Uri compensationAddress, TLog log, IDictionary <string, object> variables, Action <ItineraryBuilder> itineraryBuilder) : base(context, publisher, activity, routingSlip, compensationAddress, log, itineraryBuilder) { _variables = variables; }
public void Setup() { _completed = new TaskCompletionSource <RoutingSlipCompleted>(TestCancellationToken); _activityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken); LocalBus.SubscribeHandler <RoutingSlipCompleted>(x => _completed.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x => _activityCompleted.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", }); builder.AddVariable("Variable", "Knife"); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
public void Should_fail_if_not_supported() { using (var provider = new AesCryptoServiceProvider()) { provider.GenerateKey(); provider.GenerateIV(); using (ICryptoTransform encryptor = provider.CreateEncryptor()) { byte[] bytes = Encoding.UTF8.GetBytes("secret"); byte[] password = encryptor.TransformFinalBlock(bytes, 0, bytes.Length); var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("GetFile", new Uri("rabbitmq://localhost/execute_getfile"), new { Username = "******", Password = password, }); RoutingSlip routingSlip = builder.Build(); Console.WriteLine(routingSlip.ToJsonString()); } } }
public async Task Evaluate() { RoutingSlipBuilder builder = CreateRoutingSlipBuilder(_routingSlip); Build(builder); RoutingSlip routingSlip = builder.Build(); await _publisher.PublishRoutingSlipActivityCompensated(_compensateContext.ActivityName, _compensateContext.ExecutionId, _compensateContext.Timestamp, _duration, _routingSlip.Variables, _compensateLog.Data).ConfigureAwait(false); if (HasMoreCompensations(routingSlip)) { ISendEndpoint endpoint = await _compensateContext.GetSendEndpoint(routingSlip.GetNextCompensateAddress()).ConfigureAwait(false); await _compensateContext.Forward(endpoint, routingSlip).ConfigureAwait(false); } else { DateTime faultedTimestamp = _compensateContext.Timestamp + _duration; TimeSpan faultedDuration = faultedTimestamp - _routingSlip.CreateTimestamp; await _publisher.PublishRoutingSlipFaulted(faultedTimestamp, faultedDuration, _routingSlip.Variables, _routingSlip.ActivityExceptions.ToArray()).ConfigureAwait(false); } }
public ReviseItineraryExecutionResult(ExecuteContext <TArguments> context, IRoutingSlipEventPublisher publisher, Activity activity, RoutingSlip routingSlip, IDictionary <string, object> data, Action <ItineraryBuilder> itineraryBuilder) : base(context, publisher, activity, routingSlip, data) { _itineraryBuilder = itineraryBuilder; }
public ActionResult DeleteConfirmed(int id) { RoutingSlip routingslip = _db.RoutingSlips.Find(id); _db.RoutingSlips.Remove(routingslip); _db.SaveChanges(); return(RedirectToAction("Index")); }
public CompensatedCompensationResult(CompensateContext <TLog> compensateContext, IRoutingSlipEventPublisher publisher, CompensateLog compensateLog, RoutingSlip routingSlip) { _compensateContext = compensateContext; _publisher = publisher; _compensateLog = compensateLog; _routingSlip = routingSlip; _duration = _compensateContext.Elapsed; }
public RoutingSlipEventPublisher(ExecuteContext executeContext, RoutingSlip routingSlip) : this(executeContext, executeContext, routingSlip) { _sendEndpointProvider = executeContext; _publishEndpoint = executeContext; _routingSlip = routingSlip; _activityName = executeContext.ActivityName; _host = executeContext.Host; }
public RoutingSlipEventPublisher(CompensateContext compensateContext, RoutingSlip routingSlip) : this(compensateContext, compensateContext, routingSlip) { _sendEndpointProvider = compensateContext; _publishEndpoint = compensateContext; _routingSlip = routingSlip; _activityName = compensateContext.ActivityName; _host = compensateContext.Host; }
public RanToCompletionResult(IServiceBus bus, RoutingSlip routingSlip, string activityName, Guid activityTrackingNumber, IDictionary <string, object> results, IDictionary <string, object> arguments) { _timestamp = DateTime.UtcNow; _routingSlip = routingSlip; _activityName = activityName; _activityTrackingNumber = activityTrackingNumber; _results = results; _arguments = arguments; _bus = bus; }
public ActionResult Edit(RoutingSlip routingslip) { if (ModelState.IsValid) { _db.Entry(routingslip).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index", new { id = routingslip.RoutingSlipID })); } return(View(routingslip)); }
public RanToCompletionResult(IServiceBus bus, RoutingSlip routingSlip, string activityName, Guid activityTrackingNumber, IDictionary<string, object> results) { _timestamp = DateTime.UtcNow; _routingSlip = routingSlip; _activityName = activityName; _activityTrackingNumber = activityTrackingNumber; _results = results; _bus = bus; }
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 NextActivityResult(IConsumeContext context, RoutingSlip routingSlip, string activityName, Guid activityTrackingNumber, IDictionary<string, object> results) { _timestamp = DateTime.UtcNow; _context = context; _routingSlip = routingSlip; _activityName = activityName; _activityTrackingNumber = activityTrackingNumber; _results = results; _bus = context.Bus; }
public static async Task Run( [QueueTrigger("new-order-result", Connection = "QueueStorage")] RoutingSlip <Order> routingSlip, [Queue("new-order-result", Connection = "QueueStorage")] CloudQueue queue, ILogger log) { int index = await RoutingSlipProcessor.Process(routingSlip, queue); log.LogInformation($"C# Queue trigger function processed: {routingSlip.Steps[index].Name}"); }
private static void Send(Uri?uri, RoutingSlip routingSlip) { // This is effectively the network dispatch. foreach (ActivityHost process in s_processes) { if (process.AcceptMessage(uri, routingSlip)) { break; } } }
public static void Execute(this IServiceBus bus, RoutingSlip routingSlip) { if (routingSlip.RanToCompletion()) bus.Publish(new RoutingSlipCompletedMessage(routingSlip.TrackingNumber, routingSlip.Variables)); else { IEndpoint endpoint = bus.GetEndpoint(routingSlip.GetNextExecuteAddress()); endpoint.Send(routingSlip, x => x.SetSourceAddress(bus.Endpoint.Address.Uri)); } }
public void Should_build_routing_slip() { var routingSlipId = Guid.NewGuid(); var routingSlip = new RoutingSlip(routingSlipId, null, "foo"); routingSlip.ShouldNotBeNull(); routingSlip.Id.ShouldBe(routingSlipId); routingSlip.Itinerary.Count().ShouldBe(1); routingSlip.Itinerary.First().Address.ShouldBe("foo"); }
public FailedCompensationResult(CompensateContext <TLog> compensateContext, IRoutingSlipEventPublisher publisher, CompensateLog compensateLog, RoutingSlip routingSlip, Exception exception) { _compensateContext = compensateContext; _publisher = publisher; _compensateLog = compensateLog; _routingSlip = routingSlip; _exception = exception; _duration = _compensateContext.ElapsedTime; }
protected CompletedExecutionResult(ExecuteContext <TArguments> context, IRoutingSlipEventPublisher publisher, Activity activity, RoutingSlip routingSlip, IDictionary <string, object> data) { _context = context; _publisher = publisher; _activity = activity; _routingSlip = routingSlip; _data = data; _duration = _context.Elapsed; }
public CompensateResult(IConsumeContext context, RoutingSlip routingSlip, Activity activity, Guid activityTrackingNumber, Exception exception) { _timestamp = DateTime.UtcNow; _context = context; _bus = context.Bus; _routingSlip = routingSlip; _activity = activity; _exception = exception; _activityTrackingNumber = activityTrackingNumber; }
public RoutingSlipBuilder(RoutingSlip routingSlip, IEnumerable<CompensateLog> compensateLogs) { _trackingNumber = routingSlip.TrackingNumber; _createTimestamp = routingSlip.CreateTimestamp; _itinerary = new List<Activity>(routingSlip.Itinerary); _activityLogs = new List<ActivityLog>(routingSlip.ActivityLogs); _compensateLogs = new List<CompensateLog>(compensateLogs); _activityExceptions = new List<ActivityException>(routingSlip.ActivityExceptions); _variables = new Dictionary<string, object>(routingSlip.Variables); _subscriptions = new List<Subscription>(routingSlip.Subscriptions); _sourceItinerary = new List<Activity>(); }
public RoutingSlipBuilder(RoutingSlip routingSlip, IEnumerable<Activity> itinerary, IEnumerable<Activity> sourceItinerary) { _trackingNumber = routingSlip.TrackingNumber; _createTimestamp = routingSlip.CreateTimestamp; _itinerary = new List<Activity>(itinerary); _activityLogs = new List<ActivityLog>(routingSlip.ActivityLogs); _compensateLogs = new List<CompensateLog>(routingSlip.CompensateLogs); _activityExceptions = new List<ActivityException>(routingSlip.ActivityExceptions); _variables = new Dictionary<string, object>(routingSlip.Variables, StringComparer.InvariantCultureIgnoreCase); _subscriptions = new List<Subscription>(routingSlip.Subscriptions); _sourceItinerary = new List<Activity>(sourceItinerary); }
public SanitizedRoutingSlip(RoutingSlip routingSlip) { TrackingNumber = routingSlip.TrackingNumber; if (routingSlip.Itinerary == null) Itinerary = new List<Activity>(); else Itinerary = routingSlip.Itinerary.Select(x => (Activity)new SanitizedActivity(x)).ToList(); if (routingSlip.ActivityLogs == null) ActivityLogs = new List<ActivityLog>(); else ActivityLogs = routingSlip.ActivityLogs.Select(x => (ActivityLog)new SanitizedActivityLog(x)).ToList(); Variables = routingSlip.Variables ?? new Dictionary<string, string>(); }
public static async Task Execute(this IBus bus, RoutingSlip routingSlip) { if (routingSlip.RanToCompletion()) { DateTime timestamp = DateTime.UtcNow; TimeSpan duration = timestamp - routingSlip.CreateTimestamp; IRoutingSlipEventPublisher publisher = new RoutingSlipEventPublisher(bus, routingSlip); await publisher.PublishRoutingSlipCompleted(timestamp, duration, routingSlip.Variables); } else { ISendEndpoint endpoint = await bus.GetSendEndpoint(routingSlip.GetNextExecuteAddress()); await endpoint.Send(routingSlip, Pipe.New<SendContext>(x => x.UseExecute(context => context.SourceAddress = bus.Address))); } }
public void Setup() { _faulted = new TaskCompletionSource<RoutingSlipFaulted>(TestCancellationToken); _firstActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>(TestCancellationToken); _firstActivityCompensated = new TaskCompletionSource<RoutingSlipActivityCompensated>(TestCancellationToken); LocalBus.SubscribeHandler<RoutingSlipFaulted>(x => _faulted.SetResult(x)); Assert.IsTrue(WaitForSubscription<RoutingSlipFaulted>()); LocalBus.SubscribeHandler<RoutingSlipActivityCompleted>(x => { if (x.ActivityName.Equals("Test")) _firstActivityCompleted.SetResult(x); }); Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompleted>()); LocalBus.SubscribeHandler<RoutingSlipActivityCompensated>(x => { if (x.ActivityName.Equals("Test")) _firstActivityCompensated.SetResult(x); }); Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompensated>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", }); testActivity = GetActivityContext<SecondTestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); testActivity = GetActivityContext<FaultyActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
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.WriteLine("Press any key the stop this program..."); Console.ReadLine(); }
public async Task Setup() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", NullValue = (string)null, }); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); builder.AddVariable("Nothing", null); _routingSlip = builder.Build(); await Bus.Execute(_routingSlip); Console.WriteLine("Routing slip executed"); }
public async Task Setup() { ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); _completed = SubscribeHandler<RoutingSlipCompleted>(); _firstActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(testActivity.Name)); _secondActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(secondActivity.Name)); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", NullValue = (string)null, }); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); builder.AddVariable("Nothing", null); builder.AddVariable("ToBeRemoved", "Existing"); _routingSlip = builder.Build(); await Bus.Execute(_routingSlip); }
public void Setup() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello", NullValue = (string)null, }); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); builder.AddVariable("Nothing", null); _routingSlip = builder.Build(); Await(() => Bus.Execute(_routingSlip)); }