|
|
@ -44,7 +44,7 @@ return method.replace('.', '_') + "_response"; |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
public class ZuulConfig extends AlipayZuulConfiguration { |
|
|
|
public class MyConfig { |
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
|
... |
|
|
|
... |
|
|
@ -84,23 +84,18 @@ public class ZuulConfig extends AlipayZuulConfiguration { |
|
|
|
|
|
|
|
|
|
|
|
如果想要对微服务结果做更深一步处理,步骤如下: |
|
|
|
如果想要对微服务结果做更深一步处理,步骤如下: |
|
|
|
|
|
|
|
|
|
|
|
1. 新增一个类,继承`ZuulResultExecutor.java`,并重写`public String merge(T exchange, JSONObject responseData)`方法 |
|
|
|
1. 新增一个类,继承`GatewayResultExecutor.java`,并重写`String mergeResult(T request, String serviceResult)`方法 |
|
|
|
|
|
|
|
|
|
|
|
方法merge参数说明如下: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exchange:RequestContext对象 |
|
|
|
|
|
|
|
responseData:微服务端返回的结果 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
方法返回最终结果 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2. 配置自定义类 |
|
|
|
2. 配置自定义类 |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
public class SopGatewayApplication { |
|
|
|
@Configuration |
|
|
|
|
|
|
|
public class MyConfig { |
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
ApiConfig.getInstance().setZuulResultExecutor(new MyzuulResultExecutor()); |
|
|
|
static { |
|
|
|
SpringApplication.run(SopGatewayApplication.class, args); |
|
|
|
... |
|
|
|
|
|
|
|
ApiConfig.getInstance().setGatewayResultExecutor(new MyGatewayResultExecutor()); |
|
|
|
|
|
|
|
... |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|