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 async Task Consume(ConsumeContext <IFulfillOrder> context) { _logger.LogInformation($"Fulfilled order {context.Message.OrderId}"); var builder = new RoutingSlipBuilder(NewId.NextGuid()); var order = await _orderService.GetOrderAsync(context.Message.OrderId); builder.AddActivity("SubmitOrder", QueueNames.GetActivityUri(nameof(SubmitOrderActivity))); builder.AddActivity("ReserveProducts", QueueNames.GetActivityUri(nameof(ReserveProductsActivity)), new { order.OrderItems }); builder.AddActivity("Payment", QueueNames.GetActivityUri(nameof(PaymentActivity))); builder.AddActivity("Delivery", QueueNames.GetActivityUri(nameof(DeliveryActivity))); builder.AddVariable("CorrelationId", context.Message.CorrelationId); builder.AddVariable("OrderId", context.Message.OrderId); await builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <IOrderFulfillFaultedEvent>(new { context.Message.OrderId })); await builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <IOrderFulfillCompletedEvent>(new { context.Message.OrderId })); var routingSlip = builder.Build(); await context.Execute(routingSlip).ConfigureAwait(false); }
public async Task Setup() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); var testActivity = GetActivityContext <TestActivity>(); var 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); var completed = (await _completed).Message; Assert.AreEqual(_routingSlip.TrackingNumber, completed.TrackingNumber); }
public async Task Execute(ConsumeContext <IOffice365VerifyDomainCommand> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); var command = context.Message; builder.AddActivity(Office365ServiceConstants.ActivityVerifyCustomerDomain, _activityConfigurator.GetActivityExecuteUri(context, typeof(IVerifyCustomerDomainActivity)), _activityOffice365CustomerArgumentsMapper.MapVerifyCustomerDomain(command)); builder.AddActivity(Office365ServiceConstants.ActivityCreateTempAdminUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateTempPartnerPlatformAdminUserActivity)), _activityOffice365CustomerArgumentsMapper.MapCreateTempAdminUser(command)); builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)), _activityOffice365CustomerArgumentsMapper.MapAssignUserRoles(command)); builder.AddActivity(Office365ServiceConstants.ActivityFederateCustomerDomain, _activityConfigurator.GetActivityExecuteUri(context, typeof(IFederateCustomerDomainActivity)), _activityOffice365CustomerArgumentsMapper.MapFederateCustomerDomain(command)); builder.AddActivity(Office365ServiceConstants.ActivityVerifyCustomerDomainDatabaseStatus, _activityConfigurator.GetActivityExecuteUri(context, typeof(IVerifyCustomerDomainDatabaseStatusActivity)), _activityOffice365CustomerArgumentsMapper.MapVerifyCustomerDomainDatabaseStatus(command)); builder.AddActivity(Office365ServiceConstants.ActivityFederateCustomerDomainDatabaseStatus, _activityConfigurator.GetActivityExecuteUri(context, typeof(IFederateCustomerDomainDatabaseStatusActivity)), _activityOffice365CustomerArgumentsMapper.MapFederateCustomerDomainDatabaseStatus(command)); builder.AddActivity(Office365ServiceConstants.ActivityHardDeletePartnerPlatformUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IHardDeletePartnerPlatformUserActivity)), _activityOffice365CustomerArgumentsMapper.MapDeleteTempAdminUser(command)); builder.AddVariable("domainName", context.Message.DomainName); builder.AddVariable("workflowActivityType", WorkflowActivityType.VerifyAndFederateOffice365Domain.ToString()); builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri, RoutingSlipEvents.Faulted | RoutingSlipEvents.Completed | RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.ActivityCompensated | RoutingSlipEvents.ActivityCompensationFailed); var routingSlip = builder.Build(); await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new { builder.TrackingNumber, CreateTimestamp = DateTime.UtcNow, Arguments = context.Message, WorkflowActivityType = WorkflowActivityType.VerifyAndFederateOffice365Domain.ToString() }); await context.Execute(routingSlip); }
public async Task <IActionResult> Get(string request) { if (string.IsNullOrEmpty(request)) { return(BadRequest()); } var builder = new RoutingSlipBuilder(NewId.NextGuid()); //1 //builder.AddActivity("DownloadImage", new Uri("rabbitmq://localhost/execute_downloadimage"), new //{ // ImageUri = new Uri("http://images.google.com/someImage.jpg") //}); //2 //builder.AddActivity("DownloadImage", new Uri("rabbitmq://localhost/execute_downloadimage")); //builder.AddVariable("ImageUri", "http://images.google.com/someImage.jpg"); //3: si el ProcessImage no depende del fin de DownloadImage builder.AddActivity("DownloadImage", new Uri("rabbitmq://localhost/execute_downloadimage")); builder.AddActivity("ProcessImage", new Uri("rabbitmq://localhost/execute_processimage")); builder.AddVariable("ImageUri", "http://images.google.com/someImage.jpg"); builder.AddActivity("FilterImage", new Uri("rabbitmq://localhost/execute_filterimage")); builder.AddVariable("WorkPath", "\\dfs\\work"); //Events //1 //builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.All); //2 modo flags builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted); //builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), // RoutingSlipEvents.Completed, RoutingSlipEventContents.None); //3 builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.Completed); builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.Faulted); builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.CompensationFailed); builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityCompleted); builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityFaulted); builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityCompensated); builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityCompensationFailed); // 4 custom public interface OrderProcessingCompleted //builder.AddSubscription(new Uri("rabbitmq://localhost/order-events"), // RoutingSlipEvents.Completed, // x => x.Send<OrderProcessingCompleted>(new // { // OrderId = "BFG-9000", // OrderApproval = "ComeGetSome" // })); var routingSlip = builder.Build(); await _bus.Execute(routingSlip); return(Ok(new { routingSlip.TrackingNumber })); }
public async Task Execute(ConsumeContext <IOffice365CreateCustommerCommand> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); var createOffice365CustommerCommand = context.Message; builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365PartnerPlatformCustomer, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreatePartnerPlatformCustomerActivity)), _activityOffice365CustomerArgumentsMapper.MapCreatePartnerPlatformCustomerArguments(createOffice365CustommerCommand)); builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365DatabaseCustomer, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseCustomerActivity)), _activityOffice365CustomerArgumentsMapper.MapCreateDatabaseCustomerArguments(createOffice365CustommerCommand)); builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToPartnerPortal, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainPartnerPortalActivity)), _activityOffice365CustomerArgumentsMapper.MapAddCustomerDomainPartnerPortalArguments(createOffice365CustommerCommand)); builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToDatabase, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainToDatabaseActivity)), _activityOffice365CustomerArgumentsMapper.MapAddCustomerDomainToDatabaseArguments(createOffice365CustommerCommand)); builder.AddActivity(Office365ServiceConstants.ActivityGetOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetCustomerDomainTxtRecordsActivity)), _activityOffice365CustomerArgumentsMapper.MapGetCustomerTxtRecords(createOffice365CustommerCommand)); builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendCustomerDomainTxtRecordsActivity)), _activityOffice365CustomerArgumentsMapper.MapSendCustomerTxtRecords(createOffice365CustommerCommand)); builder.AddVariable("companyId", context.Message.CompanyId); builder.AddVariable("workflowActivityType", WorkflowActivityType.Office365AddAdditionalDomain.ToString()); builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted | RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.ActivityCompensated | RoutingSlipEvents.ActivityCompensationFailed); var routingSlip = builder.Build(); await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new { builder.TrackingNumber, CreateTimestamp = DateTime.UtcNow, Arguments = context.Message, WorkflowActivityType = WorkflowActivityType.CreateOffice365Customer.ToString() }); await context.Execute(routingSlip); }
public void Setup() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); var fetchAvatarActivity = GetActivityContext <FetchAvatarActivity>(); builder.AddActivity(fetchAvatarActivity.Name, fetchAvatarActivity.ExecuteUri); builder.AddVariable("EmailAddress", "*****@*****.**"); builder.AddVariable("BookingRequestId", NewId.NextGuid()); _routingSlip = builder.Build(); Await(() => Bus.Execute(_routingSlip)); }
public async Task Should_retry_and_eventually_compensate() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); var testActivity = GetActivityContext <TestActivity>(); var faultyCompensateActivity = GetActivityContext <FirstFaultyCompensateActivity>(); var faultActivity = GetActivityContext <FaultyActivity>(); Task <ConsumeContext <RoutingSlipActivityCompensated> > compensated = ConnectPublishHandler <RoutingSlipActivityCompensated>( context => context.Message.ActivityName.Equals(faultyCompensateActivity.Name)); Task <ConsumeContext <RoutingSlipFaulted> > routingSlipFailure = ConnectPublishHandler <RoutingSlipFaulted>(x => x.Message.TrackingNumber == builder.TrackingNumber); builder.AddVariable("Value", "Hello"); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri); builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri); await Bus.Execute(builder.Build()); await routingSlipFailure; await compensated; }
public void Should_handle_the_failed_to_compensate_event() { var handledCompensationFailure = new ManualResetEvent(false); var handledRoutingSlipFailure = new ManualResetEvent(false); LocalBus.SubscribeHandler<RoutingSlipActivityCompensationFailed>(message => { handledCompensationFailure.Set(); }); LocalBus.SubscribeHandler<RoutingSlipCompensationFailed>(message => { handledRoutingSlipFailure.Set(); }); Assert.IsTrue(WaitForSubscription<RoutingSlipCompensationFailed>()); Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompensationFailed>()); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext faultyCompensateActivity = GetActivityContext<FaultyCompensateActivity>(); ActivityTestContext faultActivity = GetActivityContext<FaultyActivity>(); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddVariable("Value", "Hello"); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri); builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri); LocalBus.Execute(builder.Build()); Assert.IsTrue(handledRoutingSlipFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); Assert.IsTrue(handledCompensationFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); }
public async Task Should_handle_the_failed_to_compensate_event_via_subscription() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); Task <ConsumeContext <RoutingSlipActivityCompensationFailed> > handledCompensationFailure = SubscribeHandler <RoutingSlipActivityCompensationFailed>(x => x.Message.TrackingNumber == builder.TrackingNumber); Task <ConsumeContext <RoutingSlipCompensationFailed> > handledRoutingSlipFailure = SubscribeHandler <RoutingSlipCompensationFailed>(x => x.Message.TrackingNumber == builder.TrackingNumber); var testActivity = GetActivityContext <TestActivity>(); var faultyCompensateActivity = GetActivityContext <FaultyCompensateActivity>(); var faultActivity = GetActivityContext <FaultyActivity>(); builder.AddVariable("Value", "Hello"); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri); builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri); builder.AddSubscription( Bus.Address, RoutingSlipEvents.CompensationFailed, RoutingSlipEventContents.All); builder.AddSubscription( Bus.Address, RoutingSlipEvents.ActivityCompensationFailed, RoutingSlipEventContents.All); await Bus.Execute(builder.Build()); await handledRoutingSlipFailure; await handledCompensationFailure; }
public void Should_handle_the_failed_to_compensate_event() { var handledCompensationFailure = new ManualResetEvent(false); var handledRoutingSlipFailure = new ManualResetEvent(false); LocalBus.SubscribeHandler <RoutingSlipActivityCompensationFailed>(message => handledCompensationFailure.Set()); LocalBus.SubscribeHandler <RoutingSlipCompensationFailed>(message => handledRoutingSlipFailure.Set()); Assert.IsTrue(WaitForSubscription <RoutingSlipCompensationFailed>()); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompensationFailed>()); ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext faultyCompensateActivity = GetActivityContext <FaultyCompensateActivity>(); ActivityTestContext faultActivity = GetActivityContext <FaultyActivity>(); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddVariable("Value", "Hello"); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri); builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri); LocalBus.Execute(builder.Build()); Assert.IsTrue(handledRoutingSlipFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); Assert.IsTrue(handledCompensationFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds())); }
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 async Task Execute(FutureConsumeContext <TInput> context) { var factory = context.GetStateMachineActivityFactory(); IItineraryPlanner <TInput> itineraryPlanner = factory.GetService <IItineraryPlanner <TInput> >(context); var trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(trackingNumber); builder.AddVariable(nameof(FutureConsumeContext.FutureId), context.FutureId); builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted); await itineraryPlanner.PlanItinerary(context, builder).ConfigureAwait(false); var routingSlip = builder.Build(); await context.Execute(routingSlip).ConfigureAwait(false); if (TrackRoutingSlip) { context.Instance.Pending.Add(trackingNumber); } }
public void Setup() { _faulted = SubscribeHandler <RoutingSlipFaulted>(); _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(x => x.Message.ActivityName.Equals("Test")); _activityCompensated = SubscribeHandler <RoutingSlipActivityCompensated>(x => x.Message.ActivityName.Equals("Test")); _secondActivityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(x => x.Message.ActivityName.Equals("SecondTest")); _activityFaulted = SubscribeHandler <RoutingSlipActivityFaulted>(x => x.Message.ActivityName.Equals("Faulty")); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(Bus.Address, RoutingSlipEvents.All); 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"); Await(() => Bus.Execute(builder.Build())); }
public async Task Should_publish_the_completed_event() { _harness = new InMemoryTestHarness(); _activity = _harness.Activity <TestActivity, TestArguments, TestLog>(); await _harness.Start(); _completed = _harness.SubscribeHandler <RoutingSlipCompleted>(); _activityCompleted = _harness.SubscribeHandler <RoutingSlipActivityCompleted>(); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(_harness.BusAddress, RoutingSlipEvents.All); builder.AddActivity(_activity.Name, _activity.ExecuteAddress, new { Value = "Hello" }); builder.AddVariable("Variable", "Knife"); await _harness.Bus.Execute(builder.Build()); await _completed; }
public async Task Consume(ConsumeContext <TRequest> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted); builder.AddVariable("RequestId", context.RequestId); builder.AddVariable("ResponseAddress", context.ResponseAddress); builder.AddVariable("FaultAddress", context.FaultAddress); builder.AddVariable("Request", context.Message); await BuildRoutingSlip(builder, context); var routingSlip = builder.Build(); await context.Execute(routingSlip).ConfigureAwait(false); }
private static RoutingSlip BuildRoutingSlip(ConsumeContext <ProcessBurgerOrder> context, Guid trackingId) { var builder = new RoutingSlipBuilder(trackingId); builder.AddVariable("OrderId", context.Message.OrderId); builder.AddVariable("CorrelationId", context.CorrelationId); // minor: abstract out this var activityName = typeof(ProcessBurgerOrderActivity).Name; var queueName = $"{activityName.Replace("Activity", string.Empty)}_execute"; var executeAddress = new Uri($"queue:{queueName}"); builder.AddActivity(activityName, executeAddress); // Completed builder .AddSubscription( context.SourceAddress, RoutingSlipEvents.Completed, x => x.Send <BurgerOrderProcessed>( new { context.Message.CorrelationId, context.Message.OrderId, context.Message.OrderDate }) ); // Faulted builder .AddSubscription( context.SourceAddress, RoutingSlipEvents.ActivityFaulted, x => x.Send <BurgerOrderFaulted>( new { context.Message.CorrelationId, context.Message.OrderId, context.Message.OrderDate }) ); return(builder.Build()); }
public void Setup() { _completed = new TaskCompletionSource <RoutingSlipCompleted>(TestCancellationToken); _firstActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken); _secondActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken); LocalBus.SubscribeHandler <RoutingSlipCompleted>(x => _completed.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x => { if (x.ActivityName.Equals("Test")) { _firstActivityCompleted.SetResult(x); } if (x.ActivityName.Equals("SecondTest")) { _secondActivityCompleted.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", NullValue = (string)null, }); testActivity = GetActivityContext <SecondTestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); builder.AddVariable("Nothing", null); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
public async Task Execute(ConsumeContext <IOffice365UserChangeRolesCommand> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); var command = context.Message; builder.AddActivity(Office365ServiceConstants.ActivityGetUserRoles, _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetUserRolesActivity)), _mapper.MapGetUserRolesArguments(command)); builder.AddActivity(Office365ServiceConstants.ActivityRemoveUserRoles, _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveUserRolesActivity)), _mapper.MapRemoveUserRolesArguments(command)); builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)), _mapper.MapAssignUserRolesArguments(command)); builder.AddVariable("userPrincipalName", context.Message.UserPrincipalName); builder.AddVariable("workflowActivityType", WorkflowActivityType.Office365UserChangeRoles.ToString()); builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted | RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.ActivityCompensated | RoutingSlipEvents.ActivityCompensationFailed); var routingSlip = builder.Build(); await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new { builder.TrackingNumber, CreateTimestamp = DateTime.UtcNow, Arguments = context.Message, WorkflowActivityType = WorkflowActivityType.Office365UserChangeRoles.ToString() }); await context.Execute(routingSlip); }
public async Task A_routing_slip() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); var testActivity = GetActivityContext <TestActivity>(); var 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); }
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)); }
public async Task Execute(BehaviorContext <OrderState, SubmitOrder> context, Behavior <OrderState, SubmitOrder> next) { var consumeContext = context.GetPayload <ConsumeContext <SubmitOrder> >(); var builder = new RoutingSlipBuilder(NewId.NextGuid()); var orderId = context.Data.OrderId; builder.AddActivity("RedisStock", new Uri("queue:redis-stock_execute"), new { ProductKey = "ITEM123", Quantity = 10.0m }); builder.AddActivity("SaveOrder", new Uri("queue:save-order_execute"), new { ProductKey = "ITEM123", Quantity = 10.0m }); //builder.AddActivity("DbStock", new Uri("queue:db-stock_execute"), new //{ // ProductKey = "ITEM123", // Quantity = 10.0m //}); builder.AddVariable("OrderId", orderId); await builder.AddSubscription(new Uri("queue:saga_order_state"), RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <SubmitOrderFaulted>(new SubmitOrderFaulted { OrderId = orderId })); await builder.AddSubscription(new Uri("queue:saga_order_state"), RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <SubmitOrderCompleted>(new SubmitOrderCompleted { OrderId = orderId })); var routingSlip = builder.Build(); await consumeContext.Execute(routingSlip); await context.RespondAsync(new SubmitOrderResponse { OrderId = orderId }); await next.Execute(context); }
public void Setup() { _completed = new TaskCompletionSource<RoutingSlipCompleted>(TestCancellationToken); _firstActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>(TestCancellationToken); _secondActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>(TestCancellationToken); LocalBus.SubscribeHandler<RoutingSlipCompleted>(x => _completed.SetResult(x)); Assert.IsTrue(WaitForSubscription<RoutingSlipCompleted>()); LocalBus.SubscribeHandler<RoutingSlipActivityCompleted>(x => { if (x.ActivityName.Equals("Test")) _firstActivityCompleted.SetResult(x); if (x.ActivityName.Equals("SecondTest")) _secondActivityCompleted.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", NullValue = (string)null, }); testActivity = GetActivityContext<SecondTestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddVariable("Variable", "Knife"); builder.AddVariable("Nothing", null); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
public async Task Consume(ConsumeContext <FulfilOrder> context) { if (context.Message.CustomerNumber.StartsWith("INVALID")) { throw new InvalidOperationException("We tried, but the customer is invalid"); } // if (context.Message.CustomerNumber.StartsWith("MAYBE")) // { // if (new Random().Next(100) > 50) // throw new ApplicationException("We randomly exploded, so sad, much tear"); // } var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("AllocateInventory", new Uri("queue:allocate-inventory_execute"), new AllocateInventory { ItemNumber = "Item123", Quantity = 10.0m }); builder.AddActivity("PaymentActivity", new Uri("queue:payment_execute"), new Payment { CardNumber = context.Message.PaymentCardNumber, Amount = 99.95m }); builder.AddVariable("OrderId", context.Message.OrderId); await builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <OrderFulfillmentFaulted>(new OrderFulfillmentFaulted { OrderId = context.Message.OrderId, Timestamp = InVar.Timestamp })); await builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None, x => x.Send <OrderFulfillmentCompleted>(new OrderFulfillmentCompleted { OrderId = context.Message.OrderId, Timestamp = InVar.Timestamp })); var routingSlip = builder.Build(); await context.Execute(routingSlip); }
public async Task Consume(ConsumeContext <FulfillOrder> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("AllocateInventory", new Uri("queue:allocate-inventory_execute"), new { ItemNumber = "ITEM123", Quantity = 10.0m }); builder.AddVariable(nameof(context.Message.OrderId), context.Message.OrderId); var routingSlip = builder.Build(); await context.Execute(routingSlip); }
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 Should_work_for_activity_arguments() { _intValue = 27; _stringValue = "Hello, World."; _decimalValue = 123.45m; Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>(); Task <ConsumeContext <RoutingSlipFaulted> > faulted = SubscribeHandler <RoutingSlipFaulted>(); ActivityTestContext testActivity = GetActivityContext <ObjectGraphTestActivity>(); ActivityTestContext testActivity2 = GetActivityContext <TestActivity>(); var builder = new RoutingSlipBuilder(Guid.NewGuid()); var dictionary = new Dictionary <string, object> { { "Outer", new OuterObjectImpl(_intValue, _stringValue, _decimalValue) }, { "Names", new[] { "Albert", "Chris" } }, { "ArgumentsDictionary", _argumentsDictionary } }; builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, dictionary); builder.AddActivity(testActivity2.Name, testActivity2.ExecuteUri, new { Value = "Howdy!" }); builder.AddVariable("ArgumentsDictionary", new Dictionary <string, string> { { "good_jpath_key", "val3" }, { "bad jpath key", "val4" } }); await Bus.Execute(builder.Build()); await Task.WhenAny(completed, faulted); if (faulted.Status == TaskStatus.RanToCompletion) { Assert.Fail("Failed due to exception {0}", faulted.Result.Message.ActivityExceptions.Any() ? faulted.Result.Message.ActivityExceptions.First() .ExceptionInfo.Message : "VisitUnknownFilter"); } completed.Status.ShouldBe(TaskStatus.RanToCompletion); }
async Task Execute(FutureConsumeContext <T> consumeContext) { // this will need to be done by a consumer at some point, to handle retry/fault handling var trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(trackingNumber); builder.AddVariable(nameof(consumeContext.FutureId), consumeContext.FutureId); builder.AddSubscription(consumeContext.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted); await _planner.PlanItinerary(consumeContext.Message, builder).ConfigureAwait(false); var routingSlip = builder.Build(); await consumeContext.Execute(routingSlip).ConfigureAwait(false); }
public async Task Should_publish_the_completed_event() { _completed = SubscribeHandler <RoutingSlipCompleted>(); _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(Bus.Address, RoutingSlipEvents.ActivityCompleted, RoutingSlipEventContents.None); var testActivity = GetActivityContext <TestActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello" }); builder.AddVariable("Variable", "Knife"); await Bus.Execute(builder.Build()); }
public async Task Execute(FutureConsumeContext <TInput> context) { var trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(trackingNumber); builder.AddVariable(nameof(FutureConsumeContext.FutureId), context.FutureId); builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted); await _buildItinerary(context, builder).ConfigureAwait(false); var routingSlip = builder.Build(); await context.Execute(routingSlip).ConfigureAwait(false); if (TrackRoutingSlip) { context.Instance.Pending.Add(trackingNumber); } }
public async Task Setup() { _limit = 10; var testActivity = GetActivityContext <TestActivity>(); var secondActivity = GetActivityContext <SecondTestActivity>(); for (var i = 0; i < _limit; i++) { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Value", "Hello"); var routingSlip = builder.Build(); await Bus.Execute(routingSlip); _sentRoutingSlips.Add(routingSlip.TrackingNumber); } }
public void Setup() { _limit = 100; ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext secondActivity = GetActivityContext <SecondTestActivity>(); for (int i = 0; i < _limit; i++) { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Value", "Hello"); RoutingSlip routingSlip = builder.Build(); TaskUtil.Await(() => Bus.Execute(routingSlip)); _sentRoutingSlips.Add(routingSlip.TrackingNumber); } }
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 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)); }
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() { _limit = 100; ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); for (int i = 0; i < _limit; i++) { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Value", "Hello"); RoutingSlip routingSlip = builder.Build(); await Bus.Execute(routingSlip); _sentRoutingSlips.Add(routingSlip.TrackingNumber); } }