예제 #1
0
    protected override void BuildRoutingSlip(RoutingSlipBuilder builder, ConsumeContext <Request> request)
    {
        // get configs
        var settings = new Settings(_configuration);

        // Add activities
        builder.AddActivity(settings.CreateOrderActivityName, settings.CreateOrderExecuteAddress);
        builder.SetVariables(new { context.Message.OrderId, context.Message.Address, context.Message.CreatedDate, context.Message.OrderDetails });
        builder.AddActivity(settings.ReserveProductActivityName, settings.ReserveProductExecuteAddress);
        builder.SetVariables(new { context.Message.OrderDetails });
    }
        public async Task ExecuteRequest(ConsumeContext <ProcessRequest> context)
        {
            try
            {
                // podemos criar o build dependendo do tipo de context

                var builder = new RoutingSlipBuilder(NewId.NextGuid());

                builder.AddActivity(ConfigurationManager.AppSettings["CreateTaskActivityName"], new Uri(ConfigurationManager.AppSettings["CreateTaskExecuteAddress"]));
                builder.AddActivity(ConfigurationManager.AppSettings["IdentifyProductsActivityName"], new Uri(ConfigurationManager.AppSettings["IdentifyProductsExecuteAddress"]));
                builder.AddActivity(ConfigurationManager.AppSettings["SendToExternalActivityName"], new Uri(ConfigurationManager.AppSettings["SendToExternalExecuteAddress"]));

                builder.SetVariables(new
                {
                    Id     = context.Message.Id,
                    Tenant = context.Message.Tenant
                });

                var routingSlip = builder.Build();

                await context.Execute(routingSlip);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        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 async Task <Guid> Publish(Uri reqUri)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("Validate", new Uri(_activityConfig.ValidateAddress));
            builder.AddActivity("PreProcess", new Uri(_activityConfig.PreProcessAddress));
            builder.AddActivity("Retrieve", new Uri(_activityConfig.RetrieveAddress));
            builder.AddActivity("PostProcess", new Uri(_activityConfig.PostProcessAddress));
            builder.AddActivity("Consent", new Uri(_activityConfig.ConsentAddress));

            builder.SetVariables(new
            {
                RequestId = NewId.NextGuid(),
                Address   = reqUri,
            });

            var routingSlip = builder.Build();

            await _bus.Publish <RoutingSlipCreated>(new
            {
                routingSlip.TrackingNumber,
                Timestamp = routingSlip.CreateTimestamp,
            });

            await _bus.Execute(routingSlip);

            return(routingSlip.TrackingNumber);
        }
예제 #5
0
        public async Task Should_publish_the_completed_event()
        {
            Task <ConsumeContext <RoutingSlipCompleted> >         completed = SubscribeHandler <RoutingSlipCompleted>();
            Task <ConsumeContext <RoutingSlipActivityCompleted> > activity  = SubscribeHandler <RoutingSlipActivityCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext <AddressActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);

            builder.SetVariables(new
            {
                Address = new Uri("http://google.com/"),
            });

            await Bus.Execute(builder.Build());

            await completed;

            var consumeContext = await activity;

            Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult <string>("UsedAddress"));
        }
예제 #6
0
        ExecutionResult Execution <TArguments> .CompletedWithoutLog(IEnumerable <KeyValuePair <string, object> > variables)
        {
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder();

            builder.SetVariables(variables);

            return(Complete(builder.Build(), RoutingSlipBuilder.NoArguments));
        }
예제 #7
0
        ExecutionResult Execution <TArguments> .CompletedWithoutLog(object variables)
        {
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder();

            builder.SetVariables(variables);

            return(Complete(builder.Build(), RoutingSlipBuilder.NoArguments));
        }
        CompensationResult Compensation <TLog> .Compensated(IDictionary <string, object> values)
        {
            var builder = new RoutingSlipBuilder(_routingSlip.TrackingNumber, _routingSlip.Itinerary,
                                                 _routingSlip.ActivityLogs.SkipLast(), _routingSlip.Variables, _routingSlip.ActivityExceptions);

            builder.SetVariables(values);

            return(Compensated(builder.Build()));
        }
