Netflix Eureka

repository·master·Indexed 11 days ago

https://github.com/netflix/eureka

A RESTful service for service discovery, load balancing, and failover of middle-tier servers, optimized for cloud environments like AWS. It provides a centralized registry for service registration and discovery, including server and client implementations.

Tokens
1K
Snippets
3
Records
7
Agent score
91%

What's inside Eureka

  1. Overview of Eureka example components

    master

    The Eureka example demonstrates a three-participant architecture:

    • Eureka Server: A centralized registry for service registration and discovery.
    • Example Service: A service that registers itself with Eureka and exposes a REST endpoint.
    • Example Client: A client that uses Eureka to discover the service's registered REST endpoint and then queries it.

    Available Example Implementations

    • ExampleEurekaService: A basic service that registers with Eureka.
    • ExampleEurekaGovernatedService: A version of the service that uses Governator/Guice for dependency injection (DI) initialization.
      • Gradle command: ./gradlew :eureka-examples:runExampleGovernatedService
      • Distribution script: ./bin/ExampleEurekaGovernatedService
    • ExampleEurekaClient: A client demonstrating how to find a specific application/VIP via Eureka for communication.
  2. What is Eureka?

    master
    Eureka is a RESTful service designed for discovery, load balancing, and failover of middle-tier servers, primarily optimized for use in the AWS cloud. It serves as a critical component in Netflix's mid-tier infrastructure to manage service registration and discovery.
  3. Use the community-maintained jersey2 compatible Eureka client

    master

    The eureka-client-jersey2 library is a community-maintained version of the Eureka client designed for compatibility with Jersey 2.

    Important Note: This library is NOT maintained by Netflix and is not used internally by Netflix. Use it only if your environment requires Jersey 2 compatibility and you are comfortable using a community-supported implementation.

  4. Build Eureka from source

    master

    To build Eureka, you must use java8 because certain required libraries (such as servo) depend on it. Although java8 is required for the build environment, the source and target compatibility are configured to 1.7.

    Note: Ensure you have checked out a specific tag before performing a build.

  5. Run Eureka examples directly using Gradle

    master

    If you have a local Eureka server running, you can execute the example service and client directly using the Gradle wrapper from the root of the project.

    1. Start your local Eureka server.
    2. Run the example service: ./gradlew :eureka-examples:runExampleService. Wait for the message "_Service started and ready to process requests.._" to confirm registration.
    3. Run the example client: ./gradlew :eureka-examples:runExampleClient.
    ./gradlew :eureka-examples:runExampleService
    ./gradlew :eureka-examples:runExampleClient
  6. Set up a Eureka server for the examples

    master

    To run the Eureka examples, you must first set up a centralized Eureka server. Follow these steps:

    1. Configure properties: Edit eureka-server.properties and uncomment the two settings that disable safeguards to allow the demo server to start up faster.
    2. Build the application: Build the project to generate the necessary libraries and artifacts.
    3. Deploy to Tomcat: Copy the generated WAR artifact to your Tomcat deployment directory.
    4. Configure JVM options: Create or update tomcat/bin/setenv.sh with specific JAVA_OPTS to bypass synchronization delays used for the demo.
    5. Verify: Start Tomcat and access http://localhost:8080/eureka. The server's own Eureka client should appear in the registry within 30 seconds.
    # Deploy the WAR artifact
    cp ./eureka-server/build/libs/eureka-server-XXX-SNAPSHOT.war $TOMCAT_HOME/webapps/eureka.war
    
    # Add to tomcat/bin/setenv.sh
    JAVA_OPTS=" \
      -Deureka.waitTimeInMsWhenSyncEmpty=0 \
      -Deureka.numberRegistrySyncRetries=0"
  7. Run Eureka examples from a distribution zip

    master

    You can package the examples into a zip distribution for standalone execution.

    1. Start your local Eureka server.
    2. Build the distribution: ./gradlew :eureka-examples:distZip.
    3. Run the service from the distribution's bin directory: ./bin/ExampleEurekaService. Wait for the "_Service started and ready to process requests.._" confirmation.
    4. Run the client from the distribution's bin directory: ./bin/ExampleEurekaClient.
    ./gradlew :eureka-examples:distZip
    ./bin/ExampleEurekaService
    ./bin/ExampleEurekaClient