SpringCloud Study Notes (4) -- Zuul, springcloudzuul

Source: Internet
Author: User

SpringCloud Study Notes (4) -- Zuul, springcloudzuul

See Chapter 19th OF Spring Cloud official documentation

19. Router and Filter: Zuul

Routing is part of the microservice architecture. For example, "/" may be mapped to your web application, and "/api/users" may be mapped to your user service, "/api/shop" may be mapped to your shop service. Zuul is a JVM-based Router and Server Load balancer.

Zuul's rule engine can be written in any JVM language, with built-in support for Java and Groovy.

Note: configure the attribute zuul. max. host. connections has been replaced by two new attributes, zuul. host. maxTotalConnections and zuul. host. maxPerRouteConnections. Their default values are 200 and 20, respectively.

19.1 How to Include Zuul

19.2 Embedded Zuul Reverse Proxy

Spring Cloud has created an embedded Zuul proxy to facilitate general development. Its common use scenario is that a UI application wants to proxy calls of one or more backend services.

To use it, you need to add @ EnableZuulProxy annotation to the main class running Spring Boot, so that it can forward local calls to suitable services. By convention, a service named "users" will receive a request to locate/users from the proxy. The Proxy uses Ribbon to locate an instance and forward it, and all requests are added with circuit breakers. Once the circuit breaker is opened, the proxy will no longer try to connect to this service.

To skip some services, you can set zuul. ignored-services. If a service matches the ignore rule and is explicitly included in the route ing, it will not be ignored. For example

To better control the routing, you can specify the service ID and path, for example:

Another method is to use Ribbon to implement route access for multiple instances.

 

19.15.3 @ EnableZuulProxy VS @ EnableZuulServer

Spring Cloud Netflix provides a large number of Filters Based on the Zuul annotation. @ EnableZuulProxy contains all annotations installed in @ EnableZuulServer. To use an empty Zuul, use @ EnableZuulServer.

 

Code in a single word

Create two service providers, user-service and order-service. As for configuration and pom, they are the same as before. They mainly introduce eureka-client and then Configure Ports and the like.

Then, create a project zuul-demo. This project does not have any special configuration, no route configuration, but still has the routing function.

Start these four projects,

Then you can access

We can see that the host is localhost: 8090. This is the zuul-demo project, that is, we can access the services on order-service and user-service through zuul-demo, this is the role of the gateway.

The gateway is external. In addition, we should note that we have not configured any routing rules here, but still can make the correct routing, thanks to Eureka, if you do not have a registration center, you have to configure the routing rules if you want to route it again. However, to be safe, specify the routing rules.

Configure the following rules

 

Filter

19.15.7 How to Write a Pre Filter

 

 

 

Reference

Http://blog.didispace.com/spring-cloud-starter-dalston-6-2/

Http://blog.didispace.com/spring-cloud-starter-dalston-6-3/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.