// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env) { app.UseCors("any"); app.UseStaticFiles(); app.UseAuthentication(); if (env.IsDevelopment()) { //app.UseDeveloperExceptionPage(); } app.UseStatusCodePages(); app.UseJimuSwagger(); // jimu client Jimu.IApplication host; #if DEBUG if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SERVICE_GROUPS"))) { host = new ApplicationClientBuilder(new ContainerBuilder(), "JimuAppClientSettings.local").Build(); } else { host = new ApplicationClientBuilder(new ContainerBuilder()).Build(); } #else host = new ApplicationClientBuilder(new ContainerBuilder()).Build(); #endif app.UseJimu(host); host.Run(); }
static void Main(string[] args) { Console.WriteLine("Hello client!"); var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NTI1ODM4NjUsInVzZXJuYW1lIjoiYWRtaW4iLCJkZXBhcnRtZW50IjoiSVTpg6gifQ.tx4etoJenyjsujHP5QGwSlhgyl9n2ftn-UziyGIIDPo"; var container = new ContainerBuilder(); var host = new ApplicationClientBuilder(container) //.UseLog4netLogger(new JimuLog4netOptions { EnableConsoleLog = true }) //.UsePollingAddressSelector() //.UseConsulForDiscovery(new Jimu.Client.Discovery.ConsulIntegration.ConsulOptions("127.0.0.1", 8500, "JimuService-")) //.UseHttpForTransfer() //.UseDotNettyForTransfer() .UseToken(() => token) //.UseServiceProxy(new Jimu.Client.Proxy.ServiceProxyOptions( new[] { "IServices" })) .Build(); host.Run(); Stopwatch watch = new Stopwatch(); while (Console.ReadLine() != "exit") { watch.Reset(); watch.Start(); var proxy = host.Container.Resolve <IServiceProxy>(); var echo = proxy.GetService <IEchoService>(); var name = echo.GetEcho("test"); watch.Stop(); Console.WriteLine($"take time {watch.ElapsedMilliseconds}," + "return: " + name); } Console.ReadKey(); }
internal static IHostBuilder UseWebHostJimu(this IHostBuilder hostBuilder, ApplicationClientBuilder jimuAppBuilder, Action <IServiceCollection> servicesAction = null, Action <WebHostBuilderContext, IApplicationBuilder> appAction = null, Action <IMvcBuilder> mvcAction = null, Action <IWebHostBuilder> webBuilderAction = null) { IApplication jimuApp = null; jimuAppBuilder.AddBeforeBuilder(cb => { hostBuilder.ConfigureWebHostDefaults(web => { var type = typeof(ClientWebModuleBase); var webModules = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => x.IsClass && type.IsAssignableFrom(x) && !x.IsAbstract) .Select(x => Activator.CreateInstance(x, jimuAppBuilder.JimuAppSettings) as ClientWebModuleBase) .OrderBy(x => x.Priority); foreach (var configure in webModules) { configure.DoWebHostBuilder(web); } webBuilderAction?.Invoke(web); web .ConfigureServices(services => { services.AddControllersWithViews(); servicesAction?.Invoke(services); var mvcBuilder = services.AddJimu(jimuAppBuilder.JimuAppSettings); mvcAction?.Invoke(mvcBuilder); cb.Populate(services); }) .Configure((context, app) => { if (context.HostingEnvironment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); }); appAction?.Invoke(context, app); app.UseJimu(jimuApp); jimuApp.Run(); JimuClient.Host = jimuApp; }); }); }); jimuApp = jimuAppBuilder.Build(); return(hostBuilder); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env) { app.UseStaticFiles(); app.UseAuthentication(); if (env.IsDevelopment()) { //app.UseDeveloperExceptionPage(); } app.UseStatusCodePages(); app.UseJimuSwagger(); // jimu client var host = new ApplicationClientBuilder(new ContainerBuilder()) //.UseLog4netLogger(new JimuLog4netOptions ////.UseNLogger(new LogOptions //{ // EnableConsoleLog = true, // EnableFileLog = true, // FileLogLevel = LogLevel.Info | LogLevel.Error, //}) //.UseConsulForDiscovery(new Client.Discovery.ConsulIntegration.ConsulOptions("127.0.0.1", 8500, "hello")) //.UseDotNettyForTransfer() //.UseHttpForTransfer() //.UsePollingAddressSelector() //.UseServerHealthCheck(1) //.SetDiscoveryAutoUpdateJobInterval(new Client.Discovery.Implement.DiscoveryOptions(1)) //.UseToken(() => { var headers = JimuHttpContext.Current.Request.Headers["Authorization"]; return headers.Any() ? headers[0] : null; }) //.UseJoseJwtForOAuth<HttpAddress>(new Client.Auth.JwtAuthorizationOptions() //{ // ServerIp = "127.0.0.1", // ServerPort = 5001, // SecretKey = "test", // ExpireTimeSpan = new TimeSpan(1, 0, 0), // TokenEndpointPath = "/api/client/token", // ValidateLifetime = true, // CheckCredential = o => // { // if (o.UserName == "admin" && o.Password == "admin") // { // o.AddClaim("department", "IT部"); // } // else // { // o.Rejected("401", "acount or password incorrect"); // } // } //}) .Build(); app.UseJimu(host); host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseJimuSwagger(); // jimu client var host = new ApplicationClientBuilder(new ContainerBuilder()).Build(); app.UseJimu(host); host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // start jimu client host; var host = new ApplicationClientBuilder(new ContainerBuilder()) //.UseConsulForDiscovery(new Jimu.Client.Discovery.ConsulIntegration.ConsulOptions("127.0.0.1", 8500, "JimuService-")) //.UseDotNettyForTransfer() //.UseHttpForTransfer() //.UsePollingAddressSelector() .Build(); app.UseJimu(host); host.Run(); }
public static ApplicationClientBuilder UseToken( this ApplicationClientBuilder serviceHostBuilder, Func <string> getToken) { serviceHostBuilder.AddModule(containerBuilder => { containerBuilder.RegisterType <ServiceTokenGetter>().As <IServiceTokenGetter>().SingleInstance(); }); serviceHostBuilder.AddInitializer(componentRegister => { var tokenGetter = componentRegister.Resolve <IServiceTokenGetter>(); tokenGetter.GetToken = getToken; var logger = componentRegister.Resolve <ILogger>(); logger.Info($"[config]get token has been set"); }); return(serviceHostBuilder); }
public void Run(string clientSettingName = "JimuAppClientSettings", string serverSettingName = "JimuAppServerSettings") { IHostBuilder thisHostBuilder = null; ApplicationHostServer.Instance.BuildHost((hostBuilder, container) => { thisHostBuilder = hostBuilder; }).BuildServer(builder => { _serverBuilderAction?.Invoke(builder); IApplication hostClient = null; builder.AddServiceModule(x => { x.Register(c => hostClient.Container.Resolve <IServiceProxy>()).As <IServiceProxy>(); }).AddRunner(x => { var clientBuilder = new ApplicationClientBuilder(new ContainerBuilder(), clientSettingName); _clientBuilderAction?.Invoke(clientBuilder); hostClient = clientBuilder.Build(); hostClient.RunInServer(thisHostBuilder); }); }).Run(serverSettingName); }
static void Main(string[] args) { Console.WriteLine("Hello World, Service2 start..."); var hostClientBuilder = new ApplicationClientBuilder(new Autofac.ContainerBuilder()); IApplication hostClient = null; var hostServerBuilder = new ApplicationServerBuilder(new Autofac.ContainerBuilder()); hostServerBuilder.AddServiceModule(x => { x.Register(c => hostClient.Container.Resolve <IServiceProxy>()).As <IServiceProxy>(); }); var hostServer = hostServerBuilder.Build(); hostServer.RunAction(x => { hostClient = hostClientBuilder.Build(); hostClient.Run(); }); hostServer.Run(); Console.ReadLine(); }