Exemple #1
0
        public void A_correlated_message_should_find_the_correct_saga()
        {
            try
            {
                using (IUnitOfWork work = UnitOfWork.Start())
                    using (var repository = new NHibernateSagaRepository <TestSaga>())
                    {
                        var ping = new PingMessage(_sagaId);

                        var initiatePolicy = new InitiatingSagaPolicy <TestSaga, PingMessage>(x => false);

                        var message = new PingMessage(_sagaId);
                        repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Joe");


                        List <TestSaga> sagas = repository.Where(x => x.CorrelationId == _sagaId).ToList();

                        Assert.AreEqual(1, sagas.Count);
                        Assert.IsNotNull(sagas[0]);
                        Assert.AreEqual(_sagaId, sagas[0].CorrelationId);
                    }
            }
            finally
            {
                UnitOfWork.Finish();
            }
        }
            static ISagaRepository <ReadOnlyInstance> CreateSagaRepository()
            {
                var provider       = new SQLiteSessionFactoryProvider(false, typeof(ReadOnlyInstanceMap));
                var sessionFactory = provider.GetSessionFactory();
                ISagaRepository <ReadOnlyInstance> sagaRepository = NHibernateSagaRepository <ReadOnlyInstance> .Create(sessionFactory);

                return(sagaRepository);
            }
Exemple #3
0
            protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
            {
                _machine        = new TestStateMachine();
                _sessionFactory = new SQLiteSessionFactoryProvider(typeof(InstanceMap))
                                  .GetSessionFactory();
                _repository = new NHibernateSagaRepository <Instance>(_sessionFactory);

                configurator.StateMachineSaga(_machine, _repository);
            }
Exemple #4
0
        protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            _machine = new SuperShopper();

            _sessionFactory = new SQLiteSessionFactoryProvider(typeof(ShoppingChoreMap))
                              .GetSessionFactory();
            _repository = NHibernateSagaRepository <ShoppingChore> .Create(_sessionFactory);

            configurator.StateMachineSaga(_machine, _repository);
        }
        public void A_correlated_message_should_find_the_correct_saga()
        {
            var repository = new NHibernateSagaRepository <TestSaga>(_sessionFactory);
            var ping       = new PingMessage(_sagaId);

            var initiatePolicy = new InitiatingSagaPolicy <TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false);

            var message = new InitiateSimpleSaga(_sagaId);
            var context = message.ToConsumeContext();

            repository.GetSaga(context, message.CorrelationId, GetHandlers, initiatePolicy)
            .Each(x => x(context));

            List <TestSaga> sagas = repository.Where(x => x.CorrelationId == _sagaId).ToList();

            Assert.AreEqual(1, sagas.Count);
            Assert.IsNotNull(sagas[0]);
            Assert.AreEqual(_sagaId, sagas[0].CorrelationId);
        }
        public void A_correlated_message_should_find_the_correct_saga()
        {
            var repository = new NHibernateSagaRepository<TestSaga>(_sessionFactory);
            var ping = new PingMessage(_sagaId);

            var initiatePolicy = new InitiatingSagaPolicy<TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false);

            var message = new InitiateSimpleSaga(_sagaId);
            IConsumeContext<InitiateSimpleSaga> context = message.ToConsumeContext();

            repository.GetSaga(context, message.CorrelationId, GetHandlers, initiatePolicy)
                .Each(x => x(context));

            List<TestSaga> sagas = repository.Where(x => x.CorrelationId == _sagaId).ToList();

            Assert.AreEqual(1, sagas.Count);
            Assert.IsNotNull(sagas[0]);
            Assert.AreEqual(_sagaId, sagas[0].CorrelationId);
        }
        private static void InitializeTimeoutService(ISessionFactory sessionFactory)
        {
            Console.Write("Initializing the timeout service... ");

            var timeoutBus = ServiceBusFactory.New(sbc =>
            {
                sbc.UseMsmq();
                sbc.VerifyMsmqConfiguration();
                sbc.UseControlBus();

                sbc.ReceiveFrom(Constants.QueueTimeouts);
                sbc.UseSubscriptionService(Constants.QueueSubscriptions);
            });

            var timeoutSagaRepository = new NHibernateSagaRepository<TimeoutSaga>(sessionFactory);
            var timeoutService = new TimeoutService(timeoutBus, timeoutSagaRepository);
            timeoutService.Start();

            Utils.WriteToConsole("done", ConsoleColor.Green);
        }
        private static void InitializeSubscriptionService(ISessionFactory sessionFactory)
        {
            Console.Write("Initializing the subscription service... ");

            var subscriptionBus = ServiceBusFactory.New(sbc =>
            {
                sbc.UseMsmq();
                sbc.VerifyMsmqConfiguration();
                sbc.SetConcurrentConsumerLimit(1);

                sbc.ReceiveFrom(Constants.QueueSubscriptions);
            });

            var subscriptionSagas = new NHibernateSagaRepository<SubscriptionSaga>(sessionFactory);
            var subscriptionClientSagas = new NHibernateSagaRepository<SubscriptionClientSaga>(sessionFactory);

            var subscriptionService = new SubscriptionService(subscriptionBus, subscriptionSagas, subscriptionClientSagas);
            subscriptionService.Start();

            Utils.WriteToConsole("done", ConsoleColor.Green);
        }
        public void Execute()
        {
            var provider = new MassTransit.NHibernateIntegration.SqlServerSessionFactoryProvider("Data Source=LocalSqlServer;Initial catalog=SagaRepository;Integrated Security=True;", typeof(EstimationSagaMap), typeof(EstimationStateSagaMap));

            provider.UpdateSchema();
            var factory    = provider.GetSessionFactory();
            var repository = new NHibernateSagaRepository <EstimationStateSaga>(factory);

            using (var bus = ServiceBusFactory.New(sbc =>
            {
                sbc.UseRabbitMq();
                sbc.ReceiveFrom("rabbitmq://localhost/subscriber");
                //sbc.Subscribe(subs => subs.Saga(new InMemorySagaRepository<EstimationSaga>()).Permanent());
                //sbc.Subscribe(subs => subs.Saga(repository).Permanent());
                sbc.Subscribe(subs => subs.Saga(repository).Permanent());
            }))
            {
                Console.WriteLine("Hit any key to end.");
                Console.ReadLine();
            }
        }
