--- server: port: 1004 context-path: / spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8 username: mybatis_ssm password: xiaoli jpa: hibernate: ddl-auto: update show-sql: true application: name: microservice-student profiles: provider-hystrix-1004 eureka: instance: hostname: localhost appname: microservice-student instance-id: microservice-student:1004 prefer-ip-address: true client: service-url: defaultZone: http://eureka2001.javaxl.com:2001/eureka/,http://eureka2002.javaxl.com:2002/eureka/,http://eureka2003.javaxl.com:2003/eureka/ info: groupId: com.javaxl.testSpringcloud artifactId: microservice-student-provider-hystrix-1004 version: 1.0-SNAPSHOT userName: http://47.100.191.44 phone: 123456 hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 1500 --- server: port: 1005 context-path: / spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8 username: mybatis_ssm password: xiaoli jpa: hibernate: ddl-auto: update show-sql: true application: name: microservice-student profiles: provider-hystrix-1005 eureka: instance: hostname: localhost appname: microservice-student instance-id: microservice-student:1005 prefer-ip-address: true client: service-url: defaultZone: http://eureka2001.javaxl.com:2001/eureka/,http://eureka2002.javaxl.com:2002/eureka/,http://eureka2003.javaxl.com:2003/eureka/ info: groupId: com.javaxl.testSpringcloud artifactId: microservice-student-provider-hystrix-1005 version: 1.0-SNAPSHOT userName: http://47.100.191.44 phone: 123456 hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 1500 --- server: port: 1006 context-path: / spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8 username: mybatis_ssm password: xiaoli jpa: hibernate: ddl-auto: update show-sql: true application: name: microservice-student profiles: provider-hystrix-1006 eureka: instance: hostname: localhost appname: microservice-student instance-id: microservice-student:1006 prefer-ip-address: true client: service-url: defaultZone: http://eureka2001.javaxl.com:2001/eureka/,http://eureka2002.javaxl.com:2002/eureka/,http://eureka2003.javaxl.com:2003/eureka/ info: groupId: com.javaxl.testSpringcloud artifactId: microservice-student-provider-hystrix-1006 version: 1.0-SNAPSHOT userName: http://47.100.191.44 phone: 123456 hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 1500
2、启动类配置
package com.javaxl.microservicestudentproviderhystrix; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableCircuitBreaker @EntityScan("com.javaxl.*.*") @EnableEurekaClient @SpringBootApplication public class MicroserviceStudentProviderHystrixApplication { public static void main(String[] args) { SpringApplication.run(MicroserviceStudentProviderHystrixApplication.class, args); } }
这样的话 就有了 hystrix集群服务;
3、我们新建项目microservice-student-consumer-hystrix-turbine-91
pom.xml加下依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency>
4、application.yml
server: port: 91 context-path: / eureka: client: service-url: defaultZone: http://eureka2001.javaxl.com:2001/eureka/,http://eureka2002.javaxl.com:2002/eureka/,http://eureka2003.javaxl.com:2003/eureka/ turbine: app-config: microservice-student # 指定要监控的应用名称 clusterNameExpression: "'default'" #表示集群的名字为default spring: application: name: turbine
5、新建启动类MicroserviceStudentConsumerHystrixTurbine91Application 加注解:@EnableTurbine
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) @EnableTurbine public class MicroserviceStudentConsumerHystrixTurbine91Application { public static void main(String[] args) { SpringApplication.run(MicroserviceStudentConsumerHystrixTurbine91Application.class, args); } }
测试:
先启动三个eureka,然后把1004 1005 带hystrix的服务都启动;
microservice-student-consumer-80这个也启动,方便测试;
dashboard,turbine启动;
这样的话 http://localhost/student/getInfo 就能调用服务集群;
http://localhost:91/turbine.stream 可以监控数据,实时ping 返回data
输入http://localhost:90/hystrix进入仪表盘,输入地址
点击 进入集群监控仪表:
备案号:湘ICP备19000029号
Copyright © 2018-2019 javaxl晓码阁 版权所有