Spring Cloud Netflix Documentation

repository·main·Indexed 26 days ago

https://github.com/spring-cloud/spring-cloud-netflix

Provides Netflix OSS integrations for Spring Boot applications, specifically focusing on service discovery and load balancing. It enables the creation of embedded Eureka servers and the integration of Eureka Clients for service registration and discovery. The documentation covers configuration via application properties, TLS authentication, health checks, and the management of Spring Cloud LoadBalancer retry behavior and metrics.

Tokens
5K
Snippets
13
Records
35
Agent score
89%

What's inside Spring Cloud Netflix

  1. Overview of Spring Cloud Netflix

    main
    Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot applications. It uses Spring Boot autoconfiguration and binds to the Spring Environment and other Spring programming model idioms. This allows developers to quickly enable and configure common distributed system patterns, such as Service Discovery via Eureka, using simple annotations to build large-scale distributed systems with battle-tested Netflix components.
  2. Overview of Spring Cloud Netflix features

    main

    Spring Cloud Netflix provides capabilities for service discovery within a Spring ecosystem. Key features include:

    • Service Discovery (Client): Eureka instances can be registered and clients can discover instances using Spring-managed beans.
    • Service Discovery (Server): An embedded Eureka server can be created using declarative Java configuration.
  3. Features of Spring Cloud Netflix

    main

    Spring Cloud Netflix provides the following core capabilities:

    • Service Discovery: Eureka instances can be registered and clients can discover instances using Spring-managed beans.
    • Embedded Eureka Server: An embedded Eureka server can be created using declarative Java configuration.
  4. Set up an embedded Eureka Server

    main

    To run your own Eureka discovery server, add the spring-cloud-starter-netflix-eureka-server dependency to your project and annotate your main configuration class with @EnableEurekaServer.

    @EnableEurekaServer
    @SpringBootApplication
    public class EurekaServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(EurekaServerApplication.class, args);
        }
    }
  5. Configure a Eureka Client in a Spring Boot application

    main

    To enable a Spring Boot application to act as a Eureka client (registering with a discovery server and discovering other services), add the spring-cloud-starter-netflix-eureka-client dependency to your project.

    By default, the client will attempt to contact a Eureka server at http://localhost:8761. This default location is controlled by the configuration key eureka.client.serviceUrl.defaultZone.

    @SpringBootApplication
    @RestController
    public class Application {
    
      @RequestMapping("/")
      public String home() {
        return "Hello World";
      }
    
      public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
      }
    }
  6. Configure Spring Cloud Netflix using application properties or command line switches

    main

    You can configure Spring Cloud Netflix features by specifying properties in any of the following locations:

    1. application.properties file
    2. application.yml file
    3. Command line switches

    Note that this list of properties is not exhaustive, as additional JAR files on your classpath may contribute further properties, and you can also define custom properties.

  7. Import project into Eclipse

    main

    You can import the project into Eclipse using two different methods:

    Use the m2e Eclipse plugin for Maven support. If you encounter errors related to POMs, ensure m2e is up to date or manually add the spring profile to your settings.xml to resolve Spring repositories.

    Without m2e plugin

    If you do not use m2e, you can generate Eclipse-specific project metadata using the eclipse:eclipse goal, then import the projects via File > Import > Existing Projects.

    $ ./mvnw eclipse:eclipse
  8. Secure the Eureka Server

    main

    To secure the Eureka Server, add spring-boot-starter-security to your classpath. You must explicitly disable CSRF protection for the /eureka/** endpoints so that Eureka clients can still communicate with the server.

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests((authz) -> authz
            .anyRequest().authenticated())
            .httpBasic(withDefaults());
        http.csrf().ignoringRequestMatchers("/eureka/**");
        return http.build();
    }