############Zuul简单使用################

1、pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>eureka-client-feign-hystrix-zuul</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-client-feign-hystrix-zuul</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

2、添加注解

package com.test.eurekaclientfeign;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean; @SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableHystrix
@EnableZuulProxy
public class EurekaClientFeignHystrixZuulApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientFeignHystrixZuulApplication.class, args);
} @Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}

3、application.yml配置文件

spring:
application:
name: eureka-client-feign-hystrix-zuul #应用名
logging: #logging日志配置
level:
root: INFO
org.hibernate: INFO
server:
port: 8669 #服务端口 eureka:
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8661/eureka
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always

这样就完成了,只是这种方式访问,需要添加serviceID访问

例如:

#不使用Zuul访问
http://192.168.137.1:8664/user/1 #使用Zuul访问,其中eureka-client-user为serviceId
http://192.168.137.1:8669/eureka-client-user/user/4

###############自己配置Zuul##################

在application.yml添加如下的配置

spring:
application:
name: eureka-client-feign-hystrix-zuul #应用名
logging: #logging日志配置
level:
root: INFO
org.hibernate: INFO
server:
port: 8669 #服务端口 eureka:
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8661/eureka
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
zuul:
routes:
eureka-client-user: /myuser/** #将serviceID = eureka-client-user 简化为 /myuser

最新文章

  1. Java程序设计之正则表达式
  2. class命名
  3. Java printf
  4. Dubbo集成Spring与Zookeeper实例
  5. Selenium2学习-021-WebUI自动化实战实例-019-设置浏览器窗口位置大小
  6. 【Stage3D学习笔记续】山寨Starling(十一):Touch事件体系
  7. 我也来学着写写WINDOWS服务-解析xml抓取数据并插入数据库
  8. ACM生活总结
  9. Github实例教程-创建库、创建主页
  10. 以Tomcat+Mysql为例,实现Docker多容器连接
  11. Apache Storm
  12. elasticsearch视频
  13. rabbitMQ的安装和创建用户
  14. Hihocoder 1329 平衡树&#183;Splay(平衡树)
  15. Subversion版本控制系统的安装和操作.
  16. 字符串最长子串匹配-dp矩阵[转载]
  17. 解决IE下载 apk/ipa 变成zip:Android 手机应用程序文件下载服务器 配置解决方法
  18. ELMAH--Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components 77 out of 90 rated th
  19. C语言:结构体和联合体(共用体)
  20. postgresql----Gist索引

热门文章

  1. filebeat收集nginx的json格式日志
  2. dedecms织梦移站后替换数据库中文件路径命令
  3. mysql数据库表自增ID批量清零 AUTO_INCREMENT = 0
  4. svn使用教程(收藏)
  5. touch cyusbConfig.cmake
  6. Linux修改mysql配置文件
  7. 使用GDI+加载32位的位图或者PNG图片(具有透明通道)
  8. HttpServlet容器响应Web客户请求流程?
  9. 当心JavaScript奇葩的逗号表达式
  10. C#写入文件内容时提示:文件正被另一个人或程序使用