栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

周阳老师springcloud学习总结

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

周阳老师springcloud学习总结

前提声明:我有跟着周阳老师来做项目,不是只过来写文章的!!里边有一些踩坑点和配置文件代码,按照b站视频顺序来写的。也不是来授课的。Alibaba的springcloud还没学,那是另一个阶段了。只是按照这篇文章给使用者包括我自己提醒顺序、配置、具体操作等等。墙裂建议没看过的小伙伴还是去学习一下,小白新手很合适!!

B站尚硅谷springcloud视频:

https://www.bilibili.com/video/BV18E411x7eT


SpringBoot 2.0版和SpringCloud H版 强烈建议使用SpringBoot 2.0以上

SpringBoot和SpringCloud之间版本有约束 H版对应2.2 G版对应2.1

总工程创建步骤

注册中心:Eureka

(貌似还有个在电脑host文件中添加修改的操作,但是具体是啥我忘了,配置了两个ip指向eureka7001.com:7001和eureka7002.com:7002)

依赖(父模块版本已经引入了,不会报错,这里单写展示一下)

		
        org.springframework.cloud
        spring-cloud-starter-netflix-eureka-server
        2.2.1.RELEASE
        

添加yml配置文件

server:
  port: 7001


eureka:
  instance:
    hostname: eureka7001.com #eureka服务端的实例名称
  client:
    register-with-eureka: false     #false表示不向注册中心注册自己。
    fetch-registry: false     #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    service-url:
    #集群指向其它eureka
      #defaultZone: http://eureka7002.com:7002/eureka/
    #单机就是7001自己
      defaultZone: http://eureka7001.com:7001/eureka/
  #server:
    #关闭自我保护机制,保证不可用服务被及时踢除
    #enable-self-preservation: false
    #eviction-interval-timer-in-ms: 2000

编写启动类

@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7001 {
        public static void main(String[] args) {
            SpringApplication.run(EurekaMain7001.class,args);
        }
}
提供者模块

            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
server:
  port: 8001

spring:
  application:
    name: cloud-payment-service
  zipkin:
      base-url: http://localhost:9411
  sleuth:
    sampler:
      #采样率值介于 0 到 1 之间,1 则表示全部采集
      probability: 1
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource            # 当前数据源操作类型
    driver-class-name: org.gjt.mm.mysql.Driver              # mysql驱动包
    url: jdbc:mysql://localhost:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 123456


eureka:
  client:
    #表示是否将自己注册进EurekaServer默认为true。
    register-with-eureka: true
    #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
    fetchRegistry: true
    service-url:
      #单机版
      defaultZone: http://localhost:7001/eureka
      # 集群版
      #defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
  instance:
      instance-id: payment8001
      #访问路径可以显示IP地址
      prefer-ip-address: true
      #Eureka客户端向服务端发送心跳的时间间隔,单位为秒(默认是30秒)
      #lease-renewal-interval-in-seconds: 1
      #Eureka服务端在收到最后一次心跳后等待时间上限,单位为秒(默认是90秒),超时将剔除服务
      #lease-expiration-duration-in-seconds: 2


mybatis:
  mapperLocations: classpath:mapper
    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}

新建项目豪猪哥界面dashboard9001


            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
        
//启动类
@EnableHystrixDashboard

访问路径
localhost:9001/hystrix

GateWay、Spring Config、Bus消息中心、SpringCloud Sleuth

博客地址
详见b站视频或者上方博客链接
66_GateWay是什么
67_GateWay非阻塞异步模型
68_Gateway工作流程
69_Gateway9527搭建
70_Gateway配置路由的两种方式
71_GateWay配置动态路由
72_GateWay常用的Predicate
73_GateWay的Filter
74_Config分布式配置中心介绍
75_Config配置总控中心搭建
76_Config客户端配置与测试
77_Config动态刷新之手动版
78_Bus消息总线是什么
79_Bus之RabbitMQ环境配置
80_Bus动态刷新全局广播的设计思想和选型
81_Bus动态刷新全局广播配置实现
82_Bus动态刷新定点通知
83_Stream为什么被引入
84_Stream是什么及Binder介绍
85_Stream的设计思想
86_Stream编码常用注解简介
87_Stream消息驱动之生产者
88_Stream消息驱动之消费者
89_Stream之消息重复消费
90_Stream之group解决消息重复消费
91_Stream之消息持久化
92_Sleuth是什么
93_Sleuth之zipkin搭建安装
94_Sleuth链路监控展现

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/763359.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号