예제 #9
0
        ExecutionResult Execution <TArguments> .Completed <TLog>(TLog log, object variables)
        {
            ActivityLog        activityLog;
            RoutingSlipBuilder builder = CreateRoutingSlipBuilder(log, out activityLog);

            builder.SetVariables(variables);

            return(Complete(builder.Build(), activityLog.Results));
        }
        protected override async Task BuildRoutingSlip(RoutingSlipBuilder builder, ConsumeContext <OrderPlaced> request)
        {
            // wait for some stuff...
            await Task.Delay(1000);

            builder.SetVariables(request.Message);

            builder.AddActivity("ProcessOrder", new Uri("exchange:ProcessOrder_execute"));
            builder.AddActivity("FullfilOrder", new Uri("exchange:FullfilOrder_execute"));
        }
예제 #11
0
        public async Task Consume(ConsumeContext <ProcessOrderPayment> context)
        {
            RoutingSlipBuilder builder = new RoutingSlipBuilder(context.Message.CommandId);

            builder.AddActivity("LoyaltyPayment", new Uri("loopback://localhost/loyalty-payment-execute"), new { });

            builder.SetVariables(new { context.Message.Order });

            await context.Execute(builder.Build());
        }
        public async Task <Guid> PublishInsertCoding(Coding coding)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("Core_Coding_Insert", new Uri($"{RabbitMqConstants.RabbitMqUri}Core_Coding_Insert"));
            builder.AddActivity("Kachar_Coding_Insert", new Uri($"{RabbitMqConstants.RabbitMqUri}Kachar_Coding_Insert"));
            builder.AddActivity("Rahavard_Coding_Insert", new Uri($"{RabbitMqConstants.RabbitMqUri}Rahavard_Coding_Insert"));
            builder.SetVariables(coding);
            var routingSlip = builder.Build();
            await _bus.Execute(routingSlip);

            return(routingSlip.TrackingNumber);
        }
        public async Task Consume(ConsumeContext <OrderPizzaMessage> ctx)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.SetVariables(ctx.Message);

            builder.AddActivity("ChargePayment", new Uri("queue:ChargePayment_execute"));
            builder.AddActivity("MakePizza", new Uri("queue:MakePizza_execute"));

            var routingSlip = builder.Build();

            await ctx.Execute(routingSlip);
        }
예제 #14
0
        public ExecutionResult ReviseItinerary <TLog>(TLog log, IEnumerable <KeyValuePair <string, object> > variables,
                                                      Action <ItineraryBuilder> buildItinerary)
            where TLog : class
        {
            if (_compensationAddress == null)
            {
                throw new RoutingSlipException("The activity does not have a compensation address");
            }

            RoutingSlipBuilder builder     = CreateReviseRoutingSlipBuilder();
            ActivityLog        activityLog = builder.AddActivityLog(_activity.Name, _activityTrackingNumber,
                                                                    _compensationAddress, log);

            builder.SetVariables(variables);

            return(ReviseItinerary(builder, activityLog.Results, buildItinerary));
        }
