Spring Cloud Netflix Eureka找不到eureka-js实例 [英] Spring Cloud Netflix Eureka doesn't find eureka-js instances
问题描述
我在春季有3种微服务:
I have 3 microservices in Spring:
- Netflix Eureka
- 制作人
- 消费者
另一个使用Eureka-js-client用NodeJs编写的微服务
And another microservice written in NodeJs with Eureka-js-client
- 节点微服务
Spring Eureka仪表板列出了所有这些
Spring Eureka dashboard lists all of them
直到现在一切看起来都还可以,但是问题是当我尝试在eureka服务器中读取我的 node-microservice 实例时.当我以这种方式成功找到员工-生产者实例
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);
通过调试,结果为
节点微服务
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')});
另一个奇怪的是,从spring调试中,我可以列出服务,其中还列出了节点微服务.
Other strange thing is that from spring debug I can list services, where also node-microservice is listed
我的代码怎么了?
推荐答案
问题是在实例对象中我没有写instanceId(在任何地方都没有提到).我发现此解决方案可对代码进行爬网,而不是在另一个也有该字段的项目中
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
},
这篇关于Spring Cloud Netflix Eureka找不到eureka-js实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!