├── gateway-reactor-gray ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── github │ │ └── lybgeek │ │ ├── ReactorGrayGateWayApplication.java │ │ ├── config │ │ └── GrayGatewayReactiveLoadBalancerClientAutoConfiguration.java │ │ ├── filter │ │ └── GrayReactiveLoadBalancerClientFilter.java │ │ ├── loadbalancer │ │ └── GrayLoadBalancer.java │ │ └── weight │ │ ├── model │ │ └── WeightMeta.java │ │ └── util │ │ └── WeightRandomUtils.java │ └── resources │ └── application.yml ├── hello-consumer ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── github │ │ └── lybgeek │ │ ├── HelloConsumerApplication.java │ │ └── controller │ │ ├── HelloController.java │ │ └── WeightController.java │ └── resources │ └── application.yml └── pom.xml /gateway-reactor-gray/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | gateway 7 | com.github.lybgeek 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway-reactor-gray 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-gateway 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-webflux 23 | 24 | 25 | 26 | com.alibaba.cloud 27 | spring-cloud-starter-alibaba-nacos-discovery 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-ribbon 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-loadbalancer 40 | 41 | 42 | 43 | org.apache.commons 44 | commons-lang3 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/java/com/github/lybgeek/ReactorGrayGateWayApplication.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class ReactorGrayGateWayApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ReactorGrayGateWayApplication.class,args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/java/com/github/lybgeek/config/GrayGatewayReactiveLoadBalancerClientAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.github.lybgeek.config; 7 | 8 | import com.github.lybgeek.filter.GrayReactiveLoadBalancerClientFilter; 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 10 | import org.springframework.cloud.gateway.config.LoadBalancerProperties; 11 | import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | @Configuration 16 | public class GrayGatewayReactiveLoadBalancerClientAutoConfiguration { 17 | public GrayGatewayReactiveLoadBalancerClientAutoConfiguration() { 18 | } 19 | 20 | 21 | 22 | @Bean 23 | @ConditionalOnMissingBean({GrayReactiveLoadBalancerClientFilter.class}) 24 | public GrayReactiveLoadBalancerClientFilter grayReactiveLoadBalancerClientFilter(LoadBalancerClientFactory clientFactory, LoadBalancerProperties properties) { 25 | return new GrayReactiveLoadBalancerClientFilter(clientFactory, properties); 26 | } 27 | 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/java/com/github/lybgeek/filter/GrayReactiveLoadBalancerClientFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek.filter; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | import com.github.lybgeek.loadbalancer.GrayLoadBalancer; 6 | import org.springframework.cloud.client.ServiceInstance; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalancerUriTools; 8 | import org.springframework.cloud.client.loadbalancer.reactive.DefaultRequest; 9 | import org.springframework.cloud.client.loadbalancer.reactive.Request; 10 | import org.springframework.cloud.client.loadbalancer.reactive.Response; 11 | import org.springframework.cloud.gateway.config.LoadBalancerProperties; 12 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 13 | import org.springframework.cloud.gateway.filter.GlobalFilter; 14 | import org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter; 15 | import org.springframework.cloud.gateway.support.DelegatingServiceInstance; 16 | import org.springframework.cloud.gateway.support.NotFoundException; 17 | import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; 18 | import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; 19 | import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; 20 | import org.springframework.core.Ordered; 21 | import org.springframework.http.HttpHeaders; 22 | import org.springframework.web.server.ServerWebExchange; 23 | import reactor.core.publisher.Mono; 24 | 25 | import java.net.URI; 26 | 27 | public class GrayReactiveLoadBalancerClientFilter implements GlobalFilter, Ordered { 28 | 29 | private static final Log log = LogFactory.getLog(ReactiveLoadBalancerClientFilter.class); 30 | private static final int LOAD_BALANCER_CLIENT_FILTER_ORDER = 10150; 31 | private final LoadBalancerClientFactory clientFactory; 32 | private LoadBalancerProperties properties; 33 | 34 | public GrayReactiveLoadBalancerClientFilter(LoadBalancerClientFactory clientFactory, LoadBalancerProperties properties) { 35 | this.clientFactory = clientFactory; 36 | this.properties = properties; 37 | } 38 | 39 | @Override 40 | public int getOrder() { 41 | return LOAD_BALANCER_CLIENT_FILTER_ORDER; 42 | } 43 | 44 | @Override 45 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 46 | URI url = (URI)exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR); 47 | String schemePrefix = (String)exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_SCHEME_PREFIX_ATTR); 48 | if (url != null && ("grayLb".equals(url.getScheme()) || "grayLb".equals(schemePrefix))) { 49 | ServerWebExchangeUtils.addOriginalRequestUrl(exchange, url); 50 | if (log.isTraceEnabled()) { 51 | log.trace(ReactiveLoadBalancerClientFilter.class.getSimpleName() + " url before: " + url); 52 | } 53 | 54 | return this.choose(exchange).doOnNext((response) -> { 55 | if (!response.hasServer()) { 56 | throw NotFoundException.create(this.properties.isUse404(), "Unable to find instance for " + url.getHost()); 57 | } else { 58 | URI uri = exchange.getRequest().getURI(); 59 | String overrideScheme = null; 60 | if (schemePrefix != null) { 61 | overrideScheme = url.getScheme(); 62 | } 63 | 64 | DelegatingServiceInstance serviceInstance = new DelegatingServiceInstance((ServiceInstance)response.getServer(), overrideScheme); 65 | URI requestUrl = this.reconstructURI(serviceInstance, uri); 66 | if (log.isTraceEnabled()) { 67 | log.trace("LoadBalancerClientFilter url chosen: " + requestUrl); 68 | } 69 | 70 | exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, requestUrl); 71 | } 72 | }).then(chain.filter(exchange)); 73 | } else { 74 | return chain.filter(exchange); 75 | } 76 | } 77 | 78 | protected URI reconstructURI(ServiceInstance serviceInstance, URI original) { 79 | return LoadBalancerUriTools.reconstructURI(serviceInstance, original); 80 | } 81 | 82 | private Mono> choose(ServerWebExchange exchange) { 83 | URI uri = (URI)exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR); 84 | GrayLoadBalancer loadBalancer = new GrayLoadBalancer(clientFactory.getLazyProvider(uri.getHost(), ServiceInstanceListSupplier.class), uri.getHost()); 85 | if (loadBalancer == null) { 86 | throw new NotFoundException("No loadbalancer available for " + uri.getHost()); 87 | } else { 88 | return loadBalancer.choose(this.createRequest(exchange)); 89 | } 90 | } 91 | 92 | private Request createRequest(ServerWebExchange exchange) { 93 | HttpHeaders headers = exchange.getRequest().getHeaders(); 94 | Request request = new DefaultRequest<>(headers); 95 | return request; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/java/com/github/lybgeek/loadbalancer/GrayLoadBalancer.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek.loadbalancer; 2 | 3 | import com.github.lybgeek.weight.model.WeightMeta; 4 | import com.github.lybgeek.weight.util.WeightRandomUtils; 5 | import org.apache.commons.lang3.ObjectUtils; 6 | import org.apache.commons.logging.Log; 7 | import org.apache.commons.logging.LogFactory; 8 | import org.springframework.beans.factory.ObjectProvider; 9 | import org.springframework.cloud.client.ServiceInstance; 10 | import org.springframework.cloud.client.loadbalancer.reactive.DefaultResponse; 11 | import org.springframework.cloud.client.loadbalancer.reactive.EmptyResponse; 12 | import org.springframework.cloud.client.loadbalancer.reactive.Request; 13 | import org.springframework.cloud.client.loadbalancer.reactive.Response; 14 | import org.springframework.cloud.loadbalancer.core.*; 15 | import org.springframework.http.HttpHeaders; 16 | import reactor.core.publisher.Flux; 17 | import reactor.core.publisher.Mono; 18 | 19 | import java.util.*; 20 | 21 | public class GrayLoadBalancer implements ReactorServiceInstanceLoadBalancer { 22 | private static final Log log = LogFactory.getLog(GrayLoadBalancer.class); 23 | private ObjectProvider serviceInstanceListSupplierProvider; 24 | private String serviceId; 25 | 26 | 27 | 28 | 29 | public GrayLoadBalancer(ObjectProvider serviceInstanceListSupplierProvider, String serviceId) { 30 | this.serviceId = serviceId; 31 | this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider; 32 | } 33 | 34 | 35 | @Override 36 | public Mono> choose(Request request) { 37 | HttpHeaders headers = (HttpHeaders) request.getContext(); 38 | if (this.serviceInstanceListSupplierProvider != null) { 39 | ServiceInstanceListSupplier supplier = (ServiceInstanceListSupplier)this.serviceInstanceListSupplierProvider.getIfAvailable(NoopServiceInstanceListSupplier::new); 40 | return ((Flux)supplier.get()).next().map(list->getInstanceResponse((List)list,headers)); 41 | } 42 | 43 | return null; 44 | 45 | 46 | } 47 | 48 | 49 | 50 | private Response getInstanceResponse(List instances,HttpHeaders headers) { 51 | if (instances.isEmpty()) { 52 | return getServiceInstanceEmptyResponse(); 53 | } else { 54 | return getServiceInstanceResponseWithWeight(instances); 55 | } 56 | } 57 | 58 | /** 59 | * 根据版本进行分发 60 | * @param instances 61 | * @param headers 62 | * @return 63 | */ 64 | private Response getServiceInstanceResponseByVersion(List instances, HttpHeaders headers) { 65 | String versionNo = headers.getFirst("version"); 66 | System.out.println(versionNo); 67 | Map versionMap = new HashMap<>(); 68 | versionMap.put("version",versionNo); 69 | final Set> attributes = 70 | Collections.unmodifiableSet(versionMap.entrySet()); 71 | ServiceInstance serviceInstance = null; 72 | for (ServiceInstance instance : instances) { 73 | Map metadata = instance.getMetadata(); 74 | if(metadata.entrySet().containsAll(attributes)){ 75 | serviceInstance = instance; 76 | break; 77 | } 78 | } 79 | 80 | if(ObjectUtils.isEmpty(serviceInstance)){ 81 | return getServiceInstanceEmptyResponse(); 82 | } 83 | return new DefaultResponse(serviceInstance); 84 | } 85 | 86 | /** 87 | * 88 | * 根据在nacos中配置的权重值,进行分发 89 | * @param instances 90 | * 91 | * @return 92 | */ 93 | private Response getServiceInstanceResponseWithWeight(List instances) { 94 | Map weightMap = new HashMap<>(); 95 | for (ServiceInstance instance : instances) { 96 | Map metadata = instance.getMetadata(); 97 | System.out.println(metadata.get("version")+"-->weight:"+metadata.get("weight")); 98 | if(metadata.containsKey("weight")){ 99 | weightMap.put(instance,Integer.valueOf(metadata.get("weight"))); 100 | } 101 | } 102 | WeightMeta weightMeta = WeightRandomUtils.buildWeightMeta(weightMap); 103 | if(ObjectUtils.isEmpty(weightMeta)){ 104 | return getServiceInstanceEmptyResponse(); 105 | } 106 | ServiceInstance serviceInstance = weightMeta.random(); 107 | if(ObjectUtils.isEmpty(serviceInstance)){ 108 | return getServiceInstanceEmptyResponse(); 109 | } 110 | System.out.println(serviceInstance.getMetadata().get("version")); 111 | return new DefaultResponse(serviceInstance); 112 | } 113 | 114 | private Response getServiceInstanceEmptyResponse() { 115 | log.warn("No servers available for service: " + this.serviceId); 116 | return new EmptyResponse(); 117 | } 118 | } -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/java/com/github/lybgeek/weight/model/WeightMeta.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek.weight.model; 2 | 3 | import java.util.Arrays; 4 | import java.util.Random; 5 | 6 | /** 7 | * 8 | * 权重元数据对象 9 | * 10 | */ 11 | public class WeightMeta { 12 | private final Random ran = new Random(); 13 | private final T[] nodes; 14 | private final int[] weights; 15 | private final int maxW; 16 | 17 | public WeightMeta(T[] nodes, int[] weights) { 18 | this.nodes = nodes; 19 | this.weights = weights; 20 | this.maxW = weights[weights.length - 1]; 21 | } 22 | 23 | /** 24 | * 该方法返回权重随机对象 25 | * @return 26 | */ 27 | public T random() { 28 | int index = Arrays.binarySearch(weights, ran.nextInt(maxW) + 1); 29 | if (index < 0) { 30 | index = -1 - index; 31 | } 32 | return nodes[index]; 33 | } 34 | 35 | public T random(int ranInt) { 36 | if (ranInt > maxW) { 37 | ranInt = maxW; 38 | } else if(ranInt < 0){ 39 | ranInt = 1; 40 | } else { 41 | ranInt ++; 42 | } 43 | int index = Arrays.binarySearch(weights, ranInt); 44 | if (index < 0) { 45 | index = -1 - index; 46 | } 47 | return nodes[index]; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | StringBuilder l1 = new StringBuilder(); 53 | StringBuilder l2 = new StringBuilder("[random]\t"); 54 | StringBuilder l3 = new StringBuilder("[node]\t\t"); 55 | l1.append(this.getClass().getName()).append(":").append(this.hashCode()).append(":\n").append("[index]\t\t"); 56 | for (int i = 0; i < weights.length; i++) { 57 | l1.append(i).append("\t"); 58 | l2.append(weights[i]).append("\t"); 59 | l3.append(nodes[i]).append("\t"); 60 | } 61 | l1.append("\n"); 62 | l2.append("\n"); 63 | l3.append("\n"); 64 | return l1.append(l2).append(l3).toString(); 65 | } 66 | } -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/java/com/github/lybgeek/weight/util/WeightRandomUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek.weight.util; 2 | 3 | import com.github.lybgeek.weight.model.WeightMeta; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | *  权重算法取自:@see https://www.ctolib.com/topics-61571.html 10 | * 11 | * 随机工具类 12 | * 13 | * 使用权重的集合Map构建随机元数据对象 14 | * 15 | * 比如: 16 | * 我们有3个url地址,他们的权重分别为1,2,3现在我们利用RandomUtil来根据权重随机获取url: 17 | * 18 | *

 
19 |   * 
20 |   * map.put(url1, 1); 
21 |   * map.put(url2, 2); 
22 |   * map.put(url3, 3); 
23 |   * RandomMeta md = WeightRandomUtils.buildWeightMeta(map);
24 |   * String weightRandomUrl = md.random(); 
25 |   * 
26 |   * 

27 | * 28 | * 29 | */ 30 | public class WeightRandomUtils { 31 | public static WeightMeta buildWeightMeta(final Map weightMap) { 32 | if(weightMap.isEmpty()){ 33 | return null; 34 | } 35 | final int size = weightMap.size(); 36 | Object[] nodes = new Object[size]; 37 | int[] weights = new int[size]; 38 | int index = 0; 39 | int weightAdder = 0; 40 | for (Map.Entry each : weightMap.entrySet()) { 41 | nodes[index] = each.getKey(); 42 | weights[index++] = (weightAdder = weightAdder + each.getValue()); 43 | } 44 | return new WeightMeta((T[]) nodes, weights); 45 | } 46 | 47 | public static void main(String[] args) { 48 | Map map = new HashMap<>(); 49 | map.put("v1",1); 50 | map.put("v2",2); 51 | WeightMeta nodes = WeightRandomUtils.buildWeightMeta(map); 52 | for(int i = 0; i < 10; i++){ 53 | new Thread(()->{ 54 | System.out.println(nodes.random()); 55 | }).start(); 56 | } 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /gateway-reactor-gray/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9082 3 | # 配置输出日志 4 | logging: 5 | level: 6 | org.springframework.cloud.gateway: TRACE 7 | org.springframework.http.server.reactive: DEBUG 8 | org.springframework.web.reactive: DEBUG 9 | reactor.ipc.netty: DEBUG 10 | 11 | #开启端点 12 | management: 13 | endpoints: 14 | web: 15 | exposure: 16 | include: '*' 17 | # 配置参考:https://www.cnblogs.com/babycomeon/p/11161073.html 18 | spring: 19 | application: 20 | name: gateway-reactor-gray 21 | cloud: 22 | nacos: 23 | discovery: 24 | server-addr: localhost:8848 25 | gateway: 26 | discovery: 27 | locator: 28 | enabled: true 29 | lower-case-service-id: true 30 | routes: 31 | - id: hello-consumer 32 | uri: grayLb://hello-consumer 33 | predicates: 34 | - Path=/hello/** 35 | # 通过访问http://localhost:9082/test/v1,来测试权重 36 | - id: hello-consumer-v1 37 | uri: lb://hello-consumer 38 | predicates: 39 | - Path=/test/** 40 | - Weight=group1, 8 41 | filters: 42 | - AddRequestHeader=hello, world 43 | - id: hello-consumer-v2 44 | uri: lb://hello-consumer 45 | predicates: 46 | - Path=/test/** 47 | - Weight=group1, 2 48 | filters: 49 | - StripPrefix=1 50 | 51 | -------------------------------------------------------------------------------- /hello-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | gateway 7 | com.github.lybgeek 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | hello-consumer 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | 21 | com.alibaba.cloud 22 | spring-cloud-starter-alibaba-nacos-discovery 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /hello-consumer/src/main/java/com/github/lybgeek/HelloConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | 7 | 8 | @SpringBootApplication 9 | public class HelloConsumerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(HelloConsumerApplication.class,args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /hello-consumer/src/main/java/com/github/lybgeek/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek.controller; 2 | 3 | import com.alibaba.nacos.api.NacosFactory; 4 | import com.alibaba.nacos.api.exception.NacosException; 5 | import com.alibaba.nacos.api.naming.NamingService; 6 | import com.alibaba.nacos.api.naming.pojo.Instance; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.util.CollectionUtils; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.LinkedHashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | @RestController 18 | @RequestMapping(value = "/hello") 19 | public class HelloController { 20 | 21 | @Value("${spring.application.name}") 22 | private String serviceName; 23 | 24 | @Value("${server.port}") 25 | private int servicePort; 26 | 27 | @Value("${spring.cloud.nacos.discovery.server-addr}") 28 | private String nacosServerAddr; 29 | 30 | 31 | @GetMapping(value="/info") 32 | public Map info() throws NacosException { 33 | NamingService namingService = NacosFactory.createNamingService(nacosServerAddr); 34 | Map metaData = new LinkedHashMap<>(); 35 | List instances = namingService.selectInstances(serviceName,true); 36 | if(!CollectionUtils.isEmpty(instances)){ 37 | for (Instance instance : instances) { 38 | if(servicePort == instance.getPort()){ 39 | metaData.put("ip",instance.getIp()); 40 | metaData.put("port",String.valueOf(instance.getPort())); 41 | metaData.putAll(instance.getMetadata()); 42 | } 43 | } 44 | } 45 | return metaData; 46 | 47 | 48 | } 49 | 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /hello-consumer/src/main/java/com/github/lybgeek/controller/WeightController.java: -------------------------------------------------------------------------------- 1 | package com.github.lybgeek.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | @RestController 10 | @RequestMapping(value = "/") 11 | public class WeightController { 12 | 13 | 14 | 15 | @GetMapping(value="/test/v1") 16 | public String testV1(HttpServletRequest request){ 17 | System.out.println("/test/v1:"+request.getHeader("hello")); 18 | return "/test/v1"; 19 | } 20 | 21 | @GetMapping(value="v1") 22 | public String v1(){ 23 | System.out.println("v1"); 24 | return "/v1"; 25 | } 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /hello-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | application: 5 | name: hello-consumer 6 | --- 7 | server: 8 | port: 7081 9 | spring: 10 | cloud: 11 | nacos: 12 | discovery: 13 | server-addr: localhost:8848 14 | metadata: 15 | version: v1 16 | profiles: dev 17 | 18 | --- 19 | server: 20 | port: 17083 21 | spring: 22 | cloud: 23 | nacos: 24 | discovery: 25 | server-addr: localhost:8848 26 | metadata: 27 | version: v2 28 | profiles: prod 29 | 30 | 31 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.github.lybgeek 8 | gateway 9 | 1.0-SNAPSHOT 10 | 11 | hello-consumer 12 | gateway-reactor-gray 13 | 14 | 15 | pom 16 | 17 | 18 | 1.0 19 | 1.8 20 | 21 | Hoxton.SR3 22 | 2.2.5.RELEASE 23 | 2.2.1.RELEASE 24 | 25 | 1.2.66 26 | 3.9 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-dependencies 36 | ${spring-cloud.version} 37 | pom 38 | import 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-parent 43 | ${spring-boot.version} 44 | pom 45 | import 46 | 47 | 48 | com.alibaba.cloud 49 | spring-cloud-alibaba-dependencies 50 | ${spring-cloud-alibaba.version} 51 | pom 52 | import 53 | 54 | 55 | com.alibaba 56 | fastjson 57 | ${fastjson.version} 58 | 59 | 60 | org.apache.commons 61 | commons-lang3 62 | ${common.lang3} 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-starter-actuator 72 | 73 | 74 | 75 | org.projectlombok 76 | lombok 77 | 1.18.10 78 | compile 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-starter-test 83 | test 84 | 85 | 86 | 87 | 88 | 89 | 90 | org.apache.maven.plugins 91 | maven-compiler-plugin 92 | 93 | ${jdk.version} 94 | ${jdk.version} 95 | 96 | 97 | 98 | org.springframework.boot 99 | spring-boot-maven-plugin 100 | ${spring-boot.version} 101 | 102 | 103 | 104 | build-info 105 | repackage 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | --------------------------------------------------------------------------------