示例#1
0
        public async static void Run(int iterations)
        {
            /*
             * An example that performs a speed test via the RestBus RabbitMQ client.
             *
             * For more examples, see the https://github.com/tenor/RestBus.Examples repo
             * For more elaborate speed tests see the https://github.com/tenor/RestBus.Benchmarks repo
             *
             */

            //Start Web API 2 host to receive messages.
            WebAPISelfHost host    = new WebAPISelfHost();
            var            servers = host.Start();

            //Create client
            BasicMessageMapper msgMapper = new BasicMessageMapper(ConfigurationManager.AppSettings["rabbitmqserver"], "test");
            RestBusClient      client    = new RestBusClient(msgMapper);

            //Compose message
            var msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, "api/test/random")
            {
                Content = new System.Net.Http.StringContent("{\"Val\":10}", new UTF8Encoding(), "application/json")
            };

            msg.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01, */*; q=0.01");

            Stopwatch watch = new Stopwatch();

            HttpResponseMessage res;

            watch.Start();
            for (int i = 0; i < iterations; i++)
            {
                //Send message
                res = await client.SendAsync(msg, System.Threading.CancellationToken.None);
            }

            watch.Stop();

            Console.WriteLine("Elapsed time: " + watch.Elapsed);
            Console.ReadKey();

            //Dispose client
            client.Dispose();
            //Dispose servers
            foreach (var server in servers)
            {
                server.Dispose();
            }
        }
示例#2
0
        public async static void Run(int iterations)
        {
            /*
             * An example that performs a speed test via the RestBus RabbitMQ client.
             * 
             * For more examples, see the https://github.com/tenor/RestBus.Examples repo
             * For more elaborate speed tests see the https://github.com/tenor/RestBus.Benchmarks repo
             * 
             */

            //Start Web API 2 host to receive messages.
            WebAPISelfHost host = new WebAPISelfHost();
            var servers = host.Start();

            //Create client
            BasicMessageMapper msgMapper = new BasicMessageMapper(ConfigurationManager.AppSettings["rabbitmqserver"], "test");
            RestBusClient client = new RestBusClient(msgMapper);

            //Compose message
            var msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, "api/test/random")
            {
                Content = new System.Net.Http.StringContent("{\"Val\":10}", new UTF8Encoding(), "application/json")
            };

            msg.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01, */*; q=0.01");

            Stopwatch watch = new Stopwatch();

            HttpResponseMessage res;
            watch.Start();
            for (int i = 0; i < iterations; i++)
            {
                //Send message
                res = await client.SendAsync(msg, System.Threading.CancellationToken.None);
            }

            watch.Stop();

            Console.WriteLine("Elapsed time: " + watch.Elapsed);
            Console.ReadKey();

            //Dispose client
            client.Dispose();
            //Dispose servers
            foreach (var server in servers) { server.Dispose(); }
        }
示例#3
0
文件: Basic.cs 项目: tuga1975/RestBus
        public async static void Run()
        {
            /*
             * An example that composes a HttpRequest Message and sends it via the RestBus RabbitMQ client.
             *
             * For more examples, see the https://github.com/tenor/RestBus.Examples repo
             *
             */

            //Start Web API 2 host to receive message.
            WebAPISelfHost host    = new WebAPISelfHost();
            var            servers = host.Start();

            //Create client
            BasicMessageMapper msgMapper = new BasicMessageMapper("amqp://localhost:5672", "test");
            //msgMapper = new QueueingMessageMapper("amqp://localhost:5672", "test"); //Uncomment this to only queue messages.

            RestBusClient client = new RestBusClient(msgMapper);

            //Compose message
            var msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, "/api/test")
            {
                Content = new System.Net.Http.StringContent("{\"Val\":10}", new UTF8Encoding(), "application/json")
            };

            msg.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01, */*; q=0.01");

            //Send message
            Console.WriteLine("Sending Message ...");

            var res = await client.SendAsync(msg, System.Threading.CancellationToken.None);

            Console.WriteLine("Response Received:\n{0}\nContent:\n{1}\n", res, Encoding.UTF8.GetString((res.Content as ByteArrayContent).ReadAsByteArrayAsync().Result));

            Console.WriteLine("Press any key to quit.");
            Console.ReadKey();

            //Dispose client
            client.Dispose();
            //Dispose servers
            foreach (var server in servers)
            {
                server.Dispose();
            }
        }
示例#4
0
文件: Basic.cs 项目: bestwpw/RestBus
        public async static void Run()
        {
            /*
             * An example that composes a HttpRequest Message and sends it via the RestBus RabbitMQ client.
             * 
             * For more examples, see the https://github.com/tenor/RestBus.Examples repo
             * 
             */

            //Start Web API 2 host to receive message.
            WebAPISelfHost host = new WebAPISelfHost();
            var servers = host.Start();

            //Create client
            BasicMessageMapper msgMapper = new BasicMessageMapper("amqp://localhost:5672", "test");
            //msgMapper = new QueueingMessageMapper("amqp://localhost:5672", "test"); //Uncomment this to only queue messages.

            RestBusClient client = new RestBusClient(msgMapper);

            //Compose message
            var msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, "/api/test")
            {
                Content = new System.Net.Http.StringContent("{\"Val\":10}", new UTF8Encoding(), "application/json")
            };

            msg.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01, */*; q=0.01");

            //Send message
            Console.WriteLine("Sending Message ...");

            var res = await client.SendAsync(msg, System.Threading.CancellationToken.None);

            Console.WriteLine("Response Received:\n{0}\nContent:\n{1}\n", res, Encoding.UTF8.GetString((res.Content as ByteArrayContent).ReadAsByteArrayAsync().Result));

            Console.WriteLine("Press any key to quit.");
            Console.ReadKey();

            //Dispose client
            client.Dispose();
            //Dispose servers
            foreach(var server in servers) { server.Dispose(); }
        }