Exemple #10
0
            protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
            {
                _provider       = new SQLiteSessionFactoryProvider(false, typeof(MissingInstanceMap));
                _sessionFactory = _provider.GetSessionFactory();
                _sagaRepository = new Lazy <ISagaRepository <MissingInstance> >(() => NHibernateSagaRepository <MissingInstance> .Create(_sessionFactory));

                _machine = new TestStateMachine();

                configurator.StateMachineSaga(_machine, _sagaRepository.Value);
            }
Exemple #11
0
		public void A_correlated_message_should_find_the_correct_saga()
		{
			try
			{
				using (IUnitOfWork work = UnitOfWork.Start())
					using (var repository = new NHibernateSagaRepository<TestSaga>())
					{
						var ping = new PingMessage(_sagaId);

						var initiatePolicy = new InitiatingSagaPolicy<TestSaga, PingMessage>(x => false);

						var message = new PingMessage(_sagaId);
						repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Joe");


						List<TestSaga> sagas = repository.Where(x => x.CorrelationId == _sagaId).ToList();

						Assert.AreEqual(1, sagas.Count);
						Assert.IsNotNull(sagas[0]);
						Assert.AreEqual(_sagaId, sagas[0].CorrelationId);
				}
			}
			finally
			{
				UnitOfWork.Finish();
			}
		}
 public Locating_an_existing_saga()
 {
     _provider       = new SQLiteSessionFactoryProvider(false, typeof(SimpleSagaMap));
     _sessionFactory = _provider.GetSessionFactory();
     _sagaRepository = new Lazy <ISagaRepository <SimpleSaga> >(() => NHibernateSagaRepository <SimpleSaga> .Create(_sessionFactory));
 }