Zuul鐨勪娇鐢紝璺敱璁块棶鏄犲皠瑙勫垯

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zuul鐨勪娇鐢紝璺敱璁块棶鏄犲皠瑙勫垯相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/config' title='config'>config   澶氫釜   framework   鍚敤   涓嶇敤   鍥剧墖   res   鎻掍欢   info   

涓€銆乑uul鐨勪粙缁?/h1>

Zuul鍖呭惈浜嗗璇锋眰鐨?strong>璺敱鍜?strong>杩囨护涓や釜鏈€涓昏鐨勫姛鑳斤細

      鍏朵腑璺敱鍔熻兘璐熻矗灏嗗閮ㄨ姹傝浆鍙戝埌鍏蜂綋鐨勫井鏈嶅姟瀹炲姏涓婏紝鏄疄鐜板閮ㄨ闂粺涓€鍏ュ彛鍩虹鑰岃繃婊ゅ櫒鍔熻兘鍒欒礋璐e璇锋眰鐨勫鐞嗚繃绋嬭繘琛屽共棰勶紝鏄疄鐜拌姹傛牎楠屻€佹湇鍔¤仛鍚堢瓑鍔熻兘鐨勫熀纭€銆?/span>

銆€銆€Zuul鍜宔ureka杩涜鏁村悎锛屽皢Zuul鑷韩娉ㄥ唽鍒癊ureka鏈嶅姟娌荤悊涓嬬殑搴旂敤锛屽悓鏃朵粠Eureka涓幏寰楀叾浠栧井鏈嶅姟鐨勬秷鎭紝涔熷嵆浠ュ悗鐨勮闂井鏈嶅姟閮芥槸閫氳繃Zuul璺宠浆鍚庤幏寰楃殑銆?/span>

娉ㄦ剰锛歓uul鏈€缁堣繕鏄細娉ㄥ唽鍒癊ureka銆?/span>

鎻愪緵=浠g悊+璺敱+杩囨护涓夊ぇ鍔熻兘

浜屻€佽矾鐢辩殑鍩烘湰閰嶇疆

1銆佹柊寤哄伐绋嬶細microservicecloud-zuul-gateway-9527

2銆乸om.xml鏂囦欢娣诲姞渚濊禆鐨刯ar

     <dependencies>
        <!-- zuul璺敱缃戝叧 -->
        <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>
        </dependency>
        <!-- actuator鐩戞帶 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- hystrix瀹归敊 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!-- 鏃ュ父鏍囬厤 -->
        <dependency>
            <groupId>com.atguigu.springcloud</groupId>
            <artifactId>microservicecloud-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!-- 鐑儴缃叉彃浠?-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

 

3銆亂ml鏂囦欢鐨勯厤缃?/span>

server:
  port: 9527

spring:
  application:
    name: microservicecloud-zuul-gateway

# zuul娉ㄥ唽鍒癊ureka
eureka:
  client:
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka
  instance:
    instance-id: gateway-9527.com
    prefer-ip-address: true

info:
  app.name: yufeng-microcloud
  company.name: www.yufeng.com
  build.artifactId: $project.artifactId$
  build.version: $project.version$

4銆乭osts鐨勪慨鏀?/span>

锛?锛夋墦寮€ C:WindowsSystem32driversetchosts 鏂囦欢锛?/span>

锛?锛夊鍔狅細127.0.0.1 myzuul.com

5銆佷富鍚姩绫伙紝娣诲姞@EnableZuulProxy

@SpringBootApplication
@EnableZuulProxy
public class Zuul_9527_StartSpringCloudApp
{
    public static void main(String[] args)
    {
        SpringApplication.run(Zuul_9527_StartSpringCloudApp.class);
    }
}

6銆佹祴璇?/span>

锛?锛夊惎鍔ㄤ笁涓猠ureka闆嗙兢, 涓€涓猰icroservicecloud-provider-dept-8001锛屽惎鍔ㄨ矾鐢辩綉鍏冲井鏈嶅姟锛?/span>

锛?锛変笉鐢ㄨ矾鐢卞拰鍚姩璺敱鐨勭粨鏋滀竴鏍凤紱

涓嶇敤璺敱锛歨ttp://localhost:8001/dept/get/2

鍚敤璺敱锛歨ttp://myzuul.com:9527/microservicecloud-dept/dept/get/2          

鎶€鏈浘鐗? src=

鎶€鏈浘鐗? src=

 涓夈€佽矾鐢辫闂槧灏勮鍒?/span>

 浠ヤ笂浣跨敤 http://myzuul.com:9527/microservicecloud-dept/dept/get/2 璁块棶锛屽垯鏆撮湶鍑轰簡璋冪敤鐨勫井鏈嶅姟鍚嶄负 microservicecloud-dept锛涗负浜嗕笉鏆撮湶鍑哄井鏈嶅姟鐨勭湡姝e悕绉帮紝浣跨敤璺敱璁块棶鏄犲皠锛?/span>

