SpringCloud (e) micro-services gateway Zuul

1. Introduction Gateway Zuul

Zuul is Netflix OSS in one, is a JVM-based routing and server load balancer. Services Framework provides routing, monitoring, resiliency, security and other aspects. Zuul works with Eureka, Ribbon, Hystrix other components.

Zuul's core is a filter through which we can filter out a lot of extended features, such as:

  • 1) Dynamic Routing dynamically routing client requests to different backend service logic to do some processing, such as a plurality of aggregated data and services return.
  • 2) request monitor can monitor the entire system a request, a request response detailed log record, real-time traffic statistics and monitoring the current system

State control.

  • 3) certification authorization to do authentication on every request access, denial illegal request, to protect the back-end services.
  • 4) stress test stress test is a very important job, like some of the electricity supplier companies need to simulate more realistic user concurrency to ensure the stability of the system during major events. By Zuul
    can forward the request to the cluster dynamically back-end services, it can also identify the real test traffic and traffic to do some special treatment.
  • 5) gray gray release issued can guarantee the stability of the overall system, can be found in the initial gray when the adjustment problems, in order to ensure that the degree of influence.

2. Why use a gateway zuul

Different micro-services in general have different network addresses, and external clients may need to call multiple service interfaces Bio able to complete a business needs. For example, a movie ticket collection APP, might call micro-film classification services, users micro-service, micro-payment services. If the client and micro service to communicate directly, there will be the following questions:

  • # Multiple client requests for different micro-services, to increase in the complexity of the client
  • # Cross-domain request, the authentication process is relatively complex in certain complex scenes
  • # Each service requires a separate certification

3. The procedure is simple process

Front-end program to access the service through a specified micro gateway.
Here Insert Picture Description

4.Zuul gateway building

(1) create a maven of modul add dependencies in the pom

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>
</dependencies>

(2) add yml profile

server:
  port: 9998
spring:
  application:
    name: diplomaproject-managerzuul
eureka: #将此服务注册到eureka
  client:
    service-url:
      defaultZone: http://127.0.0.1:9999/eureka/
  instance:
    prefer-ip-address: true #可以跨域访问
zuul:
  routes:
    host:
      connect-timeout-millis: 15000 #HTTP连接超时大于Hystrix的超时时间
      socket-timeout-millis: 60000   #socket超时
    diplomaproject-person: #服务名称
      path: /user/** #配置请求url的请求规则
      serviceId: diplomaproject-person #指明eureka注册中心的服务id

(3) add a startup class

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableEurekaClient
@EnableZuulProxy //使用网关代理
public class ManagerZuulApplication {
    public static void main(String[] args) {
        SpringApplication.run(ManagerZuulApplication.class);
    }
}

(4) reboot and start the eureka network management agent service

Here Insert Picture Description

Published 77 original articles · won praise 81 · views 5868

Guess you like

Origin blog.csdn.net/qq_37356556/article/details/104882192