目錄
概述
建立工程microservice-gateway-zuul
pom.xml
application.yml
ZuulApplication
測試
檢視注冊服務
通路原服務
通過Zuul通路服務
小結
概述
建立工程microservice-gateway-zuul

pom.xml
microservice-gateway-zuul/pom.xml
<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>microservice-spring-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>microservice-gateway-zuul</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<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>
</dependency>
</dependencies>
</project>
application.yml
spring:
application:
name: microservice-gateway-zuul
server:
port: 8040
eureka:
client:
service-url:
defaultZone: http://user:[email protected]:8761/eureka
instance:
prefer-ip-address: true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
ribbon:
ConnectTimeout: 3000
ReadTimeout: 60000
ZuulApplication
com.itmuch.cloud.ZuulApplication
package com.itmuch.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
}
測試
檢視注冊服務
通路原服務
http://localhost:8010/movie/1
通過Zuul通路服務
http://localhost:8040/microservice-consumer-movie-ribbon/movie/1
說明:
1)通路的是zuul服務端口;
2)指定預設的服務名稱和對應的接口;
小結
1)上面示例最簡單的zuul示例;
==============================
QQ群:143522604
群裡有相關資源
歡迎和大家一起學習、交流、提升!
==============================