Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
ShopERP
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杜龙飞
ShopERP
Commits
993d97ac
Commit
993d97ac
authored
Sep 05, 2025
by
PC-20220610JUCQ\Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
<develop>:(Web 端)<无> ShopERP 服务注册与发现。
parent
f281839c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
28 additions
and
47 deletions
+28
-47
CoreCms.Net.Utility/Consul/ConsulRegister.cs
+1
-1
CoreCms.Net.Web.WebApi/Controllers/HealthController.cs
+3
-2
CoreCms.Net.Web.WebApi/Controllers/OrderController.cs
+0
-23
CoreCms.Net.Web.WebApi/Doc.xml
+0
-6
CoreCms.Net.Web.WebApi/Properties/launchSettings.json
+1
-1
ShopERP.Ocelot.ApiGateWay/Program.cs
+5
-3
ShopERP.Ocelot.ApiGateWay/ShopERP.Ocelot.ApiGateWay.csproj
+1
-0
ShopERP.Ocelot.ApiGateWay/appsettings.json
+2
-2
ShopERP.Ocelot.ApiGateWay/ocelot.json
+15
-9
No files found.
CoreCms.Net.Utility/Consul/ConsulRegister.cs
View file @
993d97ac
...
@@ -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
)
//服务启动多久后注册
}
}
...
...
CoreCms.Net.Web.WebApi/Controllers/HealthController.cs
View file @
993d97ac
...
@@ -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..."
);
}
}
}
}
}
}
CoreCms.Net.Web.WebApi/Controllers/OrderController.cs
View file @
993d97ac
...
@@ -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
CoreCms.Net.Web.WebApi/Doc.xml
View file @
993d97ac
...
@@ -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冲突,在此排除扫描
...
...
CoreCms.Net.Web.WebApi/Properties/launchSettings.json
View file @
993d97ac
...
@@ -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"
,
...
...
ShopERP.Ocelot.ApiGateWay/Program.cs
View file @
993d97ac
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
().
GetResul
t
());
subApp
=>
subApp
.
UseOcelo
t
());
app
.
UseAuthorization
();
app
.
UseAuthorization
();
...
...
ShopERP.Ocelot.ApiGateWay/ShopERP.Ocelot.ApiGateWay.csproj
View file @
993d97ac
...
@@ -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>
...
...
ShopERP.Ocelot.ApiGateWay/appsettings.json
View file @
993d97ac
...
@@ -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
"
}
}
}
}
ShopERP.Ocelot.ApiGateWay/ocelot.json
View file @
993d97ac
...
@@ -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
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment