static void Execute(int port) { try { // create protocol factory, default to BinaryProtocol TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true, true); TServerTransport servertrans = new TServerSocket(port, 0, false); TTransportFactory TransportFactory = new TFramedTransport.Factory(); BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl(); TProcessor benchProcessor = new BenchmarkService.Processor(benchHandler); Aggr.Iface aggrHandler = new AggrServiceImpl(); TProcessor aggrProcessor = new Aggr.Processor(aggrHandler); TMultiplexedProcessor multiplex = new TMultiplexedProcessor(); multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor); multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor); TServer ServerEngine = new TSimpleServer(multiplex, servertrans, TransportFactory, ProtocolFactory); Console.WriteLine("Starting the server ..."); ServerEngine.Serve(); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Execute(int port) { try { // create protocol factory, default to BinaryProtocol TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true); TServerTransport servertrans = new TServerSocket(port, 0, false); TTransportFactory TransportFactory = new TFramedTransport.Factory(); BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl(); TProcessor benchProcessor = new BenchmarkService.Processor(benchHandler); Aggr.Iface aggrHandler = new AggrServiceImpl(); TProcessor aggrProcessor = new Aggr.Processor(aggrHandler); TMultiplexedProcessor multiplex = new TMultiplexedProcessor(); multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor); multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor); TServer ServerEngine = new TSimpleServer(multiplex, servertrans, TransportFactory, ProtocolFactory); Console.WriteLine("Starting the server ..."); ServerEngine.Serve(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime) { // Required to notify performance infrastructure that it can begin benchmarks applicationLifetime.ApplicationStarted.Register(() => Console.WriteLine("Application started.")); app.UseRouting(); bool.TryParse(_config["enableCertAuth"], out var enableCertAuth); if (enableCertAuth) { app.UseAuthentication(); app.UseAuthorization(); } bool.TryParse(_config["enableGrpcWeb"], out var enableGrpcWeb); if (enableGrpcWeb) { app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true }); } app.UseMiddleware <ServiceProvidersMiddleware>(); app.UseEndpoints(endpoints => { ConfigureAuthorization(endpoints.MapGrpcService <BenchmarkServiceImpl>()); ConfigureAuthorization(endpoints.MapControllers()); ConfigureAuthorization(endpoints.MapGet("/", context => { return(context.Response.WriteAsync("Benchmark Server")); })); ConfigureAuthorization(endpoints.MapPost("/unary", async context => { MemoryStream ms = new MemoryStream(); await context.Request.Body.CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); JsonSerializer serializer = new JsonSerializer(); var message = serializer.Deserialize <SimpleRequest>(new JsonTextReader(new StreamReader(ms))); ms.Seek(0, SeekOrigin.Begin); using (var writer = new JsonTextWriter(new StreamWriter(ms, Encoding.UTF8, 1024, true))) { serializer.Serialize(writer, BenchmarkServiceImpl.CreateResponse(message)); } context.Response.StatusCode = StatusCodes.Status200OK; ms.Seek(0, SeekOrigin.Begin); await ms.CopyToAsync(context.Response.Body); })); }); }
public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime) { // Required to notify performance infrastructure that it can begin benchmarks applicationLifetime.ApplicationStarted.Register(() => Console.WriteLine("Application started.")); app.UseRouting(); #if CLIENT_CERTIFICATE_AUTHENTICATION app.UseAuthentication(); app.UseAuthorization(); #endif #if GRPC_WEB app.UseGrpcWeb(); #endif app.UseMiddleware <ServiceProvidersMiddleware>(); app.UseEndpoints(endpoints => { endpoints.MapGrpcService <BenchmarkServiceImpl>(); endpoints.MapControllers(); endpoints.MapGet("/", context => { return(context.Response.WriteAsync("Benchmark Server")); }); endpoints.MapPost("/unary", async context => { MemoryStream ms = new MemoryStream(); await context.Request.Body.CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); JsonSerializer serializer = new JsonSerializer(); var message = serializer.Deserialize <SimpleRequest>(new JsonTextReader(new StreamReader(ms))); ms.Seek(0, SeekOrigin.Begin); using (var writer = new JsonTextWriter(new StreamWriter(ms, Encoding.UTF8, 1024, true))) { serializer.Serialize(writer, BenchmarkServiceImpl.CreateResponse(message)); } context.Response.StatusCode = StatusCodes.Status200OK; ms.Seek(0, SeekOrigin.Begin); await ms.CopyToAsync(context.Response.Body); }); }); }
public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGrpcService <BenchmarkServiceImpl>(); endpoints.MapControllers(); endpoints.MapGet("/", context => { return(context.Response.WriteAsync("Benchmark Server")); }); endpoints.MapPost("/unary", async context => { MemoryStream ms = new MemoryStream(); await context.Request.Body.CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); JsonSerializer serializer = new JsonSerializer(); var message = serializer.Deserialize <SimpleRequest>(new JsonTextReader(new StreamReader(ms))); ms.Seek(0, SeekOrigin.Begin); using (var writer = new JsonTextWriter(new StreamWriter(ms, Encoding.UTF8, 1024, true))) { serializer.Serialize(writer, BenchmarkServiceImpl.CreateResponse(message)); } context.Response.StatusCode = StatusCodes.Status200OK; ms.Seek(0, SeekOrigin.Begin); await ms.CopyToAsync(context.Response.Body); }); }); }
public SimpleResponse Post([FromBody] SimpleRequest request) { return(BenchmarkServiceImpl.CreateResponse(request)); }