コード例 #1
0
        public static IServiceCollectionConfigurator ConfigureBus(this IServiceCollectionConfigurator configurator)
        {
            configurator.AddBus(context =>
                                Bus.Factory.CreateUsingRabbitMq(
                                    busFactoryConfigurator =>
            {
                var host = busFactoryConfigurator.Host("localhost", "sample.api");

                // // we could set a consumer here by using ReceiveEndpoint,
                // // or use the extension method of AddConsumer* on IServiceCollectionConfigurator
                // // it is also possible to configure endpoint by xDefinitions, e.g. SagaDefinition<T>
                // // NOT adding a receive endpoint name, publishes the message to all Consumer instances
                // // Broadcasting Pub/Sub, not Competitive Consumer, the latter will be available if
                // // Receive endpoint has a name
                // busFactoryConfigurator.ReceiveEndpoint(host, e =>
                // {
                //     e.UseRetry(r=>r.Exponential(3,TimeSpan.FromMilliseconds(300),TimeSpan.FromMilliseconds(2000),
                //         TimeSpan.FromMilliseconds(100)));
                //     e.UseInMemoryOutbox();
                //     e.Consumer(
                //         () => new SubmitOrderConsumer(context.Container.GetService<ILogger<SubmitOrderConsumer>>()));
                // });

                // creates queues, sagas and etc.
                busFactoryConfigurator.ConfigureEndpoints(context);

                // busFactoryConfigurator.ReceiveEndpoint(
                //     KebabCaseEndpointNameFormatter.Instance.Consumer<RoutingSlipCompletedBatchConsumer>(),
                //     endpoint =>
                //     {
                //         // this should be at least the number of MessageLimit,
                //         // otherwise we always get a time limit
                //         endpoint.PrefetchCount = 20;
                //
                //         endpoint.Batch<RoutingSlipCompleted>(b =>
                //         {
                //             b.MessageLimit = 10;
                //             b.TimeLimit = TimeSpan.FromSeconds(5);
                //
                //             b.Consumer<RoutingSlipCompletedBatchConsumer, RoutingSlipCompleted>(
                //                 context.Container);
                //         });
                //     });
            }));


            return(configurator);
        }
コード例 #2
0
 private void ConfigureBus(IServiceCollectionConfigurator configurator)
 {
     configurator.AddConsumer <ProductAddedToOrderConsumer>();
     configurator.AddConsumer <ProductQuantityChangedConsumer>();
     configurator.AddConsumer <CommandErrorConsumer>();
     configurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
     {
         var busConfig = Configuration.GetSection("Bus");
         var host      = cfg.ConfigureHost(busConfig);
         cfg.ReceiveEndpoint(host, "UISubscriptions", e =>
         {
             e.ConfigureConsumer <ProductAddedToOrderConsumer>(provider);
             e.ConfigureConsumer <ProductQuantityChangedConsumer>(provider);
             e.ConfigureConsumer <CommandErrorConsumer>(provider);
         });
     }));
 }
コード例 #3
0
        public static IServiceCollectionConfigurator ConfigureBus(this IServiceCollectionConfigurator configurator)
        {
            configurator.AddBus(context =>
                                Bus.Factory.CreateUsingRabbitMq(
                                    busFactoryConfigurator =>
            {
                var host = busFactoryConfigurator.Host("localhost", "sample.api");

                // when using scheduler this line should be added
                busFactoryConfigurator.UseMessageScheduler(new Uri("queue:quartz-scheduler"));

                busFactoryConfigurator.ConfigureEndpoints(context);
            }));


            return(configurator);
        }
コード例 #4
0
        private void ConfigureBus(IServiceCollectionConfigurator configurator)
        {
            configurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                var busConfig = Configuration.GetSection("Bus");
                var host      = cfg.ConfigureHost(busConfig);
                cfg.ConfigureSend(sendPipe =>
                {
                    sendPipe.UseSendFilter(new OperationContextEstablisher());
                });

                EndpointConvention.Map <AddProductToOrder>(new Uri(new Uri(busConfig["Host"]), nameof(AddProductToOrder)));
                EndpointConvention.Map <CancelOrder>(new Uri(new Uri(busConfig["Host"]), nameof(CancelOrder)));
                EndpointConvention.Map <PlaceOrder>(new Uri(new Uri(busConfig["Host"]), nameof(PlaceOrder)));
                EndpointConvention.Map <RemoveProduct>(new Uri(new Uri(busConfig["Host"]), nameof(RemoveProduct)));
                EndpointConvention.Map <SetProductQuantity>(new Uri(new Uri(busConfig["Host"]), nameof(SetProductQuantity)));

                EndpointConvention.Map <StartDelivery>(new Uri(new Uri(busConfig["Host"]), nameof(StartDelivery)));
                EndpointConvention.Map <ReturnOrder>(new Uri(new Uri(busConfig["Host"]), nameof(ReturnOrder)));
                EndpointConvention.Map <DeliverOrder>(new Uri(new Uri(busConfig["Host"]), nameof(DeliverOrder)));
            }));
        }