Skip to content

Very simple implementation of a microservice that uses Ribbon to connect to an Eureka server in order to discover the address of its dependencies

License

Notifications You must be signed in to change notification settings

jfcorugedo/sample-eureka-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Service Discovery Client using Ribbon

Quick summary

This sample application implements a service discovery client using Netflix open source Ribbon project.

It's a Spring based application. It uses Spring Boot to start Spring context and run the application and Spring Cloud Netflix to integrate Netflix Ribbon implementation into Spring.

##Version

  • Spring Boot 1.4.0
  • Spring Cloud 1.1.5

How do I get set up?

In order to use service discovery pattern in a common Spring Boot application only three steps are needed:

  • Add Spring Cloud dependencies:

    org.springframework.cloud spring-cloud-starter-eureka 1.1.5.RELEASE org.springframework.cloud spring-cloud-starter-hystrix 1.1.5.RELEASE

These dependencies add Ribbon client classes to the project as well as Neflix circuit breaker implementation: Hystrix.

  • Enable Service discovery during Spring Boot startup using the annotation @EnableEurekaClient and circuit breaker using annotation @EnableCircuitBreaker on the main class:

    @SpringBootApplication @EnableEurekaClient @EnableCircuitBreaker @RestController public class SngDemoConsumerApplication {
    ... }

  • Add some configuration. Two configuration files are needed:

bootstrap.yml

spring:
  application:
    name: consumer

application.yml

server:
  port: 8002 

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-server:8000/eureka/

These parameters tell the application where the service registry is available. The first time the application tries to call another service, Ribbon will try to resolve service name to a list of URLs calling any Eureka Server configured in these parameters.

Deployment instructions

The application starts as a normal Spring Boot application:

  • Run mvn install inside the proeject
  • Go to target folder
  • Run java -jar sng-demo-service-consumer-1.0.0-SNAPSHOT.jar
  • Optional: If you're using STS IDE you can use a view called Boot Dashboard to start/stop any Spring Boot project you have in your workspace

About

Very simple implementation of a microservice that uses Ribbon to connect to an Eureka server in order to discover the address of its dependencies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published