コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #14
0
ファイル: InMemoryBusTests.cs プロジェクト: evenbing/EasyNetQ
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }