问题
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