SPRINGCLOUD16---Zuul-filter

Source: Internet
Author: User

 PackageCom.itmuch.cloud;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.cloud.netflix.zuul.EnableZuulProxy;ImportOrg.springframework.context.annotation.Bean, @SpringBootApplication @enablezuulproxy Public classzuulapplication { Public Static voidMain (string[] args) {Springapplication.run (zuulapplication.class, args); } @Bean PublicPrezuulfilter Prezuulfilter () {return NewPrezuulfilter (); }}
 PackageCom.itmuch.cloud;Importjavax.servlet.http.HttpServletRequest;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;ImportCom.netflix.zuul.ZuulFilter;ImportCom.netflix.zuul.context.RequestContext;//http://localhost: 8040/routes: {"/microservice-provider-user/**": "Microservice-provider-user"}//http://localhost: 8040/MICROSERVICE-PROVIDER-USER/SIMPLE/1 access the user microservices via Zuul and use filters Public classPrezuulfilterextendsZuulfilter {Private Static FinalLogger Logger = Loggerfactory.getlogger (prezuulfilter.class); @Override//determine if you want to use this filter in advance   Public BooleanShouldfilter () {return true; } @Override PublicObject Run () {//the logic of the filterHttpServletRequest request =Requestcontext.getcurrentcontext (). Getrequest (); String Host=Request.getremotehost (); PreZuulFilter.LOGGER.info ("Requested host:{}", host); return NULL; } @Override//Filter Type   PublicString FilterType () {return"Pre"; } @Override//execution order, the bigger the more back   Public intFilterorder () {return1; }}
Spring:  application:    name:microservice-gateway-zuulserver:  8040Eureka:  Client:    service-URL:      defaultzone:http://user:[email protected]:8761/ Eureka  instance:    prefertrue        hystrix.command. default. execution.isolation.thread.timeoutinmilliseconds:60000Ribbon:      60000
 spring:application:name:microservice -gateway-zuulserver:port:  8040eureka:client:service -url:defaultzone:http:  // user: [Email protected]:8761/eureka   Instance:prefer -ip-address: true  zuul:ignoredservices:microservice - Consumer-movie-ribbon-with-hystrix routes:microservice -provider-user:/user< Span style= "COLOR: #008000" >/**  
 spring:application:name:microservice -gateway-zuulserver:port:  8040eureka:client:service -url:defaultzone:http:  // user: [Email protected]:8761/eureka   Instance:prefer -ip-address: true  zuul:routes:abc:path: /user-path/**   Serviceid:microservice-provider-user  
Spring:  application:    name:microservice-gateway-zuulserver:  8040Eureka:  Client:    service-URL:      defaultzone:http://user:[email protected]:8761/ Eureka  instance:    prefertrueZuul:  routes:    ABC:       /user-url/**      http://192.168.85.1: 7900/    
Spring:application:name:microservice-gateway-Zuulserver:port:8040Eureka:client:service-url:defaultZone:http://User:[email Protected]:8761/eurekaInstance:prefer-ip-address:trueZuul:routes:abc:path:/user-url/**Service-id:microservice-provider-userribbon:eureka:enabled:falsemicroservice-provider-user: # This is rib. Bon Serviceid Ribbon:listofservers of the microservices to be requested:http://localhost: 7900,http://localhost: 7901
Spring:  application:    name:microservice-gateway-zuulserver:  8040Eureka:  Client:    service-URL:      defaultzone:http://user:[email protected]:8761/ Eureka  instance:    prefertrueZuul:  /API  Strip  falselogging: Level  :    Com.netflix:DEBUG
Spring:  application:    name:microservice-gateway-zuulserver:  8040Eureka:  Client:    service-URL:      defaultzone:http://user:[email protected]:8761/ Eureka  instance:    prefertrueZuul:  /simple  Strip  falselogging: Level  :    com.netflix:debug
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelversion>4.0.0 </modelVersion> <parent> <groupId>com.itmuch.cloud</groupId> <artifactid>mi Croservice-spring-cloud</artifactid> <version>0.0.1-SNAPSHOT</version> </parent> < Artifactid>microservice-gateway-zuul-filter</artifactid> <packaging>jar</packaging> < Properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties&gt    ;            <dependencies> <dependency> <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactid>spring-cloud-starter-eureka </artifactId> &LT;/DEPEndency> </dependencies></project> 

SPRINGCLOUD16---Zuul-filter

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.