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; }
// 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 }
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(); } } }
static void Main(string[] args) { int iterationsPerTask = Int32.Parse(ConfigurationManager.AppSettings["MessagesPerThread"]); int taskCount = Int32.Parse(ConfigurationManager.AppSettings["NoOfThreads"]); bool expectReply = Boolean.Parse(ConfigurationManager.AppSettings["ExpectReply"]); var amqpUrl = ConfigurationManager.AppSettings["ServerUri"]; //AMQP URI for RabbitMQ server var serviceName = "speedtest"; //Uniquely identifies this service var msgMapper = expectReply ? new BasicMessageMapper(amqpUrl, serviceName) : new SendOnlyMessageMapper(amqpUrl, serviceName); var subscriber = new RestBusSubscriber(msgMapper); var client = new RestBusClient(msgMapper); Task[] tasks = new Task[taskCount]; for(int t = 0; t < taskCount; t++) { tasks[t] = new Task(() => { Message msg; for (int i = 0; i < iterationsPerTask; i++) { msg = new Message { Body = BodyGenerator.GetNext() }; var res = client.PostAsJsonAsync("api/test/", msg, null).Result; } }, TaskCreationOptions.LongRunning); } Console.WriteLine("Sending " + iterationsPerTask * taskCount + " messages across " + taskCount + " threads"); Stopwatch watch = new Stopwatch(); watch.Start(); for(int t = 0; t < taskCount; t++) { tasks[t].Start(); } Task.WaitAll(tasks); watch.Stop(); Console.WriteLine("Total time: " + watch.Elapsed); Console.ReadKey(); client.Dispose(); }
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(); //****// }
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 = "samba"; //Uniquely identifies this service var msgMapper = new BasicMessageMapper(amqpUrl, serviceName); var subscriber = new RestBusSubscriber(msgMapper); restbusHost = new RestBusHost(subscriber); restbusHost.Start(); //****// }
// 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); } }