Spring Cloud 学习系列:(十)使用 Turbine 聚合监控数据

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
img

正文

name: microservice-provider-service-hystrix-turbine

eureka:

client:

service-url:

defaultZone: http://localhost:8761/eureka/

management:

endpoints:

web:

exposure:

include: “*”

cors:

allowed-origins: “*”

allowed-methods: “*”

turbine:

app-config: microservice-provider-service-hi,microservice-provider-service-hi2

aggregator:

clusterConfig: default

clusterNameExpression: new String(“default”)

combine-host: true

instanceUrlSuffix:

default: actuator/hystrix.stream

注意:如果使用 springboot2.0 和 spring cloud Finchley 版本及以上搭建,使用(/actuator/hystrix.stream 而不是/hystrix.stream 为插入点)

如果你不想加 actuator,那你就配置一下这个:

management:

endpoints:

web:

exposure:

include: [“health”,“info”,“hystrix.stream”]

4、搭建两个服务,这样可以测 Turbine 聚合监控数据

(1)、application.yml

server:

port: 8764

spring:

application:

name: microservice-provider-service-hi

eureka:

client:

service-url:

defaultZone: http://localhost:8761/eureka/

management:

endpoints:

web:

exposure:

include: “*”

cors:

allowed-origins: “*”

allowed-methods: “*”

(2)、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 https://maven.apache.org/xsd/maven-4.0.0.xsd”>

4.0.0

com.riemann

microservice-eureka-hystrix-turbine

0.0.1-SNAPSHOT

com.riemann

microservice-provider-service-hi

0.0.1-SNAPSHOT

microservice-provider-service-hi

Eureka Hystrix Turbine Client

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.boot

spring-boot-maven-plugin

(3)、Application

package com.riemann.microserviceproviderservicehi;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.cloud.netflix.hystrix.EnableHystrix;

import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication

@EnableEurekaClient

@EnableDiscoveryClient

@RestController

@EnableHystrix

@EnableHystrixDashboard

@EnableCircuitBreaker

public class MicroserviceProviderServiceHiApplication {

public static void main(String[] args) {

SpringApplication.run(MicroserviceProviderServiceHiApplication.class, args);

}

@Value(“${server.port}”)

String port;

@RequestMapping(“/hi”)

@HystrixCommand(fallbackMethod = “hiError”)

public String index(@RequestParam(value = “name”, defaultValue = “riemann”) String name) {

return "hi " + name + " ,i am from port: " + port;

}

public String hiError(String name) {

return "sorry " + name + “,fallback method!”;

}

}

(5)、另一个 microservice-provider-service-hi2 跟 microservice-provider-service-hi 一样的搭建。

5、结果测试

依次开启 microservice-eureka-server-hystrix-turbine、microservice-provider-service-hi、microservice-provider-service-hi2、microservice-provider-service-hystrix-turbine 工程。

打开浏览器输入:http://localhost:8763/turbine.stream,界面如下:

依次请求:

http://localhost:8764/hi?name=riemann

http://localhost:8765/hi?name=edgar

打开:http://localhost:8764/hystrix

输入监控流: http://localhost:8763/turbine.stream

在这里插入图片描述

哦豁,这是翻车的节奏么,不着急。这是因为 Spring Boot 2.0 版本以上不支持,所以要降版本,我是一个倔强的人,不想妥协降版本。

那就在 Turbine 服务的 Application 里加入这个 Bean 就可以了。

package com.riemann.microserviceproviderservicehi;

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.client.discovery.EnableDiscoveryClient;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.cloud.netflix.hystrix.EnableHystrix;

import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

import org.springframework.cloud.netflix.turbine.EnableTurbine;

import org.springframework.context.annotation.Bean;

import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication

@EnableEurekaClient

@EnableDiscoveryClient

@RestController

@EnableHystrix

@EnableHystrixDashboard

@EnableCircuitBreaker

@EnableTurbine

public class MicroserviceProviderServiceHystrixTurbineApplication {

public static void main(String[] args) {

SpringApplication.run(MicroserviceProviderServiceHystrixTurbineApplication.class, args);

}

Spring全套教学资料

Spring是Java程序员的《葵花宝典》,其中提供的各种大招,能简化我们的开发,大大提升开发效率!目前99%的公司使用了Spring,大家可以去各大招聘网站看一下,Spring算是必备技能,所以一定要掌握。

目录:

部分内容:

Spring源码

  • 第一部分 Spring 概述
  • 第二部分 核心思想
  • 第三部分 手写实现 IoC 和 AOP(自定义Spring框架)
  • 第四部分 Spring IOC 高级应用
    基础特性
    高级特性
  • 第五部分 Spring IOC源码深度剖析
    设计优雅
    设计模式
    注意:原则、方法和技巧
  • 第六部分 Spring AOP 应用
    声明事务控制
  • 第七部分 Spring AOP源码深度剖析
    必要的笔记、必要的图、通俗易懂的语言化解知识难点

脚手框架:SpringBoot技术

它的目标是简化Spring应用和服务的创建、开发与部署,简化了配置文件,使用嵌入式web服务器,含有诸多开箱即用的微服务功能,可以和spring cloud联合部署。

Spring Boot的核心思想是约定大于配置,应用只需要很少的配置即可,简化了应用开发模式。

  • SpringBoot入门
  • 配置文件
  • 日志
  • Web开发
  • Docker
  • SpringBoot与数据访问
  • 启动配置原理
  • 自定义starter

微服务架构:Spring Cloud Alibaba

同 Spring Cloud 一样,Spring Cloud Alibaba 也是一套微服务解决方案,包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。

  • 微服务架构介绍
  • Spring Cloud Alibaba介绍
  • 微服务环境搭建
  • 服务治理
  • 服务容错
  • 服务网关
  • 链路追踪
  • ZipKin集成及数据持久化
  • 消息驱动
  • 短信服务
  • Nacos Confifig—服务配置
  • Seata—分布式事务
  • Dubbo—rpc通信

Spring MVC

目录:

部分内容:

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
40)]

[外链图片转存中…(img-bI8vai2J-1713426520940)]

Spring MVC

目录:

[外链图片转存中…(img-9eBeysCf-1713426520940)]

[外链图片转存中…(img-E7qeTbIw-1713426520941)]

[外链图片转存中…(img-umE8SqK9-1713426520941)]

部分内容:

[外链图片转存中…(img-R22PvZD3-1713426520941)]

[外链图片转存中…(img-MN16a0NE-1713426520941)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-eR6p8YUQ-1713426520942)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 18
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值