private void AppResolve(IApplicationBuilder app) { app.UseMvc(routes => { //routes.MapGet("micro", async ctx => await MicroServiceRunner.Methods(ctx)); routes.MapPost("micro", async(request, response, route) => { //route.Values.TryGetValue("contract", out var contract); //route.Values.TryGetValue("method", out var method); var sender = new HttpServerMessageSender(_codecFactory.GetEncoder(), response); try { await OnReceived(sender, request); } catch (Exception ex) { var result = new ResultMessage(); if (ex is SpearException busi) { result.Code = busi.Code; result.Message = busi.Message; } else { var logger = app.ApplicationServices.GetService <ILogger <HttpMicroListener> >(); logger.LogError(ex, ex.Message); result.Code = (int)HttpStatusCode.InternalServerError; result.Message = ex.Message; } await sender.Send(MicroMessage.CreateResultMessage(Guid.NewGuid().ToString("N"), result)); } }); }); }
private void BuildApplication(IApplicationBuilder app) { app .UseRouting() .UseEndpoints(routes => { routes.MapGet("micro", async ctx => { var services = _entryFactory.Entries.ToDictionary(k => $"micro/{k.Key}", v => v.Value.Parameters.ToDictionary(pk => pk.Name, pv => pv.ParameterType.GetTypeInfo().Name)); ctx.Response.ContentType = "application/json"; await ctx.Response.WriteAsync(JsonConvert.SerializeObject(services), Encoding.UTF8); }); routes.MapGet("healthy", async ctx => { var header = ctx.Response.GetTypedHeaders(); header.CacheControl = new CacheControlHeaderValue { NoCache = true }; await ctx.Response.WriteAsync("ok", Encoding.UTF8); }); routes.MapPost("micro/executor", async ctx => { //route.Values.TryGetValue("serviceId", out var serviceId); var sender = new HttpServerMessageSender(_messageCodec, ctx.Response, _address.Gzip); try { await OnReceived(sender, ctx); } catch (Exception ex) { var result = new MessageResult(); if (ex is SpearException busi) { result.Code = busi.Code; result.Message = busi.Message; } else { _logger.LogError(ex, ex.Message); result.Code = (int)HttpStatusCode.InternalServerError; result.Message = ex.Message; } await sender.Send(result); } }); }); }
public static void AppResolve(this IApplicationBuilder app) { app.Run(async(context) => { var messageId = Guid.NewGuid().ToString("N"); var _serializer = (ISerializer <string>)app.ApplicationServices.GetService(typeof(ISerializer <string>)); var serviceRouteProvider = (IServiceRouteProvider)app.ApplicationServices.GetService(typeof(IServiceRouteProvider)); var serviceExecutor = (IServiceExecutor)app.ApplicationServices.GetService(typeof(IServiceExecutor)); var sender = new HttpServerMessageSender(_serializer, context, new DiagnosticListener("BimTechDiagnosticListener")); HttpMessageListener httpMessageListener = new HttpMessageListener(_serializer, serviceRouteProvider, serviceExecutor); var actionFilters = app.ApplicationServices.GetServices <IActionFilter>(); await httpMessageListener.OnReceived(sender, messageId, context, actionFilters); }); }
private void AppResolve(IApplicationBuilder app) { app.UseMvc(routes => { routes.MapGet("micro", async ctx => { var services = _entryFactory.Services.ToDictionary(k => $"micro/{k.Key}", v => v.Value.Parameters.ToDictionary(pk => pk.Name, pv => pv.ParameterType.GetTypeInfo().Name)); ctx.Response.ContentType = "application/json"; await ctx.Response.WriteAsync(JsonConvert.SerializeObject(services), Encoding.UTF8); }); routes.MapPost("micro/executor", async(request, response, route) => { //route.Values.TryGetValue("serviceId", out var serviceId); var sender = new HttpServerMessageSender(_codecFactory.GetEncoder(), response); try { await OnReceived(sender, request); } catch (Exception ex) { var result = new ResultMessage(); if (ex is SpearException busi) { result.Code = busi.Code; result.Message = busi.Message; } else { _logger.LogError(ex, ex.Message); result.Code = (int)HttpStatusCode.InternalServerError; result.Message = ex.Message; } await sender.Send(MicroMessage.CreateResultMessage(Guid.NewGuid().ToString("N"), result)); } }); //routes.MapRoute("default", "{controller=Home}/{action=Index}/{Id?}"); }); }