示例#1
0
        static async Task Main(string[] args)
        {
            Register();
            var bootstrapper = new BusBootstrapper(_serviceCollection, "saga-101_checkout", c =>
            {
                c.Consumer <CreatePendingCheckoutCommandHandler>();
                //c.Consumer(()=> new CreatePendingCheckoutCommandHandler());
            });

            await bootstrapper.Start();

            var bus    = bootstrapper.GetBus();
            var sender = await bus.GetSendEndpoint(new Uri("rabbitmq://localhost/saga-101_checkout"));

            await sender.Send <CreatePendingCheckoutCommand>(new CreatePendingCheckoutCommand
            {
                CorrelationId = Guid.NewGuid(),
                CheckoutId    = Guid.NewGuid(),
                Amount        = 250,
                ProductId     = Guid.NewGuid(),
                CheckoutBy    = Guid.NewGuid()
            });

            Console.WriteLine("Hello World!");
        }
示例#2
0
        public void TestFixtureSetUp()
        {
            _container = new WindsorContainer();
            _container.Kernel.ComponentRegistered += Kernel_ComponentRegistered;
            String connectionString = ConfigurationManager.ConnectionStrings["log"].ConnectionString;
            var rebusUrl = new MongoUrl(connectionString);
            var rebusClient = rebusUrl.CreateClient(false);
            var rebusDb = rebusClient.GetDatabase(rebusUrl.DatabaseName);
            _messages = rebusDb.GetCollection<TrackedMessageModel>("messages");
            MongoDbMessagesTracker tracker = new MongoDbMessagesTracker(rebusDb);

            JarvisRebusConfiguration configuration = new JarvisRebusConfiguration(connectionString, "test")
            {
                ErrorQueue = "jarvistest-errors",
                InputQueue = "jarvistest-input",
                MaxRetry = 3,
                NumOfWorkers = 1,
                EndpointsMap = new System.Collections.Generic.Dictionary<string, string>()
                {
                    { "Jarvis.Framework.Tests" , "jarvistest-input"}
                }
            };

            configuration.AssembliesWithMessages = new List<System.Reflection.Assembly>()
            {
                typeof(SampleMessage).Assembly,
            };
            BusBootstrapper bb = CreateBusBootstrapper(tracker, configuration);

            TestHelper.RegisterSerializerForFlatId<SampleAggregateId>();

            bb.Start();
            var rebusConfigurer = _container.Resolve<RebusConfigurer>();
            rebusConfigurer.Start();
            _bus = _container.Resolve<IBus>();

            _handler = new SampleCommandHandler();
            _commandExecutionExceptionHelper = new JarvisDefaultCommandExecutionExceptionHelper(NullLogger.Instance, 20, 10);
            var handlerAdapter = new MessageHandlerToCommandHandlerAdapter<SampleTestCommand>(_handler, _commandExecutionExceptionHelper, tracker, _bus);

            _container.Register(
                Component
                    .For<IHandleMessages<SampleTestCommand>>()
                    .Instance(handlerAdapter)
            );

            var handlerAggregateAdapter = new MessageHandlerToCommandHandlerAdapter<SampleAggregateTestCommand>(_handler, _commandExecutionExceptionHelper, tracker, _bus);

            _container.Register(
                Component
                    .For<IHandleMessages<SampleAggregateTestCommand>>()
                    .Instance(handlerAggregateAdapter)
            );
        }
        public void TestFixtureSetUp()
        {
            _container = new WindsorContainer();
            
            String connectionString = ConfigurationManager.ConnectionStrings["log"].ConnectionString;
            var rebusUrl = new MongoUrl(connectionString);
            var rebusClient = new MongoClient(rebusUrl);
            var rebusDb = rebusClient.GetDatabase(rebusUrl.DatabaseName);
            _messages = rebusDb.GetCollection<TrackedMessageModel>("messages");
            MongoDbMessagesTracker tracker = new MongoDbMessagesTracker(rebusDb);
            BusBootstrapper bb = new BusBootstrapper(
                _container,
                connectionString,
                "test",
                tracker);
            JarvisRebusConfiguration configuration = new JarvisRebusConfiguration()
            {
                ErrorQueue = "jarvistest-errors",
                InputQueue = "jarvistest-input",
                MaxRetry = 3,
                NumOfWorkers = 1,
                EndpointsMap = new System.Collections.Generic.Dictionary<string, string>()
                {
                    { "Jarvis.Framework.Tests" , "jarvistest-input"}
                }
            };
            bb.Configuration = configuration;
            bb.Start();
            var startableBus = _container.Resolve<IStartableBus>();
            startableBus.Start();
            _bus = _container.Resolve<IBus>();
            
            _handler = new SampleCommandHandler();
            _handlerAdapter = new MessageHandlerToCommandHandlerAdapter<SampleTestCommand>(
                _handler, tracker, _bus);

            _container.Register(
                Component
                    .For<IHandleMessages<SampleTestCommand>>()
                    .Instance(_handlerAdapter)
            );
        }
            public TestProcess(Boolean useJarvisConfiguration, String connectionString, String inputQueue, Dictionary <String, String> mapping)
            {
                _container = new WindsorContainer();
                NullMessageTracker tracker = new NullMessageTracker();

                MongoUrlBuilder mb = new MongoUrlBuilder(connectionString);

                mb.DatabaseName = inputQueue;

                JarvisRebusConfiguration configuration = new JarvisRebusConfiguration(mb.ToString(), "test")
                {
                    ErrorQueue   = "jarvistest-errors",
                    InputQueue   = inputQueue,                   //we listen on input1
                    MaxRetry     = 3,
                    NumOfWorkers = 1,
                    EndpointsMap = mapping,
                };

                configuration.CentralizedConfiguration = true;

                configuration.AssembliesWithMessages = new List <System.Reflection.Assembly>()
                {
                    typeof(SampleMessage).Assembly,
                };

                if (useJarvisConfiguration)
                {
                    _busBootstrapper = new JarvisTestBusBootstrapper(
                        _container,
                        configuration,
                        tracker);

                    _busBootstrapper.Start();
                    var rebusConfigurer = _container.Resolve <RebusConfigurer>();
                    rebusConfigurer.Start();
                    _bus = _container.Resolve <IBus>();
                }
                else
                {
                    var mongoUrl       = new MongoUrl(connectionString);
                    var mongoClient    = new MongoClient(mongoUrl);
                    var _mongoDatabase = mongoClient.GetDatabase(mongoUrl.DatabaseName);

                    var busConfiguration = global::Rebus.Config.Configure.With(new CastleWindsorContainerAdapter(_container))
                                           .Logging(l => l.ColoredConsole())
                                           .Serialization(c => c.UseNewtonsoftJson(BusBootstrapper.JsonSerializerSettingsForRebus))
                                           .Timeouts(t => t.StoreInMongoDb(_mongoDatabase, configuration.Prefix + "-timeouts"))
                                           .Subscriptions(s => s.StoreInMongoDb(_mongoDatabase, configuration.Prefix + "-subscriptions", isCentralized: true))
                                           .Events(e => e.BeforeMessageSent += BeforeMessageSent);

                    busConfiguration = busConfiguration
                                       .Transport(t => t.UseMsmq(configuration.InputQueue))
                                       .Options(o => o.SimpleRetryStrategy(
                                                    errorQueueAddress: configuration.ErrorQueue,
                                                    maxDeliveryAttempts: configuration.MaxRetry
                                                    )).Options(o => o.SetNumberOfWorkers(configuration.NumOfWorkers))
                                       .Routing(r => r.TypeBased().MapAssemblyOf <AnotherSampleMessage>(mapping.First().Value))
                    ;

                    _bus = busConfiguration.Start();
                }
            }