Unable to retrieve instance from Eureka server using JS client

I’m having a problem trying to get a service URL discover by eureka.

I’m using eureka-js-client to connect to Eureka and for testing purposes I’ve created two microservices, I’ve called it: ms1 and ms2.

What I’ve tried is:

  • Start Eureka server to allow services register into it
  • Start ms1 and register into Eureka
  • Start ms2, register into Eureka and get ms1 URL.

To accomplish this I’ve launched eureka server as a Spring Boot app using @EnableEurekaServer. This part works fine, I can access http://localhost:8761/ and see the dashboard.

Then, in my microservices I’ve this configuration

this._client = new Eureka({
                instance: {
                    app: 'ms1',
                    instanceId: 'ms1',
                    hostName: 'localhost',
                    ipAddr: '127.0.0.1',
                    statusPageUrl: `http://localhost:${port ? port : this._port}`,
                    healthCheckUrl: `http://localhost:${port? port : this._port}/health`,
                    port: {
                        '$': port? port: this._port,
                        '@enabled': true,
                    },
                    vipAddress: 'myvip',
                    dataCenterInfo: {
                        '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
                        name: 'MyOwn',
                    },
                },
                eureka: {
                    host: 'localhost',
                    port: 8761,
                    servicePath: '/eureka/apps/'
                },
            })

And the same for ms2 changing the name.

When I run the project it output registered with eureka: ms1/ms1 and services seems to be registered in eureka correctly:
enter image description here

But now the problem is trying to get the URL of one of the two services. From either of the two services, if I try to get the Eureka instances I always get an empty list.

I have this code:

let instances: any = this.getClient().getInstancesByAppId(microserviceName);
let instance = null;
let url = ''
if (instances != null && instances.length > 0) {
    instance = instances[0];
    let protocol = instance.securePort["@enabled"] == "true" ? "https" : "http";
    url = `${protocol}//${instance.ipAddr}:${instance.port.$}/`
}

Where in “microserviceName” variable I’ve tried:

  • “ms1”
  • “MS1”
  • “ms1/ms1”

But the response is always an empty array with this output:

Unable to retrieve instances for appId: ms1

So, what’s the problem? Have I missed something? I think the flow is correct:

  1. Start Eureka server.
  2. Register services into server.
  3. Look for instances in the server.

Thanks in advance.