0

What I want to achieve is:

  • registering a node.js service in my eureka-server in heroku.

    So far i can register a regular eureka-client in my eureka-server in heroku, without problems. But i am getting really confused with the configuration when try with node.js service...

    I thought eureka-js-client was the solution, no success so far...

    Code below.

    const express = require('express');
    const path = require('path');
    const port = process.env.PORT || 3090;
    const app = express();
    app.use(express.static(__dirname));
    const bodyParser = require('body-parser');
    app.use(bodyParser.urlencoded({extended: false}));
    app.use(bodyParser.json());
    
    app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'index.html'))
    });
    
    const Eureka = require('eureka-js-client').Eureka;
    
    const eureka = new Eureka({
    instance: {
    app: 'sheila',
    hostName: 'localhost',
    ipAddr: '127.0.0.1',
    statusPageUrl: 'http://localhost:5000',
    healthCheckUrl: 'http://localhost:5000/health',
    port: {
    '$': 5000,
    '@enabled': 'true',
    },
    vipAddress: 'myvip',
    dataCenterInfo: {
    '@Class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
    name: 'MyOwn',
    },
    },
    eureka: {
    host: 'localhost',
    port: 8761,
    servicePath: '/eureka/apps/',
    },
    });
    eureka.logger.level('debug');
    eureka.start(function(error){
    console.log(error || 'complete');
    });
    
    // ------------------ Server Config --------------------------------------------
    var server = app.listen(5000, function () {
    var port = server.address().port;
    console.log('Listening at %s', port);
    });
    

First i've tried locally after running docker run -it -p 8761:8761 springcloud/eureka on my docker console. But i get this error:

Problem making eureka request { [Error: connect ECONNREFUSED 127.0.0.1:8761]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8761 }

if i run it as it is from a heroku service, It does not execute :( :(

I also tried by substituting the host for the url of my heroku eureka server, but then i get 401 or 404 errors. The eureka server requires a password which i added in my heroku client js .

Any ideas?

Sheila
  • 1
  • 2

1 Answers1

3

You need to include an instanceId which should be a unique identifier of this instance.

const eureka = new Eureka({
  instance: {
    instanceId:'sheila',
    app: 'sheila',
    hostName: 'localhost',
    ipAddr: '127.0.0.1',
    statusPageUrl: 'http://localhost:5000',
    healthCheckUrl: 'http://localhost:5000/health',
    port: {
      '$': 5000,
      '@enabled': 'true',
    },
    vipAddress: 'myvip',
    dataCenterInfo: {
      '@Class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
      name: 'MyOwn',
    },
  },
  eureka: {
    host: 'localhost',
    port: 8761,
    servicePath: '/eureka/apps/',
  },
});
JasonB
  • 6,243
  • 2
  • 17
  • 27
siven
  • 54
  • 2