zuul 动态路由mysql_zuul和consul配置http路由转发

0. 服务注册的坑

用zuul和consul进行服务发现时,相同服务的端口不能相同,否则consul中的instance-id会相同,即使是不同ip也不能相同。

1. consul 安装

2. 配置zuul的application.yml

zuul的application.yml如下

server:

port: 8762

spring:

cloud:

consul:

discovery:

instance-id: ${spring.application.name}:${server.port}

prefer-ip-address: true

health-check-interval: 10s

hostname: ${spring.application.name}

service-name: ${spring.application.name}

enabled: true

register: true

host: 127.0.0.1 #consul-ip

port: 8500 #consul-port

enabled: true

http:

multipart:

location: ${user.dir}/temp

application:

name: rsapm-zuul

#logging:

# level:

# com.netflix: debug

zuul:

# prefix: /XXX

# ignored-services: '*'

sensitiveHeaders:

routes:

XXX-brain:

path: /brain/**

# strip-prefix: false

XXX-mysql-data:

path: /mysql/**

strip-prefix: false

host:

socket-timeout-millis: 60000

connect-timeout-millis: 60000

hystrix:

command:

default:

execution:

timeout:

enabled: false

isolation:

thread:

timeoutInMilliseconds: 60000

ribbon:

ReadTimeout: 60000

ConnectTimeout: 60000

其中,routes 为配zuul转发的路由表;command 为zuul转发http请求的超时时间等配置。

3. zuul的pom.xml (maven)

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">

4.0.0

com.XXX.XXX

XXX

0.0.1-SNAPSHOT

jar

org.springframework.boot

spring-boot-starter-parent

1.5.14.RELEASE

UTF-8

1.8

org.springframework.cloud

spring-cloud-starter-netflix-zuul

org.springframework.cloud

spring-cloud-starter-consul-discovery

org.springframework.cloud

spring-cloud-starter-openfeign

com.google.code.gson

gson

2.8.2

org.springframework.cloud

spring-cloud-dependencies

Edgware.RELEASE

pom

import

org.springframework.boot

spring-boot-maven-plugin

3. 配置被转发应用的application.yml中添加cosul配置

被转发应用的application.yml如下

server:

port: 8101

spring:

cloud:

consul:

discovery:

instance-id: ${spring.application.name}:${server.port}

prefer-ip-address: true

health-check-interval: 10s

hostname: ${spring.application.name}

service-name: ${spring.application.name}

enabled: true

register: true

host: 127.0.0.1 #consul-ip

port: 8500 #consul-port

enabled: true

4. 被转发应用的pom.xml (maven)添加依赖

org.springframework.cloud

spring-cloud-starter-consul-discovery

org.springframework.cloud

spring-cloud-starter-openfeign

org.springframework.cloud

spring-cloud-dependencies

Edgware.RELEASE

pom

import

org.springframework.boot

spring-boot-maven-plugin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值