Search code examples
springcloudnetflix-eurekanetflixnetflix-ribbon

Spring Cloud Netflix - how to access Eureka/Ribbon from traditional web app?


Everything I found on the internet about Spring Cloud Netflix is about running microservices from Boot applications using @EnableEurekaClients and so on.

Now I'm trying to connect my logging microservice within a traditional war application (springmvc, jaxws etc) - piece of legacy which can not be converted to Boot or modified in any way (by technical task).

I've created a new maven module "log-server-client" that knows nothing about upper web layer and intended to be used as a simple dependency in any maven project.

How should I configure access to Spring Cloud Netflix for this simple dependency? At least, how to configure Eureka and Ribbon?

I just extracted some lines of code from RestTemplate and created my custom JmsTemplate (microservice works with jms remoting with apache camel and activemq), exactly how it is done in RestTemplate, but this code stil lacks connection to infrastructure

afaik, we can create a global singleton bean, run a separate thread from this bean, and run Boot app from this thread, but don't you think that it is very ugly and can lead to problems? How it really should be used?


Solution

  • Great question!

    One approach is to use a "sidecar". This seems to be a companion Spring Boot application that registers with the Eureka Server on behalf of your traditional web app.

    See e.g.:

    http://www.java-allandsundry.com/2015/09/spring-cloud-sidecar.html

    http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html#_polyglot_support_with_sidecar

    Another approach is to use the following library:

    "A small lib to allow registration of legacy applications in Eureka service discovery."

    https://github.com/sawano/eureka-legacy-registrar

    This library can be used outside of Spring Boot.