浅谈springcloud常用依赖和配置

网友投稿 364 2023-01-11

浅谈springcloud常用依赖和配置

spring cloud常用依赖和配置整理

常用依赖

// pom.xml

xmlns:xsi="http://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">

4.0.0

com.roit

config

1.0.0

pom

org.springframework.boot

spring-boot-starter-parent

2.3.3.RELEASE

UTF-8

UTF-8

1.8

org.springframework.cloud

spring-cloud-dependencies

Hoxton.SR7

pom

import

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

org.springframework.cloud

spring-cloud-netflix-eureka-client

org.springframework.cloud

spring-cloud-starter-consul-discovery

org.springframework.cloud

spring-cloud-starter-alibaba-nacos-discovery

org.springframework.cloud

nacos-client

org.springframework.cloud

spring-cloud-starter-openfeign

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.cloud

spring-cloud-starter-netflix-turbine

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-gateway

org.springframework.cloud

spring-cloud-config-server

org.springframework.cloud

spring-cloud-starter-config

org.springframework.cloud

spring-cloud-starter-bus-amqp

org.springframework.cloud

spring-cloud-starter-stream-rabbit

org.springframework.cloud

&lthttp://;artifactId>spring-cloud-starter-zipkin

xmlns:xsi="http://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">

4.0.0

com.roit

config

1.0.0

pom

org.springframework.boot

spring-boot-starter-parent

2.3.3.RELEASE

UTF-8

UTF-8

1.8

org.springframework.cloud

spring-cloud-dependencies

Hoxton.SR7

pom

import

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

org.springframework.cloud

spring-cloud-netflix-eureka-client

org.springframework.cloud

spring-cloud-starter-consul-discovery

org.springframework.cloud

spring-cloud-starter-alibaba-nacos-discovery

org.springframework.cloud

nacos-client

org.springframework.cloud

spring-cloud-starter-openfeign

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.cloud

spring-cloud-starter-netflix-turbine

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-gateway

org.springframework.cloud

spring-cloud-config-server

org.springframework.cloud

spring-cloud-starter-config

org.springframework.cloud

spring-cloud-starter-bus-amqp

org.springframework.cloud

spring-cloud-starter-stream-rabbit

org.springframework.cloud

&lthttp://;artifactId>spring-cloud-starter-zipkin

配置

// application.yml

# 设置端口

server:

port: 8000

# 服务名

spring:

application:

name: eureka

# eureka 配置

eureka:

instance:

hostname: localhost

client:

service-url:

defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka

# 是否需要将自己的路径注册到 eureka 服务端

register-with-eureka: true

# 是否需要从 eureka 服务端抓取路径

fetch-registry: true

# consul

spring:

cloud:

consul:

host: localhost

port: 8500

discovery:

# 注册到 consul 的服务名

service-name: ${spring.application.name}

# 监控界面显示 ip

prefer-ip-address: true

# nacos

spring:

cloud:

nacos:

discovery:

# 服务端地址

server-addr: 127.0.0.1:8848

# ribben 负载均衡策略

provider:

ribbon:

NFloadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

# feign 超时配置, 集成了 ribbon

ribbon:

# 连接超时时间 默认 1000ms

ConnectTimeout: 1000

# 逻辑处理超时时间 默认 1000ms

ReadTimeout: 3000

#feign 集成了 hystrix,开启 hystrix

feign:

hystrix:

enabled: true

# feign 设置日志级别,只支持 debug, 请求响应的相关数据

logging:

level:

com.roit.controller: debug

# turbine 聚合监控

turbine:

combine-host-port: true

# 配置监控的服务名

app-config: provider,consumer

cluster-name-expression: "'default'"

aggregator:

cluster-config: default

#instanceUrlSuffix: /actuator/hystrix.stream

# gateway 网关

spring:

cloud:

gateway:

routes:

- id: provider

# provider 的静态访问路径

# uri: http://localhost:8001/

# 动态

uri: lb://provider

# 匹配规则

predicates:

- Path=/goods/**

# 局部过滤器

filters:

- AddRequestParameter=username,zs

discovery:

locator:

# 请求路径加上微服务名称,http://localhost/provider/goods/ 或 http://localhost/goods/ 都行

enabled: true

# 默认名称大写,改为允许小写

lower-case-service-id: true

# config 服务端

spring:

cloud:

config:

server:

# 文件的仓库地址

git:

uri: https://gitee.com/config.git

# username: zs

# password: 123

# 文件所在分支

label: master

# config 客户端,bootstrap.yml

spring:

cloud:

config:

# http://localhost:8888/master/config-dev.yml

# config 服务端地址

# uri: http://localhost:8888

name: config

profile: dev,redis

label: master

# 动态配置 config 服务端地址,先将config 服务端注册到 eureka

discovery:

enabled: true

# config 服务端的名字,大写

service-id: config-server

# config 客户端 单服务自动刷新

# 1. 加依赖 actuator

# 2. 获取数据的 controller 上加@RefreshScope

# 3. curl -X POST http://localhost:8001/actuator/refresh

management:

endpoints:

web:

exposure:

# * 暴露所有;refresh 暴露自动刷新,/actuator/refresh。

include: '*'

# bus 自动刷新,先给 config-server 发消息,再由 server 去通知所有的 config-client

# bus-amqp 内部使用 rabbitmq 发消息

# config-server 需暴露 bus-refresh 和 配置 rabbitmq

# curl -X POST http://localhost:8888/actuator/bus-refresh

include: 'bus-refresh'

# config-client 需配置 rabbitmq 和 在获取数据的 controller 上加 @RefreshScope

spring:

rabbitmq:

host: localhost

port: 5672

username: guest

password: guest

virtual-host: /

# stream-rabbit

spring:

cloud:

stream:

binders:

# 定义绑定器名称

mybinder:

type: rabbit

# 指定 mq 的环境

environment:

spring:

rabbitmq:

host: localhost

port: 5672

username: guest

password: guest

virtual-host: /

bindings:

# 生产者 @EnableBinding(Source.class)

output:

# 消费者 @EnableBinding(Sink.class), @StreamListener(Sink.INPUT)

# input:

binder: mybinder

# 绑定的交换机名称

destination: myexchange

# sleuth + zipkin

spring:

zipkin:

# zipkin 服务端路径

base-url: http://lacalhost:9411/

sleuth:

sampler:

# 数据采集率 默认0.1

probability: 0.1

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:有道翻译免费api(有道翻译免费下载手机版)
下一篇:Spring Boot web项目的TDD流程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~