本地开发动态网关不生效

Blade 未结 2 173
dubbo
dubbo 剑者 2024-06-06 16:54

一、该问题的重现步骤是什么?

本地启动 blade-gateway-ccc 端口8084  启动blade-auth-ccc

访问接口 

http://localhost:8084/blade-auth/oauth/token?tenantId=000000&username=1&password=c4ca4238a0b923820dcc509a6f75849b&grant_type=password&scope=all&type=account

提示转发不到docker内网IP 并不是我本机auth-ccc的ip

"Failed to handle request [GET http://localhost:8084/blade-auth/oauth/token?tenantId=000000&username=1&password=c4ca4238a0b923820dcc509a6f75849b&grant_type=password&scope=all&type=account]: Connection timed out: no further information: /172.17.0.3:8100"

1. 

2. 

3.

gateway.ccc.json配置

图片.png

图片.png

图片.png

二、你期待的结果是什么?实际看到的又是什么?

希望通过网关转发到配置的本地服务上

三、你正在使用的是什么产品,什么版本?在什么操作系统上?


四、请提供详细的错误堆栈信息,这很重要。


五、若有更多详细信息,请在下面提供。

2条回答
  • 2024-06-06 17:07
    断点 DynamicRouteServiceListener


    dynamicRouteServiceListener 配置是对的
    请求也走到了 本地的gateway 就是无法转发到本机
    
    怎么排查


    0 讨论(0)
  • 只是想优先转发到本地的服务可以重写下这个类的逻辑:org.springframework.cloud.loadbalancer.core.RoundRobinLoadBalancer

        private Response<ServiceInstance> processInstanceResponse(ServiceInstanceListSupplier supplier,

                                                                  List<ServiceInstance> serviceInstances) {


            // 注册中心无可用实例 返回空

            if (CollectionUtils.isEmpty(serviceInstances)) {

                return new EmptyResponse();

            }

            // 获取nacos上本地可用服务,如果有就优先路由到本地

            List<String> priorIpPattern = List.of(NetUtil.getLocalhostStr());

            String[] priorIpPatterns = priorIpPattern.toArray(new String[0]);

            List<ServiceInstance> priorIpInstances = serviceInstances.stream().filter(

                    (i -> PatternMatchUtils.simpleMatch(priorIpPatterns, i.getHost()))

            ).collect(Collectors.toList());

            if (!priorIpInstances.isEmpty()) {

                serviceInstances = priorIpInstances;

            }


            Response<ServiceInstance> serviceInstanceResponse = getInstanceResponse(serviceInstances);

            if (supplier instanceof SelectedInstanceCallback && serviceInstanceResponse.hasServer()) {

                ((SelectedInstanceCallback) supplier).selectedServiceInstance(serviceInstanceResponse.getServer());

            }

            System.out.println(serviceInstanceResponse.getServer().getServiceId() + "服务转发到:" + serviceInstanceResponse.getServer().getHost().concat(":").concat(String.valueOf(serviceInstanceResponse.getServer().getPort())));

            return serviceInstanceResponse;

        }


    作者追问:2024-06-07 10:29

    想走原来作者提供的逻辑,帮忙定位下是哪里的问题,困扰好几天了,团队现在协作开发不起来

    0 讨论(0)
提交回复