springcloud2.0 --turbine

pom文件依赖

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

启动类加入注解

@SpringBootApplication
@EnableTurbineStream
public class ExampleTurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(ExampleTurbineApplication.class, args);
    }

}

配置文件

server:
  port: 8754
spring:
  rabbitmq:
    host: 172.16.10.2
    username: test
    password: test
    port: 5672
    virtual-host: turbine
eureka:
  instance:
    hostname: localhost
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
turbine:
  stream:
    port: 8989
management:
  port: 8989

这章的细节有点多,我们先将主要的配置先贴出来。

如何使用rabbitmq收集流量

在这里插入图片描述

  1. 第一段说明了,我们需要在客户端引入相关的依赖,也就是要有一个采集流量的点,我们选择了以feign作为流量收集的点,当然其他模块也是可以的。这里要采集流量需要引入两个依赖。 spring-cloud-netflix-hystrix-stream和spring-cloud-starter-stream-*。 这里的星号指的是看你用什么作为中间件,本例用的是rabbitmq 所以是 spring-cloud-starter-stream-rabbit,当然kakfa应该也是可以的。(可以看一下我们feign中的依赖)。
  2. 第二段指明了我们服务端要做什么,首先我们需要到启动添加注释@EnableTurbineStream,其次我们需要添加一个叫spring-boot-starter-webflux的依赖,后续又说明了spring-cloud-starter-netflix-turbine-stream已经包含了spring-boot-starter-webflux的依赖,并且在第四段又说了spring-cloud-starter-netflix-turbine-stream这个依赖包含了所有turbine需要的依赖,所以我们直接引入了这个。
  3. 第三段是什么意思呢,为什么有一个8989端口。 这里是一个要注意的点,当我们的项目也就是turbine没有web依赖的时候(spring-boot-starter-web),我们指定的 server.port就是流量收集的端口,我们访问这个端口,例如: http://localhost:port/ 你会发现有很多的消息不停的刷出来。那什么时候会是8989呢, 当我们项目使用了spring-boot-starter-web这个依赖,boot会将server.port的监听绑定到web上。同时我们采集的流量需要有一个端口可以访问,这时候8989这个端口就是turbine默认在server.port被绑定后采集的端口,在配置文件中加入下面的配置就可以了。当然端口你可以自己改,但是在使用dashborad的时候要主要配置端口。 监听流量的时候你可以选择监听哪个模块的流量,这个在dashboard会介绍怎么用。
turbine:
  stream:
    port: 8989

效果

在这里插入图片描述

最后

turbine 这个章节内容其实很多的,需要注意的坑上面都列出来了,还有很多的内容等待挖掘,目前还是简单的做一个版本,再后续迭代探索。目前的cloud2.0还有许多地方没有完善,包括官网文档也有几处错误没有即时修改,导致在看的时候被带入坑中。至于如何使用http收集流量,官网的介绍比较的清楚,和1.0的版本基本一致,而且也没有太多的内容,推荐大家自己尝试一下。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值