Exemplo n.º 1
0
        public IList<IDisposable> Start()
        {
            List<IDisposable> servers = new List<IDisposable>();

            //Initialize startup object
            var startup = new Startup();

            string baseAddress = null;
            //baseAddress = "http://localhost:9000/"; //Uncomment this line to also listen via HTTP on localhost:9000

            //Start WebAPI OWIN host 
            servers.Add(WebApp.Start(url: baseAddress, startup: startup.Configuration));

            //Start RestBus Subscriber/host

            var amqpUrl = ConfigurationManager.AppSettings["rabbitmqserver"]; //AMQP URI for RabbitMQ server
            var serviceName = "test"; //Uniquely identifies this service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
            var subscriber = new RestBusSubscriber(msgMapper);
            var host = new RestBusHost(subscriber, startup.Config);

            host.Start();
            Console.WriteLine("Server started ... Ctrl-C to quit.");

            servers.Add(host);
            return servers;

        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {

            #if !BARE_TO_THE_METAL_MODE
                app.UseMvc();
            #endif

            MessageSize = int.Parse(Configuration["MessageSize"]);

            var amqpUrl = Configuration["ServerUri"]; //AMQP URI for RabbitMQ server
            var serviceName = "speedtest"; //Uniquely identifies this service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
            var subscriber = new RestBusSubscriber(msgMapper);
            app.ConfigureRestBusServer(subscriber);

            #if BARE_TO_THE_METAL_MODE
                app.Run(async c =>
                {
                    if (c.Request.Path.StartsWithSegments("/api/test"))
                    {
                        var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Message { Body = BodyGenerator.GetNext() });
                        var bytes = System.Text.Encoding.UTF8.GetBytes(json);
                        await c.Response.Body.WriteAsync(bytes, 0, bytes.Length);
                    }
                });
            #endif
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {

            var amqpUrl = "amqp:localhost:5672"; //AMQP URL for RabbitMQ installation
            var serviceName = "madagascar"; //The unique identifier for the target service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);

            RestBusClient client = new RestBusClient(msgMapper);

            RequestOptions requestOptions = null;
            /* 
             * //Uncomment this section to get a response in JSON format
             * 
            requestOptions = new RequestOptions();
            requestOptions.Headers.Add("Accept", "application/json");
             */

            var response = SendMessage(client, requestOptions).Result;

            //Display response
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.Content.ReadAsStringAsync().Result);

            client.Dispose();
            Console.ReadKey();

        }
Exemplo n.º 4
0
        static void Main()
        {
            //Initialize startup object
            var startup = new Startup();

            string baseAddress = null;
            //baseAddress = "http://localhost:9000/"; //Uncomment this line to also listen on localhost:9000

            //Start WebAPI OWIN host 
            using (WebApp.Start(url: baseAddress, startup: startup.Configuration))
            {
                //Start RestBus Subscriber/host

                var amqpUrl = ConfigurationManager.AppSettings["ServerUri"]; //AMQP URI for RabbitMQ server
                var serviceName = "speedtest"; //Uniquely identifies this service

                var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
                var subscriber = new RestBusSubscriber(msgMapper);
                using (var host = new RestBusHost(subscriber, startup.Config))
                {
                    host.Start();
                    Console.WriteLine("Server started ... Ctrl-C to quit.");
                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 5
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Init RestBus client
            var amqpUrl = "amqp://localhost:5672"; //AMQP URL for RabbitMQ installation
            var serviceName = "samba"; //The unique identifier for the target service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
            HelloServiceClient = new RestBusClient(msgMapper);
        }
Exemplo n.º 6
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(); }
        }
Exemplo n.º 7
0
        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(); }
        }
Exemplo n.º 8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //*** Start RestBus subscriber/host **//

            var amqpUrl = "amqp://localhost:5672"; //AMQP URL for RabbitMQ installation
            var serviceName = "samba"; //Uniquely identifies this service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
            var subscriber = new RestBusSubscriber(msgMapper);
            restbusHost = new RestBusHost(subscriber, GlobalConfiguration.Configuration);
            restbusHost.Start();

            //****//

        }
Exemplo n.º 9
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Initialize ServiceStack application
            new AppHost().Init();


            //*** Start RestBus subscriber/host **//

            var amqpUrl = "amqp:localhost:5672"; //AMQP URL for RabbitMQ installation
            var serviceName = "madagascar"; //Uniquely identifies this service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
            var subscriber = new RestBusSubscriber(msgMapper);
            restbusHost = new RestBusHost(subscriber);
            restbusHost.Start();

            //****//
        }
Exemplo n.º 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseIISPlatformHandler();

            app.UseStaticFiles();

            app.UseMvc();

            // Create RestBus Subscriber
            var amqpUrl = "amqp://localhost:5672"; //AMQP URI for RabbitMQ server
            var serviceName = "samba"; //Uniquely identifies this service

            var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
            var subscriber = new RestBusSubscriber(msgMapper);

            bool standAlone = false;
            /* 
               This service listens for requests through both HTTP and the message broker. 
               If you desire a standalone service that only listens to the message broker:
               1. Set standAlone to true
               2. Update the hosting.json file with the instructions in the file.
            */

            if (standAlone)
            {
                // Configures the rest bus server -- needed if running standalone server, ignored otherwise.
                app.ConfigureRestBusServer(subscriber);
            }
            else
            {
                app.RunRestBusHost(subscriber);
            }
        }
Exemplo n.º 11
0
        public 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
             *
             */

            BasicMessageMapper msgMapper = new BasicMessageMapper("amqp://localhost:5672", "test");
            RestBusClient client = new RestBusClient(msgMapper);

            var msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, "/test/my_api")
            {
                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");

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

            Console.ReadKey();
            client.Dispose();
        }