Microservice development architecture - Spring Cloud common problems and summary <1> Eureka common problems

      Personal GitHub address: https://github.com/leebingbin/

    In the process of using Spring Cloud, it is inevitable to encounter some problems. So make some conclusions about the common problems of Spring Cloud.

1. Frequently Asked Questions about Eureka


1.1 Eureka registration service is slow


    By default, the process of service registration to Eureka Server is slow. When developing or testing, it is often desirable to speed up this
process, thereby increasing productivity.

    The cause and solution of the problem:

    The registration of the service involves periodic heartbeats, once every 30 seconds by default (through the serviceUrl configured by the client). The service is only discovered by other clients if the metadata in the local caches of the instance, server and client are all the same (so 3 heartbeats may be required). The time interval can be modified with the parameter eureka.instance.leaseRenewal InSeconds to speed up the process of connecting clients to other services. In a production environment it's best to stick to the default, as there are some calculations inside the server that make assumptions about renewals.

    To sum up, to solve the problem of slow service registration, you only need to set eureka.instance.leaseRenewal InSeconds to a smaller value. This configuration is used to set the time interval for Eureka Client to send heartbeat to Eureka Server. The default is 30, and the unit is seconds. In a production environment, it is recommended to stick to the default values.

 

1.2 Slow or no logout of stopped microservice nodes

    In a development environment, it is often expected that Eureka Server can quickly and efficiently deregister a stopped microservice instance. However, due to the long period of Eureka Server cleaning invalid nodes (default 90 seconds) and the self-protection mode, it may encounter the problem of slow or even no logout of microservices. The solution is as follows:

    · Eureka Server Edge:

    Configure to turn off self-protection, and configure the interval for Eureka Server to clean up invalid nodes as needed.

eureka.server.enable-self-preservation
# 设为false, 关闭自我保护, 从而保证会注销微服务

eureka.server.eviction-interval-timer-in-ms
# 清理间隔(单位毫秒,默认是60 * 1000)

    · Eureka Client Edge:

    Configure the health check to be enabled, and configure the renewal time and expiration time as needed.    

eureka.client.healthcheck.enabled
# 设为true,开启健康检查(需要spring-boot-starter-actuator 依赖)

eureka.instance.lease-renewal-interval-in-seconds
# 续约更新时间间隔(默认是30秒)

eureka.instance.lease-expiration-duration-in-seconds
# 续约到期时间(默认90秒)

    It is worth noting that these configurations are only recommended for development or testing, and it is recommended to stick to the default values ​​for production environments.

 

Tips: Configuration example

# Eureka Server配置
eureka:
  server:
    enable-self-preservation:false
    eviction-interval-timer-in-ms:4000

 

# Eureka Client配置
eureka:
  client:
    healthcheck:
      enabled:true
  instance:
    lease-expiration-duration-inseconds:30
    lease-renewal-interval-in-seconds:10

 

    · Modifying Eureka's renewal frequency may break Eureka's self-protection feature; this also means that in a production environment, if you want to use Eureka's self-protection feature, you should stick to the default configuration.

 

1.3 Instance ID of custom microservice

    Instance ID is used to uniquely identify the microservice instance registered on Eureka Server. On the home page of Eureka Server, you can visually see the InstanceID of each microservice. For example, DESKTOP-6063U0F:CONFIG-SERVER:8273 in the figure below is the Instance ID.

    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}} . Of course, if you want to customize this part of the content, you only need to configure the eureka.instance.instance-id property in the microservice. The example is as follows:

spring:
  application:
    name:movieticketing-provider-user
eureka:
  instance:
    # 将 Instance ID 设置成IP: 端口的形式
    instance-id:${spring.cloud.client.ipAddress}:${server.port}

    In this way, the Instance ID of the microservice movieticketing-provider-user can be set to the form of IP:Port.

 

1.4 Summary and solution of Eureka's UNKNOWN problem

    Registration information UNKNOWN is a common problem for newbies. But often many newbies do not know that there are two kinds of UNKNOWN, one is the application name UNKNOWN, and the other is the application status UNKNOWN.

    1) Application name UNKNOWN

    The application name UNKNOWN is obviously inappropriate. First, the name of the microservice is not semantic enough, and it is impossible to intuitively see which microservice it is; more importantly, we often use the application name to consume the interface of the corresponding microservice.

    Generally speaking, there are two situations that can cause this problem:

    · The spring.application.name or eureka.instance.appname properties are not configured. If neither of these properties is configured, it will cause problems with the application name UNKNOWN.

    · Some older versions of SpringFox cause this problem, such as SpringFox 2.6.0. It is recommended to use a newer pending version (SpringFox 2.6.1 and above).

 

    2) Microservice instance status UNKNOWN

    Microservice instance state UNKNOWN is equally troublesome. Generally speaking, only microservices whose status is UP will be requested. This problem is generally caused by health checks.

    eureka.client.healthcheck.enabled=true must be set in application.yml, but not in bootstrap.yml, otherwise it will cause the problem of application status UNKNOWN in some scenarios.

    Tips:

    1) SpringFox is an open source API documentation framework based on Spring and Swagger, formerly swagger-springmvc [ http://springfox.io/ ].

    2) Swagger is a very popular API documentation framework, it can help us design, build, test, RESTful interface, and also generate RESTful interface documentation. http://swagger.io/

 

      

This article is an original article by the blogger, please indicate the source for reprinting!

https://my.oschina.net/u/3375733/blog/

Guess you like

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