mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
可自定义路由拉取url
This commit is contained in:
@@ -78,3 +78,85 @@ public class OpenServiceConfig extends AlipayServiceConfiguration {
|
||||
```
|
||||
|
||||
到此准备工作就完成了,接下来可前往`新增接口`查看如何新增接口。
|
||||
|
||||
## 非Java项目接入
|
||||
|
||||
如果是非Java项目接入,如php,需要做到以下几点:
|
||||
|
||||
1. 提供路由配置接口
|
||||
2. 服务注册到nacos,并在nacos的metadata中指定接口路径,metadata的key为:`sop.routes.path`
|
||||
|
||||
- 提供路由配置接口
|
||||
|
||||
php应用提供的接口需要返回如下json内容:
|
||||
|
||||
```json
|
||||
{
|
||||
"serviceId": "story-service",
|
||||
"createTime": 1568603471646,
|
||||
"updateTime": 1568603471646,
|
||||
"description": null,
|
||||
"routeDefinitionList": [
|
||||
{
|
||||
"id": "alipay.category.get1.0",
|
||||
"name": "alipay.category.get",
|
||||
"version": "1.0",
|
||||
"uri": "lb://story-service",
|
||||
"path": "/alipay.category.get/",
|
||||
"order": 0,
|
||||
"ignoreValidate": 0,
|
||||
"status": 1,
|
||||
"mergeResult": 1,
|
||||
"permission": 0
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
json参数说明
|
||||
|
||||
|参数名|是否必填|说明|
|
||||
|:----|:----|:----|
|
||||
|serviceId |是|serviceId,服务id |
|
||||
|createTime |是|创建时间,Unix timestamp,毫秒 |
|
||||
|updateTime |是|修改时间,Unix timestamp,毫秒 |
|
||||
|description|否|描述|
|
||||
|routeDefinitionList元素参数说明|是|路由配置,见:routeDefinitionList元素参数说明|
|
||||
|
||||
routeDefinitionList元素参数说明
|
||||
|
||||
|参数名|是否必填|说明|
|
||||
|:----|:----|:----|
|
||||
|id |是|路由id,全局唯一,格式:接口名+版本号 |
|
||||
|name|是|接口名称|
|
||||
|version|是|版本号|
|
||||
|uri|是|格式:lb:// + serviceId,如:lb://order-service|
|
||||
|path|是|接口path,填端口号后面的path,如你的接口为http://open.domain.com:8080/goods/list_goods,填:/goods/list_goods|
|
||||
|order|是|固定填:0|
|
||||
|ignoreValidate|是|忽略签名验证,1:是,0:否|
|
||||
|status|是|启用状态,1:启用,2:禁用|
|
||||
|mergeResult|是|是否统一返回结果,1:是,0:否|
|
||||
|permission|是|是否需要权限访问,1:是,0:否|
|
||||
|
||||
- 服务注册到nacos
|
||||
|
||||
可前往nacos官网,参考[open-api](https://nacos.io/zh-cn/docs/open-api.html),使用nacos提供的接口完成服务注册
|
||||
|
||||
|
||||
- 在nacos的metadata中指定接口路径
|
||||
|
||||
伪代码如下:
|
||||
|
||||
```java
|
||||
Instance instance = new Instance();
|
||||
instance.setServiceName("order-service");
|
||||
instance.setIp("192.168.0.11");
|
||||
instance.setPort(8080);
|
||||
// 在nacos的metadata中指定接口路径
|
||||
instance.getMetadata().put("sop.routes.path", "/goods/list_goods");
|
||||
|
||||
namingService.registerInstance(serviceId, instance);
|
||||
```
|
||||
|
||||
完成以上步骤后,php服务注册到nacos,网关会触发监听事件,获取新注册的服务,然后会向你的服务拉取路由配置。
|
Reference in New Issue
Block a user