0409-Service registration and discovery-Eurek Ribbon Feign common problems and solutions

One, Eureka

1.1. Configuration of Eureka Environment:

eureka.environment: string

Reference documentation:

https://github.com/Netflix/eureka/wiki/Configuring-Eureka

1.2. Configuration of Eureka DataCenter

eureka.datacenter: cloud

https://github.com/Netflix/eureka/wiki/Configuring-Eureka

Here it says: configure -Deureka.datacenter=cloud, so eureka will know it's on the AWS cloud

Dot notation and indentation can be used at the same time

1.3. Tips for Eureka to start self-protection

EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

Protected mode is mainly used for protection in scenarios where there is a network partition between a group of clients and Eureka Server. Once in protected mode, Eureka Server will try to protect the information in its service registry and no longer delete data in the service registry (that is, no microservices will be unregistered). 

https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication

1.4. How to solve the problem of slow registration service in Eureka?

eureka.instance.leaseRenewalIntervalInSeconds

Reference documentation:

http://cloud.spring.io/spring-cloud-static/Camden.SR1/#_why_is_it_so_slow_to_register_a_service

original:

Why is it so Slow to Register a Service?

Being an instance also involves a periodic heartbeat to the registry (via the client’s serviceUrl) with default duration 30 seconds. A service is not available for discovery by clients until the instance, the server and the client all have the same metadata in their local cache (so it could take 3 heartbeats). You can change the period using eureka.instance.leaseRenewalIntervalInSeconds and this will speed up the process of getting clients connected to other services. In production it’s probably better to stick with the default because there are some computations internally in the server that make assumptions about the lease renewal period.

translate:

As an example also involves periodic heartbeats with the registry, with a default duration of 30 seconds (via serviceUrl). The service is not available for client discovery (so 3 heartbeats may be required) until the instance, server, client all have the same metadata in the local cache. You can use the eureka.instance.leaseRenewalIntervalInSeconds configuration, which will speed up the process of connecting clients to other services. In production, it's best to stick with the default, because there are some calculations inside the server that make assumptions about renewals.

1.5. How to solve the problem that Eureka Server does not kick out the nodes that have been shut down?

Under the singleton STS, normal exit can be eliminated, if forced to close, it will not be eliminated

under the cluster,

server side:

eureka.server.enable-self- preservation (set to false to turn off self-preservation main)
eureka.server.eviction -interval-timer-in-ms cleaning interval (in milliseconds, default is 60*1000)

client side:

eureka.client.healthcheck.enabled = true enables                            health check (requires spring-boot-starter- actuator dependency)
eureka.instance.lease -renewal-interval-in-seconds=10         lease renewal interval (default 30 seconds)
eureka.instance.lease -expiration-duration-in-seconds=30 Lease expiration time (default 90 seconds)

Example:

Server side configuration:

eureka:
    server:
        enableSelfPreservation: false
        evictionIntervalTimerInMs: 4000

Client configuration:

eureka:
    instance:
        leaseRenewalIntervalInSeconds: 10
        leaseExpirationDurationInSeconds: 30

Note : Changing the update frequency of Eureka will break the self-protection function of the server, production mode does not allow shutdown

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

1.6. Eureka configure instanceId to display IP 

In Spring Cloud, the default value of a service's Instance ID is ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}} , ie 机器主机名:应用名称:应用端口 . Therefore, the service information seen in the Eureka Server home page is similar to the following: itmuch:microservice-provider-user:8000 . What if you want to customize the information in this section?

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    preferIpAddress: true
    instance-id: ${spring.cloud.client.ipAddress}:${server.port}

1.7. Summary of Eureka Configuration Best Practices

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

2. Ribbon

2.1. When customizing the configuration, the @Configuration and @ComponentScan packages should not overlap

2.2. When using RestTemplate, when you want to get a List, you should use an array instead of a List directly

        // wrong
        // List<User> list = restTemplate.getForObject("http://microservice-provider-user/list-all",List.class);
        // for (User u : list) {
        //         System.out.println(u);
        // }
        // right
        User[] users = restTemplate.getForObject("http://microservice-provider-user/list-all", User[].class);
        List<User> list2 = Arrays.asList(users);
        return list2;

3. Feign

3.1. When customizing the configuration, the @Configuration and @ComponentScan packages should not overlap

3.2. In the interface where @FeignClient is located, combined annotations such as @GetMapping are not supported

3.3. When using @PathVariable, you need to specify its value

3.4. Feign does not currently support complex objects as a parameter

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324599336&siteId=291194637