prateeak ojha prateeak ojha - 4 days ago 3
Node.js Question

How to Register Node app with Spring Cloud and Netflix's Eureka

I am trying hard to register my node app, with Netflix's Eureka , and after googling a lot, I am still looking for a solution . The max I can figure out is we have Prana but I got an issue which is still in the issue list of Prana (I guess it means my REST Template is not able to discover this app).

Sidecar , is another suggested solution , for which I am not getting any response . Apart from these two I have found a node module Eureka-Node-client , but none of them serve my purpose .

Answer

You can create a Sidecar application like you would create any spring-boot app:

@EnableSidecar
@SpringBootApplication
public class SideCarApplication {

    public static void main(final String[] args) {
        SpringApplication.run(SideCarApplication.class, args);
    }

}

The important thing is that you have to configure it to correctly register your actual service. Your application.yml should look like this:

server:
  port: 9999 -- the port your spring-boot sidecar is running
spring:
  application:
    name: nodeapplication -- the name will be your id in eureka

sidecar:
  port: 8000 -- the node applications port
  health-uri: http://localhost:8000/health.json -- the exposed health eindpoint of your node application

It is important to note that the healthpoint should return UP so your services status will be correct in eureka. The returned json for a healthy service :

{
  "status":"UP"
}

If you are having trouble setting up a spring-boot app, use https://start.spring.io/ to configure a project. Sadly there isn't a sidecar option to tick, but you will get the idea. You can do the same from STS (Spring Tool Suite).

The maven dependency for Sidecar (with spring-cloud as a parent):

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-sidecar</artifactId>
</dependency>