Exemplo n.º 1
0
        public void RequestResponseSaga_should_make_a_request_get_the_response_and_end()
        {
            new RequestResponseSaga().Initialize(bus);

            const string text         = "some text";
            var          startMessage = new StartMessage {
                Text = text
            };

            // imitate the responding service
            bus.Respond <TestRequestMessage, TestResponseMessage>(request =>
                                                                  new TestResponseMessage {
                Text = request.Text
            });

            // set up the subscription for the end message
            EndMessage endMessage = null;

            bus.Subscribe <EndMessage>("id", end =>
            {
                endMessage = end;
            });

            // now publish the start message to kick the saga off
            bus.Publish(startMessage);

            // assert that the end message was assigned and has the correct text
            Assert.IsNotNull(endMessage);
            Assert.AreEqual(text, endMessage.Text);
        }
Exemplo n.º 2
0
        public void Can_call_publish_inside_a_subscribe_handler()
        {
            var bus = RabbitHutch.CreateBus("host=localhost");

            // setup the Saga
            Console.WriteLine("Setting up the Saga");
            bus.Subscribe <StartMessage>("simpleSaga", startMessage =>
            {
                Console.WriteLine("Saga got StartMessage: {0}", startMessage.Text);
                var firstProcessedMessage = startMessage.Text + " - initial process ";
                var request = new TestRequestMessage {
                    Text = firstProcessedMessage
                };

                bus.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                {
                    Console.WriteLine("Saga got Response: {0}", response.Text);
                    var secondProcessedMessage = response.Text + " - final process ";
                    var endMessage             = new EndMessage {
                        Text = secondProcessedMessage
                    };
                    bus.Publish(endMessage);
                });
            });

            // setup the RPC endpoint
            Console.WriteLine("Setting up the RPC endpoint");
            bus.Respond <TestRequestMessage, TestResponseMessage>(request =>
            {
                Console.WriteLine("RPC got Request: {0}", request.Text);
                return(new TestResponseMessage {
                    Text = request.Text + " Responded! "
                });
            });

            // setup the final subscription
            Console.WriteLine("Setting up the final subscription");
            bus.Subscribe <EndMessage>("inline_saga_spike", endMessage =>
                                       Console.WriteLine("Test got EndMessage: {0}", endMessage.Text));

            Thread.Sleep(1000);
            // now kick it off
            Console.WriteLine("Test is publishing StartMessage");
            bus.Publish(new StartMessage {
                Text = "Hello Saga!! "
            });

            // give the message time to run through the process
            Thread.Sleep(1000);
        }
Exemplo n.º 3
0
        public void Can_call_publish_inside_a_subscribe_handler()
        {
            var bus = RabbitHutch.CreateBus("host=localhost");

            // setup the Saga
            Console.WriteLine("Setting up the Saga");
            bus.Subscribe<StartMessage>("simpleSaga", startMessage =>
            {
                Console.WriteLine("Saga got StartMessage: {0}", startMessage.Text);
                var firstProcessedMessage = startMessage.Text + " - initial process ";
                var request = new TestRequestMessage { Text = firstProcessedMessage };

                bus.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                {
                    Console.WriteLine("Saga got Response: {0}", response.Text);
                    var secondProcessedMessage = response.Text + " - final process ";
                    var endMessage = new EndMessage { Text = secondProcessedMessage };
                    bus.Publish(endMessage);
                });
            });

            // setup the RPC endpoint
            Console.WriteLine("Setting up the RPC endpoint");
            bus.Respond<TestRequestMessage, TestResponseMessage>(request =>
            {
                Console.WriteLine("RPC got Request: {0}", request.Text);
                return new TestResponseMessage {Text = request.Text + " Responded! "};
            });

            // setup the final subscription
            Console.WriteLine("Setting up the final subscription");
            bus.Subscribe<EndMessage>("inline_saga_spike", endMessage =>
                Console.WriteLine("Test got EndMessage: {0}", endMessage.Text));

            Thread.Sleep(1000);
            // now kick it off
            Console.WriteLine("Test is publishing StartMessage");
            bus.Publish(new StartMessage { Text = "Hello Saga!! " });

            // give the message time to run through the process
            Thread.Sleep(1000);
        }