Commit 4c7291cf by Nepxion

新增用户自定义和编程灰度路由策略

parent aaa57beb
......@@ -46,6 +46,12 @@
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-strategy-extension-service</artifactId>
<version>${discovery.plugin.version}</version>
</dependency>
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-config-center-extension-nacos</artifactId>
<version>${discovery.plugin.version}</version>
</dependency>
......
......@@ -15,6 +15,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.extension.MyDiscoveryEnabledAdapter;
import com.nepxion.discovery.plugin.example.extension.MyDiscoveryListener;
import com.nepxion.discovery.plugin.example.extension.MyLoadBalanceListener;
import com.nepxion.discovery.plugin.example.extension.MyRegisterListener;
......@@ -49,4 +50,9 @@ public class DiscoveryApplicationA1 {
public MySubscriber mySubscriber() {
return new MySubscriber();
}
@Bean
public MyDiscoveryEnabledAdapter MyDiscoveryEnabledAdapter() {
return new MyDiscoveryEnabledAdapter();
}
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
* @version 1.0
*/
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -19,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@ConditionalOnProperty(name = PluginConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-springcloud-example-a")
public class AFeignImpl extends AbstractFeignImpl implements AFeign {
private static final Logger LOG = LoggerFactory.getLogger(AFeignImpl.class);
@Autowired
private BFeign bFeign;
......@@ -27,7 +31,7 @@ public class AFeignImpl extends AbstractFeignImpl implements AFeign {
value = doInvoke(value);
value = bFeign.invoke(value);
System.out.println("调用路径:" + value);
LOG.info("调用路径:{}", value);
return value;
}
......
......@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
* @version 1.0
*/
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -19,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@ConditionalOnProperty(name = PluginConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-springcloud-example-b")
public class BFeignImpl extends AbstractFeignImpl implements BFeign {
private static final Logger LOG = LoggerFactory.getLogger(BFeignImpl.class);
@Autowired
private CFeign cFeign;
......@@ -27,7 +31,7 @@ public class BFeignImpl extends AbstractFeignImpl implements BFeign {
value = doInvoke(value);
value = cFeign.invoke(value);
System.out.println("调用路径:" + value);
LOG.info("调用路径:{}", value);
return value;
}
......
......@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
* @version 1.0
*/
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
......@@ -18,11 +20,13 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@ConditionalOnProperty(name = PluginConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-springcloud-example-c")
public class CFeignImpl extends AbstractFeignImpl implements CFeign {
private static final Logger LOG = LoggerFactory.getLogger(CFeignImpl.class);
@Override
public String invoke(@RequestBody String value) {
value = doInvoke(value);
System.out.println("调用路径:" + value);
LOG.info("调用路径:{}", value);
return value;
}
......
......@@ -43,6 +43,14 @@ spring.application.config.path=classpath:rule.xml
# spring.application.group.key=group
# spring.application.group.key=application
# Plugin strategy config
# 开启和关闭用户自定义和编程灰度路由策略的控制,包括跟业务无关(例如:不允许某个服务器的IP地址或者某个版本被负载均衡到)和业务数据(例如用户根据业务参数的不同,负载均衡到不同的服务器)有关两种,该功能只支持服务,不支持网关。缺失则默认为true
spring.application.strategy.control.enabled=true
# 开启和关闭用户自定义和编程灰度路由策略的业务有关性的控制。一旦关闭,从业务接口无法把数据传递到上下文对象(StrategyContext);一旦开启,需要设置下面的scan.packages。缺失则默认为true
spring.application.strategy.business.context.control.enabled=true
# 用户自定义和编程灰度路由策略的时候,需要指定对业务Controller类的扫描路径,以便传递上下文对象
spring.application.strategy.business.scan.packages=com.nepxion.discovery.plugin.example.feign
# Swagger config
swagger.service.base.package=com.nepxion.discovery.plugin.admincenter.endpoint
swagger.service.description=Admin Center Restful APIs
......
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