Spring Cloud Netflix Eureka doesn't find eureka-js instances

女生的网名这么多〃 提交于 2019-12-11 06:56:04

问题


I have 3 microservices in Spring:

  • Netflix Eureka
  • A Producer
  • A Consumer

And another microservice written in NodeJs with Eureka-js-client

  • node-microservice

Spring Eureka dashboard lists all of them

Until now everything looks OK, but the problem is when I try to read my node-microservice instance in eureka server. While I successfully find employee-producer instance in this way

List<ServiceInstance> instances=discoveryClient.getInstances("employee-producer");
    ServiceInstance serviceInstance=instances.get(0);

I'm not able to find my node-microservice

List<ServiceInstance> instances=discoveryClient.getInstances("node-microservice");
    ServiceInstance serviceInstance=instances.get(0);

From debug the result is

node-microservice

const Eureka = require('eureka-js-client').Eureka;
const express = require('express');
const server = express();
server.use(express.json());
server.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});
server.listen(3001);
server.get('/', function (req, res) {
    res.send("CIaooo");
});



// example configuration
const client = new Eureka({
    // application instance information
    instance: {
        app: 'node-microservice',
        hostName: 'localhost',
        ipAddr: '127.0.0.1',
        port:  {
            '$': 3001,
            '@enabled': 'true',
        },
        vipAddress: 'jq.test.something.com',
        statusPageUrl: 'http://localhost:3001/info',
        dataCenterInfo:  {
            '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
            name: 'MyOwn',
        }
    },
    eureka: {
        // eureka server host / port
        host: 'localhost',
        port: 8761,
        servicePath: '/eureka/apps/'
    },
});

client.logger.level('debug');

client.start(function(error){
    console.log(error || 'complete')});

Other strange thing is that from spring debug I can list services, where also node-microservice is listed

What's wrong with my code?


回答1:


The problem is that in the instance object I didn't write instanceId (wasn't mentioned anywhere). I found this solution crawling the code and than in another project where there was also this field

instance: {
        app: 'node-microservice',
        instanceId: 'nodemicroservice',
        hostName: 'localhost',
        ipAddr: '127.0.0.1',
        port:  {
            '$': 3001,
            '@enabled': 'true',
        },
        vipAddress: 'nodemicroservice',
        statusPageUrl: 'http://localhost:3001/info',
        dataCenterInfo:  {
            '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
            name: 'MyOwn',
        },
        registerWithEureka: true,
        fetchRegistry: true
    },


来源:https://stackoverflow.com/questions/50965591/spring-cloud-netflix-eureka-doesnt-find-eureka-js-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!