1銆佸湪yml鏂囦欢涓鍔犺矾鐢辨槧灏?/span>

# 璺敱鏄犲皠
zuul:
  routes:
    mydept:
      serviceId: microservicecloud-dept
      path: /mydept/**

serviceId锛氭槧灏勭殑鏈嶅姟鍚嶏紱path锛氭槧灏勬垚涓虹殑璺緞锛?/span>

鍦▂ml淇敼涔嬪墠浣跨敤锛歨ttp://myzuul.com:9527/microservicecloud-dept/dept/get/2  璁块棶锛?/span>

鍦▂ml淇敼涔嬪悗浣跨敤锛歨ttp://myzuul.com:9527/mydept/dept/get/2  璁块棶锛?/span>

2銆佹鏃朵娇鐢?nbsp;http://myzuul.com:9527/microservicecloud-dept/dept/get/2  鍜?nbsp;http://myzuul.com:9527/mydept/dept/get/2  閮藉彲浠ユ垚鍔熺殑璋冪敤璇ユ帴鍙o紝杩樻槸浼氭毚闇茶皟鐢ㄧ殑寰湇鍔″悕涓簃icroservicecloud-dept锛涙墍浠ラ渶瑕佸幓璁╀娇鐢?nbsp;http://myzuul.com:9527/microservicecloud-dept/dept/get/2  閾炬帴涓嶈兘澶熻闂紱

锛?锛夊洜姝わ紝闇€瑕佸湪yml鏂囦欢涓鍔犲師鏈嶅姟鐨勫拷鐣ワ細

# 璺敱鏄犲皠
zuul:
  ignored-services: microservicecloud-dept
  routes:
    mydept:
      serviceId: microservicecloud-dept
      path: /mydept/**

ignored-services:鐗瑰埆娉ㄦ剰姝ゅ鐨勯厤缃€傞€氳繃閰嶇疆姝ら€夐」锛岄檺鍒朵笉鑳介€氳繃璁块棶鏈嶅姟鍚嶅幓璁块棶寰湇鍔?/span>

濡傛灉鎯虫妸鍏朵粬寰堝鐨勫井鏈嶅姟閮介€氳繃閰嶇疆蹇界暐鎺夌湡瀹炶闂矾寰勫垯鐩存帴浣跨敤 ”*” 鏉ヤ唬鏇裤€?/span>

锛?锛夐噸鍚井鏈嶅姟

<1> 浣跨敤鍘熻矾寰勮闂姤閿欙紝http://myzuul.com:9527/microservicecloud-dept/dept/get/2 

鎶€鏈浘鐗? src=

 <2> 浣跨敤璺敱鏄犲皠璺緞鍙互姝e父璁块棶锛歨ttp://myzuul.com:9527/mydept/dept/get/2

鎶€鏈浘鐗? src=

 锛?锛夊湪瀹為檯鐨勪娇鐢ㄦ椂鍊欙紝鏈夊緢澶氫釜鏈嶅姟鍣ㄩ渶瑕侀檺鍒朵笉鑳介€氳繃鏈嶅姟鍚嶅幓璁块棶锛涘垯鍦▂ml鍋氬涓嬬殑淇敼锛?/span>

# 璺敱鏄犲皠
zuul:
  ignored-services: "*"
  routes:
    mydept:
      serviceId: microservicecloud-dept
      path: /mydept/**

娴嬭瘯缁撴灉涓庝笂闈㈢殑缁撴灉涓€鏍凤紱

 

3銆佽缃粺涓€鍏叡鍓嶇紑

锛?锛変慨鏀箉ml鏂囦欢锛屽涓嬫墍绀?/span>

# 璺敱鏄犲皠
zuul:
  prefix: /yufeng
  ignored-services: "*"
  routes:
    mydept:
      serviceId: microservicecloud-dept
      path: /mydept/**

锛?锛夋祴璇?/span>

<1> 鍦ㄦ祻瑙堝櫒涓墦寮€锛歨ttp://myzuul.com:9527/mydept/dept/get/2锛屾姤閿欏涓嬶細

鎶€鏈浘鐗? src=

 <2> 鍦ㄦ祻瑙堝櫒涓墦寮€锛歨ttp://myzuul.com:9527/yufeng/mydept/dept/get/2锛屽彲浠ユ甯歌闂紱

鎶€鏈浘鐗? src=

 

以上是关于Zuul鐨勪娇鐢紝璺敱璁块棶鏄犲皠瑙勫垯的主要内容,如果未能解决你的问题,请参考以下文章

gulp4.0鐨勪娇鐢ㄥ拰gulpfile.js浠诲姟閰嶇疆

linux缁冧範

macOS閿洏鏄犲皠

NLog璺敱瑙勫垯鍜屼笂涓嬫枃淇℃伅

Photon Server鍒濊瘑(涓? ---ORM鏄犲皠鏀硅繘