Mitro
Mitro

Reputation: 1260

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

I have 3 microservices in Spring:

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

Spring Eureka dashboard lists all of them instances

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 not found

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

enter image description here

What's wrong with my code?

Upvotes: 1

Views: 1735

Answers (1)

Mitro
Mitro

Reputation: 1260

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
    },

Upvotes: 3

Related Questions