Ejemplo n.º 1
0
        public void Should_be_able_to_do_simple_request_response_lots()
        {
            const int numberOfCalls = 1000;

            var countdownEvent = new CountdownEvent(numberOfCalls);
            var count          = 0;

            for (int i = 0; i < numberOfCalls; i++)
            {
                var request = new TestRequestMessage {
                    Text = "Hello from the client! " + i.ToString()
                };
                using (var publishChannel = bus.OpenPublishChannel())
                {
                    publishChannel.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                    {
                        Console.WriteLine("Got response: '{0}'", response.Text);
                        count++;
                        countdownEvent.Signal();
                    });
                }
            }

            countdownEvent.Wait(15000);
            count.ShouldEqual(numberOfCalls);
        }
Ejemplo n.º 2
0
        public void Should_be_able_to_do_simple_request_response()
        {
            var request = new TestRequestMessage {Text = "Hello from the client! "};

            Console.WriteLine("Making request");
            bus.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                Console.WriteLine("Got response: '{0}'", response.Text));

            Thread.Sleep(2000);
        }
Ejemplo n.º 3
0
        public void Should_be_able_to_do_simple_request_response_lots()
        {
            for (int i = 0; i < 1000; i++)
            {
                var request = new TestRequestMessage { Text = "Hello from the client! " + i.ToString() };
                bus.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                    Console.WriteLine("Got response: '{0}'", response.Text));
            }

            Thread.Sleep(1000);
        }
Ejemplo n.º 4
0
        public void Should_be_able_to_do_simple_request_response()
        {
            var request = new TestRequestMessage {
                Text = "Hello from the client! "
            };

            Console.WriteLine("Making request");
            bus.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                                                                  Console.WriteLine("Got response: '{0}'", response.Text));

            Thread.Sleep(2000);
        }
Ejemplo n.º 5
0
        public void Should_be_able_to_do_simple_request_response_lots()
        {
            for (int i = 0; i < 1000; i++)
            {
                var request = new TestRequestMessage {
                    Text = "Hello from the client! " + i.ToString()
                };
                bus.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                                                                      Console.WriteLine("Got response: '{0}'", response.Text));
            }

            Thread.Sleep(3000);
        }
Ejemplo n.º 6
0
        public void Should_be_able_to_do_simple_request_response_that_takes_a_long_time()
        {
            var request = new TestRequestMessage
            {
                Text = "Hello from the client! ",
                CausesServerToTakeALongTimeToRespond = true
            };

            Console.WriteLine("Making request");
            bus.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                                                                  Console.WriteLine("Got response: '{0}'", response.Text));

            Thread.Sleep(7000);
        }
Ejemplo n.º 7
0
        public void Should_be_able_to_do_simple_request_response_that_throws_on_server()
        {
            var request = new TestRequestMessage
            {
                Text = "Hello from the client! ",
                CausesExceptionInServer = true
            };

            Console.WriteLine("Making request");
            bus.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                                                                  Console.WriteLine("Got response: '{0}'", response.Text));

            Thread.Sleep(2000);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void Should_be_able_to_do_simple_request_response_that_throws_on_response_consumer()
        {
            var request = new TestRequestMessage {
                Text = "Hello from the client! "
            };

            Console.WriteLine("Making request");
            bus.Request <TestRequestMessage, TestResponseMessage>(request, response =>
            {
                Console.WriteLine("Got response: '{0}'", response.Text);
                throw new SomeRandomException("Something very bad just happened!");
            });

            Thread.Sleep(2000);
        }
Ejemplo n.º 10
0
        public void SubscribePublishSaga_should_publish_when_request_is_consumed()
        {
            new SubscribePublishSaga().Initialize(bus);

            const string text = "some text";
            var requestMessage = new TestRequestMessage {Text = text};
            TestResponseMessage responseMessage = null;

            bus.Subscribe<TestResponseMessage>("id", response =>
            {
                responseMessage = response;
            });

            bus.Publish(requestMessage);

            Assert.IsNotNull(responseMessage);
            Assert.AreEqual(text, responseMessage.Text);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public void Should_be_able_to_do_simple_request_response()
        {
            var autoResetEvent = new AutoResetEvent(false);

            var request = new TestRequestMessage {
                Text = "Hello from the client! "
            };

            Console.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                {
                    Console.WriteLine("Got response: '{0}'", response.Text);
                    autoResetEvent.Set();
                });
            }

            autoResetEvent.WaitOne(1000);
        }
