首页 > 代码库 > SpringCloud网关ZUUL集成consul

SpringCloud网关ZUUL集成consul

最近一直在搞基于springcloud的微服务开发,为了不限定微服务开发语言,服务发现决定采用consul不多说上代码

 

pom文件

 

<style></style>

<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>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.3.1.RELEASE</version>

<relativePath /> <!-- lookup parent from repository -->

</parent>

 

<groupId>com.tsx.springcloud.zuul</groupId>

<artifactId>start</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>

 

<name>SpringCloudZuulStart</name>

<url>http://maven.apache.org</url>

 

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>

 

<repositories>

<repository>

<id>dev-nexus</id>

<url>http://ob.yihecloud.com/nexus/content/groups/public/</url>

<snapshots>

<enabled>true</enabled>

<updatePolicy>always</updatePolicy>

</snapshots>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>dev-nexus</id>

<url>http://ob.yihecloud.com/nexus/content/groups/public/</url>

<snapshots>

<enabled>true</enabled>

<updatePolicy>always</updatePolicy>

</snapshots>

<releases>

<updatePolicy>never</updatePolicy>

</releases>

</pluginRepository>

</pluginRepositories>

 

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-dependencies</artifactId>

<version>Brixton.RELEASE</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>

 

<dependencies>

 

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-consul-discovery</artifactId>

<exclusions>

<exclusion>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot</artifactId>

</exclusion>

<exclusion>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-autoconfigure</artifactId>

</exclusion>

<exclusion>

<groupId>com.netflix.hystrix</groupId>

<artifactId>hystrix-core</artifactId>

</exclusion>

<!-- zuul 服务调用出错的jar包冲突 -->

<exclusion>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-netflix-core</artifactId>

</exclusion>

</exclusions>

</dependency>

 

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-feign</artifactId>

<version>1.1.7.RELEASE</version>

<exclusions>

<exclusion>

<groupId>com.netflix.hystrix</groupId>

<artifactId>hystrix-core</artifactId>

</exclusion>

</exclusions>

</dependency>

 

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-zuul</artifactId>

<version>1.1.7.RELEASE</version>

</dependency>

 

</dependencies>

 

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>

</project>

 

 

配置

 

<style></style>

spring.cloud.consul.host=10.1.11.90

spring.cloud.consul.port=8500

spring.cloud.consul.enabled=true

spring.cloud.consul.config.enabled=false

spring.cloud.consul.discovery.enabled=true

#register is true by default, if it‘s true, it will register the service

spring.cloud.consul.discovery.register=true

#refer to HystrixCommandProperties

#execution.isolation.thread.interruptOnTimeout=50000

 

#zuul retry

#zuul.retryable=true

zuul.routes.api-c.path=/api-c/**

zuul.routes.api-c.serviceId=service-c

 

#zuul routes 1

zuul.routes.host.path=/host/**

zuul.routes.host.serviceId=host

#use url to instead serviceId, and it will not support hystrix and ribbon

#zuul.routes.host.url=http://172.16.4.15:8080/

 

#zuul routes 2

zuul.routes.virtual.path=/virtual/**

zuul.routes.virtual.serviceId=virtual

#use url to instead serviceId, and it will not support hystrix and ribbon

#zuul.routes.virtual.url=http://172.16.4.102:8080/

 

zuul.routes.baidu.path=/baidu/**

zuul.routes.baidu.url=http://www.baidu.com/

 

SpringCloud网关ZUUL集成consul