예제 #15
0
        public async Task BookMeeting(ConsumeContext <BookMeeting> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity(_settings.FetchAvatarActivityName, _settings.FetchAvatarExecuteAddress);

            builder.SetVariables(new
            {
                context.Message.EmailAddress,
                context.Message.StartTime,
                context.Message.Duration,
                context.Message.RoomCapacity
            });

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
        protected override void Build(RoutingSlipBuilder builder)
        {
            base.Build(builder);

            builder.SetVariables(_variables);
        }
예제 #17
0
 public IRoutingSlipTransactionBuilder SetVariables(object variables)
 {
     _routingSlip.SetVariables(variables);
     return(this);
 }
예제 #18
0
        static void Main()
        {
            ConfigureLogger();

            // MassTransit to use Log4Net
            Log4NetLogger.Use();


            IBusControl busControl = CreateBus();

            busControl.StartAsync().Wait();

            string validateQueueName = ConfigurationManager.AppSettings["ValidateActivityQueue"];

            Uri validateAddress = _host.GetSendAddress(validateQueueName);

            string retrieveQueueName = ConfigurationManager.AppSettings["RetrieveActivityQueue"];

            Uri retrieveAddress = _host.GetSendAddress(retrieveQueueName);


            try
            {
                for (;;)
                {
                    Console.Write("Enter an address (quit exits): ");
                    string requestAddress = Console.ReadLine();
                    if (requestAddress == "quit")
                    {
                        break;
                    }

                    if (string.IsNullOrEmpty(requestAddress))
                    {
                        requestAddress = "http://www.microsoft.com/index.html";
                    }

                    int limit = 1;

                    if (requestAddress.All(x => char.IsDigit(x) || char.IsPunctuation(x)))
                    {
                        string[] values = requestAddress.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        requestAddress = values[0];
                        if (values.Length > 1)
                        {
                            limit = int.Parse(values[1]);
                            Console.WriteLine("Sending {0}", limit);
                        }
                    }

                    switch (requestAddress)
                    {
                    case "0":
                        requestAddress = "http://www.microsoft.com/index.html";
                        break;

                    case "1":
                        requestAddress = "http://i.imgur.com/Iroma7d.png";
                        break;

                    case "2":
                        requestAddress = "http://i.imgur.com/NK8eZUe.jpg";
                        break;
                    }

                    Uri requestUri;
                    try
                    {
                        requestUri = new Uri(requestAddress);
                    }
                    catch (UriFormatException)
                    {
                        Console.WriteLine("The URL entered is invalid: " + requestAddress);
                        continue;
                    }

                    IEnumerable <Task> tasks = Enumerable.Range(0, limit).Select(x => Task.Run(async() =>
                    {
                        var builder = new RoutingSlipBuilder(NewId.NextGuid());

                        builder.AddActivity("Validate", validateAddress);
                        builder.AddActivity("Retrieve", retrieveAddress);

                        builder.SetVariables(new
                        {
                            RequestId = NewId.NextGuid(),
                            Address   = requestUri,
                        });

                        RoutingSlip routingSlip = builder.Build();

                        await busControl.Publish <RoutingSlipCreated>(new
                        {
                            TrackingNumber = routingSlip.TrackingNumber,
                            Timestamp      = routingSlip.CreateTimestamp,
                        });

                        await busControl.Execute(routingSlip);
                    }));

                    Task.WaitAll(tasks.ToArray());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception!!! OMG!!! {0}", ex);
                Console.ReadLine();
            }
            finally
            {
                busControl.Stop();
            }
        }
예제 #19
0
        private static void Main()
        {
            var logger = new LoggerConfiguration().WriteTo.ColoredConsole().CreateLogger();

            Log.Logger = logger;

            var busControl = CreateBus();

            busControl.Start();

            var validateQueueName = ConfigurationManager.AppSettings["ValidateActivityQueue"];

            var validateAddress = _host.Settings.GetQueueAddress(validateQueueName);

            var retrieveQueueName = ConfigurationManager.AppSettings["RetrieveActivityQueue"];

            var retrieveAddress = _host.Settings.GetQueueAddress(retrieveQueueName);

            var confirmQueueName = "confirm";

            var confirmAddress = _host.Settings.GetQueueAddress(confirmQueueName);


            try
            {
                while (true)
                {
                    Console.Write("Enter seats to reserver (quit exits): ");
                    var requestAddress = Console.ReadLine();
                    if (requestAddress == "quit")
                    {
                        break;
                    }

                    int count;
                    if (!int.TryParse(requestAddress, out count))
                    {
                        Console.WriteLine("Invalid arg");
                        continue;
                    }

                    var builder = new RoutingSlipBuilder(NewId.NextGuid());

                    builder.AddActivity("Validate", validateAddress);
                    builder.AddActivity("Retrieve", retrieveAddress);
                    builder.AddActivity("Confirm", confirmAddress);

                    builder.SetVariables(new
                    {
                        RequestId   = NewId.NextGuid(),
                        GuestsCount = count
                    });

                    var routingSlip = builder.Build();

                    busControl.Publish <RoutingSlipCreated>(new
                    {
                        TrackingNumber = routingSlip.TrackingNumber,
                        Timestamp      = routingSlip.CreateTimestamp,
                    }).Wait();

                    busControl.Execute(routingSlip).Wait();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception!!! OMG!!! {0}", ex);
                Console.ReadLine();
            }
            finally
            {
                busControl.Stop();
            }
        }