Ejemplo n.º 13
0
        public void Should_be_able_to_do_simple_request_response_that_throws_on_response_consumer()
        {
            var autoResetEvent = new AutoResetEvent(false);
            var request        = new TestRequestMessage {
                Text = "Hello from the client! "
            };

            Console.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request <TestRequestMessage, TestResponseMessage>(request, response =>
                {
                    Console.WriteLine("Got response: '{0}'", response.Text);
                    autoResetEvent.Set();
                    throw new SomeRandomException("Something very bad just happened!");
                });
            }

            autoResetEvent.WaitOne(1000);
        }
Ejemplo n.º 14
0
        public void SubscribePublishSaga_should_publish_when_request_is_consumed()
        {
            new SubscribePublishSaga().Initialize(bus);

            const string text           = "some text";
            var          requestMessage = new TestRequestMessage {
                Text = text
            };
            TestResponseMessage responseMessage = null;

            bus.Subscribe <TestResponseMessage>("id", response =>
            {
                responseMessage = response;
            });

            bus.Publish(requestMessage);

            Assert.IsNotNull(responseMessage);
            Assert.AreEqual(text, responseMessage.Text);
        }
Ejemplo n.º 15
0
        public void Should_be_able_to_do_simple_request_response_lots()
        {
            const int numberOfCalls = 1000;

            var countdownEvent = new CountdownEvent(numberOfCalls);
            var count = 0;

            for (int i = 0; i < numberOfCalls; i++)
            {
                var request = new TestRequestMessage { Text = "Hello from the client! " + i.ToString() };
                using (var publishChannel = bus.OpenPublishChannel())
                {
                    publishChannel.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                    {
                        Console.WriteLine("Got response: '{0}'", response.Text);
                        count++;
                        countdownEvent.Signal();
                    });
                }
            }

            countdownEvent.Wait(15000);
            count.ShouldEqual(numberOfCalls);
        }
Ejemplo n.º 16
0
        public void Should_be_able_to_do_simple_request_response_that_throws_on_server()
        {
            var request = new TestRequestMessage
            {
                Text = "Hello from the client! ",
                CausesExceptionInServer = true
            };

            Console.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                    Console.WriteLine("Got response: '{0}'", response.Text));
            }

            Thread.Sleep(2000);
        }
Ejemplo n.º 17
0
        public void Should_be_able_to_do_simple_request_response_that_throws_on_response_consumer()
        {
            var request = new TestRequestMessage { Text = "Hello from the client! " };

            Console.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                {
                    Console.WriteLine("Got response: '{0}'", response.Text);
                    throw new SomeRandomException("Something very bad just happened!");
                });
            }

            Thread.Sleep(2000);
        }
Ejemplo n.º 18
0
        public void Should_be_able_to_do_simple_request_response_that_takes_a_long_time()
        {
            var request = new TestRequestMessage
            {
                Text = "Hello from the client! ",
                CausesServerToTakeALongTimeToRespond = true
            };

            Console.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                    Console.WriteLine("Got response: '{0}'", response.Text));
            }

            Thread.Sleep(7000);
        }
Ejemplo n.º 19
0
        public void Should_be_able_to_do_simple_request_response()
        {
            var autoResetEvent = new AutoResetEvent(false);

            var request = new TestRequestMessage {Text = "Hello from the client! "};

            Console.WriteLine("Making request");
            using (var publishChannel = bus.OpenPublishChannel())
            {
                publishChannel.Request<TestRequestMessage, TestResponseMessage>(request, response =>
                {
                    Console.WriteLine("Got response: '{0}'", response.Text);
                    autoResetEvent.Set();
                });
            }

            autoResetEvent.WaitOne(1000);
        }