springcloud kafka 分布式配置中心管理

springcloud kafka 分布式配置中心管理

大家好,又见面了,我是你们的朋友全栈君。

  1. 配置管理服务端   更新配置信息需要调用接口地址(post请求)/bus/refresh

1.1配置管理服务端需要的jar

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-config-server</artifactId>

</dependency>

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

<!– 注册中心–>

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-eureka</artifactId>

</dependency>

<!– kafka消息中心 –>

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-bus-kafka</artifactId>

</dependency>

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-config-monitor</artifactId>

</dependency>

1.2.在bootstrap.yml中添加

spring:

  application:

    name: framework-config-service

#配置文件设置成本地模式

  profiles:

    active: native

#开启消息总线刷新

  cloud:

    bus:

      enabled: true

    config:

      server:

        native:

          search-locations: F:/config/

#设置消息总线的地址

    stream:

      kafka:

        binder:

          brokers: 10.1.110.45:9092,10.1.110.44:9092

          zkNodes: 10.1.110.45:2181,10.1.110.44:2181

server:

  port: 8899

#关闭安全验证

management:

  security:

    enabled: false

#注册中心

eureka:

  client:

    service-url:http://localhost:8761/eureka/

 

1.3.启动项设置

@SpringBootApplication

@EnableDiscoveryClient

@EnableConfigServer

@RefreshScope

public class ConfigBoostrap {

    public static void main(String[] args) {

        ApplicationContext applicationContext = SpringApplication.run(ConfigBoostrap.class, args);

    }

}

 

  1. 配置文件管理客户端配置

2.1.需要的jar

<!– kafka消息中心 –>

<dependency>

   <groupId>org.springframework.cloud</groupId>

   <artifactId>spring-cloud-starter-bus-kafka</artifactId>

</dependency>

<!– 配置文件–>

<dependency>

   <groupId>org.springframework.cloud</groupId>

   <artifactId>spring-cloud-config-client</artifactId>

</dependency>

<!–信息采集 –>

<dependency>

   <groupId>org.springframework.boot</groupId>

   <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

2.2.消息总线的配置需要在bootstrap.yml中设置

#配置消息总线

spring:

  cloud:

    stream:

      kafka:

        binder:

          brokers: 10.1.110.45:9092,10.1.110.44:9092

          zkNodes: 10.1.110.45:2181,10.1.110.44:2181

#启动配置文件中心读取

    config:

      discovery:

        enabled: true

        service-id: framework-config-service

      profile: dev

  application:

    name: framework-common-service

#注册中心

eureka:

  client:

    service-url:

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

management:

  security:

    enabled: false

server:

  port: 8760

2.3.在启动项添加@EnableDiscoveryClient注解

 

@SpringBootApplication

@EnableDiscoveryClient

@EnableFeignClients

@EnableHystrixDashboard

@EnableCircuitBreaker

//@MapperScan(basePackages = “com.tzbank.common.dao”)

public class CommonBootstrap {

   public static void main(String[] args) {

      ApplicationContext applicationContext = SpringApplication.run(CommonBootstrap.class, args);

      SpringContextUtils.setApplicationContext(applicationContext);

   }

}

2.4.需要动态刷新的数据,取值的写法

需要在有刷新的数据的类或者方法上加上

@RefreshScope注解

取值的方法有:

import org.springframework.core.env.Environment;中取值

@Autowired

Environment environment;

或者直接绑定${value}中的value是对应配置文件的值

@Vlue(“${value}”)

Private String value;

 

转载于:https://my.oschina.net/youkun/blog/1834460

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107456.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python调用so文件[通俗易懂]

    python调用so文件[通俗易懂]从文章一将各个算法整合:文章(一)算法传送门:如下整合的c++代码run.cpp:源码传输门地址:https://wwi.lanzoup.com/izAEa027198d#define__USE_GNU#include<iostream>#include<cstdlib>#define__USE_GNU#include<string>#include”stdio.h”#define__USE_GNU#include”strin

    2022年9月16日
    2
  • eclipse 新建java文件自动加作者,日期注释设置

    eclipse 新建java文件自动加作者,日期注释设置eclipse 新建java文件自动加作者,日期注释设置

    2022年4月23日
    41
  • Pycharm 字体大小及背景颜色的设置

    Pycharm 字体大小及背景颜色的设置设置Pycharm的字体大小及背景颜色Pycharm设置字体的大小及风格选择File–>setting–>Editor–>Font,我们可以看到如下图所示界面,我们就可以根据自己的喜好随意调整字体的大小,字体的样式风格,文字行间距,设置之后的的效果在下面的窗口可以实时预览,调整和设置都比较方便。Pycharm设置背景颜色选择File–>…

    2022年8月26日
    7
  • python语言变量命名规则[通俗易懂]

    python语言变量命名规则[通俗易懂]Python语言变量命名规则变量名只能包含字母、数字和下划线。(推荐学习:0基础入门python)变量名可以字母或下划线开头,但不能以数字开头。例如,可将变量命名为message_1,但不能将其命名为1_message。变量名不能包含空格,但可使用下划线来分隔其中的单词。例如,变量名greeting_message可行,但变量名greetingmessage会引发错误。不要将Pytho…

    2022年6月14日
    35
  • cmd从c盘切换到d盘_cmd怎样切换到d盘

    cmd从c盘切换到d盘_cmd怎样切换到d盘1、按WIN+R键打开运行,输入cmd并回车;2、默认路径为用户文档路径,如果想要切换到C盘中的某个文件夹,比如AppData,可以执行命令cdAppData;3、但如果想切换到D盘,输入cd

    2022年8月2日
    16
  • phpstrom激活码2021 5月最新注册码_通用破解码

    phpstrom激活码2021 5月最新注册码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    35

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号