How to register External Service (Non MSA) On Eureka Discovery registry How to register External Service (Non MSA) On Eureka Discovery registry docker docker

How to register External Service (Non MSA) On Eureka Discovery registry


Registering a java application with Eureka is not a big deal, because Netflix supplies a java Eureka client that is included in your classpath when using the spring-cloud-starter-netflix-eureka-client dependency. And Spring Boot will configure this client from your application properties.

Registering and application from outside the application code is different situation. You can certainly still do this.

I will just mention a little theory here, and then get to a suggested solution.

Theory

The basic way to do this, is to use the Eureka REST operations. This is an API where you can manually register/unregister service instances, and supply a regular heartbeat for Eureka to consider the service instance available.

It's really not a very large API, and with your current knownledge of Eureka client configuration you would probably have an easy time.

Solution with spring-cloud-netflix-sidecar

Spring Cloud already has your usecase covered! The approach here is that you will create a companion container for kibana, a sidecar. And the application in this container will be responsible for registering your service with Euerka. This type of application is very small, it will be quick to implement with Java and Spring Cloud.

Here's the documentation from Spring Cloud: Polyglot support with Sidecar

Here's a tutorial on it: Spring Cloud Netflix Sidecar Tutorial

And here's a repository that does this in a very simple way: Spring-Cloud-Sidecar_Tutorial

There is almost no code in the sidecar application, only this application class (taken from the repository above):

package com.craftcodecrew.lumen.service.sidecar;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.sidecar.EnableSidecar;@SpringBootApplication@EnableSidecarpublic class LumenServiceSidecarApplication {    public static void main(String[] args) {        SpringApplication.run(LumenServiceSidecarApplication.class, args);    }}

This configuration:

server:  port: 5678spring:  application:    name: lumen-serviceeureka:  client:    serviceUrl:      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}  instance:    preferIpAddress: truesidecar:  port: ${SIDECAR_PORT:8000}  health-uri: ${SIDECAR_HEALTH_URI:http://localhost:8000/health}  home-page-uri: ${SIDECAR_HOMEPAGE_URI:http://localhost:8000/}

And a very simple pom.xml.

As you can see, the sidecar library takes some configuration that you need to point to your kibana instance. So, they need to be on the same network. And also on the same network as Eureka.

Provided that your kibana container name is 'kibana', your config would look like this:

server:  port: 5678spring:  application:    name: kibanaeureka:  client:    serviceUrl:      defaultZone: ${EUREKA_URI:http://eureka:8761/eureka}  instance:    preferIpAddress: truesidecar:  port: ${SIDECAR_PORT:5601}  health-uri: ${SIDECAR_HEALTH_URI:http://kibana:5601/status}  home-page-uri: ${SIDECAR_HOMEPAGE_URI:http://kibana:5601/}

You could also control those values in environment variables configured in the docker-compose definition. Like so:

  kibana-sidecar:    image: kibana-sidecar    links:      - "kibana"    ports:      - "5678:5678"    environment:      - EUREKA_URI=<your_eureka_instance_uri>      - SIDECAR_PORT=5601      - SIDECAR_HEALTH_URI=http://kibana:5601/status      - SIDECAR_HOMEPAGE_URI=http://kibana:5601/    networks:      - cloud