Exemple #1
0
        public virtual void Consume(ContinueConcurrentSaga message)
        {
            Trace.WriteLine("Consuming " + message.GetType());
            Thread.Sleep(1000);

            if (Value == -1)
            {
                throw new InvalidOperationException("Should not be a -1 dude!!");
            }

            Value = message.Value;
            Trace.WriteLine("Completed " + message.GetType());
        }
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            Guid transactionId = CombGuid.Generate();

            _log.Info("Creating transaction for " + transactionId);

            const int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Endpoint.Send(startConcurrentSaga);
            LocalBus.Endpoint.Send(startConcurrentSaga);

            _log.Info("Just published the start message");

            UnsubscribeAction unsubscribeAction = LocalBus.Subscribe <ConcurrentLegacySaga>();

            Thread.Sleep(1500);

            const int nextValue = 2;
            var       continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);
            _log.Info("Just published the continue message");
            Thread.Sleep(8000);

            unsubscribeAction();
            foreach (ConcurrentLegacySaga saga in _sagaRepository.Where(x => true))
            {
                _log.Info("Found saga: " + saga.CorrelationId);
            }

            int currentValue = _sagaRepository.Where(x => x.CorrelationId == transactionId).First().Value;

            Assert.AreEqual(nextValue, currentValue);
        }