首页 > 解决方案 > 无法将nodejs微服务与spring boot应用程序(zuul服务器)连接起来

问题描述

我正在尝试使用 zuul 服务器(api-gateway)将 node.js 微服务与 spring boot 应用程序连接起来。

zuul application.properties:

spring.application.name=api-gateway
hystrix.shareSecurityContext=true
eureka.client.service-url.default-zone=http://localhost:8761/eureka


zuul.routes.node-simple.serviceId=node-simple
zuul.routes.node-simple.path=/node-simple/**

zuul.routes.home.path=/home
zuul.routes.home.url=http://localhost:8080
zuul.sensitive-headers=Cookie,Set-Cookie
server.port=8080

节点js尤里卡配置

const client = new Eureka({
  instance: {
    id: appName,    
    instanceId: 'node',
    app: appName,
    hostName: 'localhost',
    ipAddr: '127.0.0.1',
    statusPageUrl: 'http://localhost:8200',
    port: {
      '$': PORT,
      '@enabled': 'true',
    },
    vipAddress: appName,
    dataCenterInfo: {
      '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
      name: 'MyOwn',
    }
  },
  eureka: {
    host: 'localhost',
    port: 8761,
    servicePath: '/eureka/apps/'
  }
});

当我尝试在 eureka 上访问 zuul (api-gateway) 的 URL 时,出现此错误:

负载均衡器没有可用于客户端的服务器:node-simple

标签: node.jsspringspring-bootnetflix-eurekanetflix-zuul

解决方案


这是我在 zuul 设置中的配置。zuul 设置从 Eureka 服务器获取路由信息

zuul.sensitive-headers= Cookie,Set-Cookie
zuul.strip-prefix=false
zuul.debug.request=true

spring.application.name= zuul-server
eureka.instance.preferIpAddress=true
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}

下面是我的尤里卡配置

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.server.enable-self-preservation=false

为了能够注册 nodejs 应用程序并在路由请求时找到它,我按照这里的教程进行操作。实现与 Eureka 服务器的连接并保持通信


推荐阅读