<develop>:(Web 端)<无> ShopERP 服务注册与发现。

parent f281839c
...@@ -61,7 +61,7 @@ namespace CoreCms.Net.Utility.Consul ...@@ -61,7 +61,7 @@ namespace CoreCms.Net.Utility.Consul
Check = new AgentServiceCheck() Check = new AgentServiceCheck()
{ {
Interval = TimeSpan.FromSeconds(10),//多久检查一次心跳 Interval = TimeSpan.FromSeconds(10),//多久检查一次心跳
HTTP = $"http://{ip}:{port}/Health/Index",//健康检查地址 HTTP = $"http://{ip}:{port}/api/Health/Index",//健康检查地址
Timeout = TimeSpan.FromSeconds(5), //超时时间 Timeout = TimeSpan.FromSeconds(5), //超时时间
DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(5)//服务启动多久后注册 DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(5)//服务启动多久后注册
} }
......
...@@ -5,13 +5,14 @@ namespace ShopERP.WebApi.Controllers ...@@ -5,13 +5,14 @@ namespace ShopERP.WebApi.Controllers
/// <summary> /// <summary>
/// 健康检查 /// 健康检查
/// </summary> /// </summary>
[Route("[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController]
public class HealthController : Controller public class HealthController : Controller
{ {
[HttpGet] [HttpGet]
public IActionResult Index() public IActionResult Index()
{ {
return Ok(); return Ok("Health check...");
} }
} }
} }
...@@ -64,27 +64,5 @@ namespace CoreCms.Net.Web.WebApi.Controllers ...@@ -64,27 +64,5 @@ namespace CoreCms.Net.Web.WebApi.Controllers
} }
#endregion #endregion
#region 取消订单====================================================
/// <summary>
/// 取消订单
/// </summary>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiCallBack> CancelOrder([FromBody] FMStringId entity)
{
var jm = new WebApiCallBack();
if (string.IsNullOrEmpty(entity.id))
{
jm.msg = "请提交要取消的订单号";
return jm;
}
var ids = entity.id.Split(",");
jm = await _orderServices.CancelOrder(ids);
return jm;
}
#endregion
} }
} }
\ No newline at end of file
...@@ -24,12 +24,6 @@ ...@@ -24,12 +24,6 @@
创建订单 创建订单
</summary> </summary>
</member> </member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.OrderController.CancelOrder(CoreCms.Net.Model.FromBody.FMStringId)">
<summary>
取消订单
</summary>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Infrastructure.ApiExplorerIgnores.Apply(Microsoft.AspNetCore.Mvc.ApplicationModels.ActionModel)"> <member name="M:CoreCms.Net.Web.WebApi.Infrastructure.ApiExplorerIgnores.Apply(Microsoft.AspNetCore.Mvc.ApplicationModels.ActionModel)">
<summary> <summary>
自带的Controller与swagger3.0冲突,在此排除扫描 自带的Controller与swagger3.0冲突,在此排除扫描
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"applicationUrl": "http://localhost:2015" "applicationUrl": "http://localhost:6008"
} }
}, },
"$schema": "http://json.schemastore.org/launchsettings.json", "$schema": "http://json.schemastore.org/launchsettings.json",
......
using Ocelot.DependencyInjection; using Ocelot.DependencyInjection;
using Ocelot.Middleware; using Ocelot.Middleware;
using Ocelot.Provider.Consul;
using ShopERP.Ocelot.ApiGateWay.Infrastructure; using ShopERP.Ocelot.ApiGateWay.Infrastructure;
namespace ShopERP.Ocelot.ApiGateWay namespace ShopERP.Ocelot.ApiGateWay
...@@ -21,7 +22,8 @@ namespace ShopERP.Ocelot.ApiGateWay ...@@ -21,7 +22,8 @@ namespace ShopERP.Ocelot.ApiGateWay
builder.Configuration.AddJsonFile("ocelot.json", optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile("ocelot.json", optional: true, reloadOnChange: true);
//使用 Ocelot 接管代码 //使用 Ocelot 接管代码
builder.Services.AddOcelot(builder.Configuration); builder.Services.AddOcelot(builder.Configuration)
.AddConsul();
var app = builder.Build(); var app = builder.Build();
...@@ -39,8 +41,8 @@ namespace ShopERP.Ocelot.ApiGateWay ...@@ -39,8 +41,8 @@ namespace ShopERP.Ocelot.ApiGateWay
app.UseRouting(); app.UseRouting();
//配置双路由: API (/T1) 走 Ocelot ,其他请求正常走 .NET8 流程 //配置双路由: API (/T1) 走 Ocelot ,其他请求正常走 .NET8 流程
app.MapWhen(context=>context.Request.Path.StartsWithSegments("/T1"), app.MapWhen(context => context.Request.Path.StartsWithSegments("/T1"),
subApp=>subApp.UseOcelot().GetAwaiter().GetResult()); subApp => subApp.UseOcelot());
app.UseAuthorization(); app.UseAuthorization();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Consul" Version="1.7.14.7" /> <PackageReference Include="Consul" Version="1.7.14.7" />
<PackageReference Include="Ocelot" Version="24.0.1" /> <PackageReference Include="Ocelot" Version="24.0.1" />
<PackageReference Include="Ocelot.Provider.Consul" Version="24.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"Consul": { "Consul": {
"consulAddress": "http://127.0.0.1:8500", "consulAddress": "http://127.0.0.1:8500",
"serviceName": "api", "serviceName": "api_orderService",
"apiServiceName": "api" "apiServiceName": "api_orderService"
} }
} }
...@@ -9,16 +9,22 @@ ...@@ -9,16 +9,22 @@
"LoadBalancerOptions": { "LoadBalancerOptions": {
"Type": "RoundRobin" // 轮询 "Type": "RoundRobin" // 轮询
}, },
"DownstreamHostAndPorts": [
{
"Host": "127.0.0.1",
"Port": 5201 //服务端口
} //可以多个,自行负载均衡
],
//上游地址 //上游地址
"UpstreamPathTemplate": "/T1/{url}", //网关地址--url变量 //冲突的还可以加权重Priority "UpstreamPathTemplate": "/T1/{url}", //网关地址--url变量 //冲突的还可以加权重Priority
"UpstreamHttpMethod": [ "GET", "POST", "DELETE", "PUT" ] "UpstreamHttpMethod": [ "GET", "POST", "DELETE", "PUT" ],
"UseServiceDisConvery": true, //使用服务发现
"ServiceName": "api_orderService" //Consul服务名称
} }
] ],
"GlobalConfiguration": {
//Ocelot应用地址
"BaseUrl": "http://127.0.0.1:5200",
"ServiceDiscoveryProvider": {
//Consul地址
"Host": "127.0.0.1",
//Consul端口
"Port": 8500,
"Type": "Consul" //由Consul提供服务发现,每次请求Consul
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment