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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 善待自己:改变命运的N个人生哲理

    善待自己:改变命运的N个人生哲理心灵的栅栏  人与月亮的距离并不遥远,因为人与人心灵间的距离更为遥远。  ——王尔德    当玛格丽特的丈夫杰瑞因脑瘤去世后,她变得异常愤怒,生活太不公平,她憎恨孤独。孀居3年,她的脸变得紧绷绷的。  一天,玛格丽特在小镇拥挤的路上开车,忽然发现一幢她喜欢的房子周围竖起一道新的栅栏。那房子已有一百多年的历史,颜色变白,有很大的门廊,过去一直隐藏在路后面。如今马路扩展,街口竖起了红绿灯,小镇已颇有些

    2022年7月12日
    15
  • UIWebView OC与JS交互那些事

    UIWebView OC与JS交互那些事UIWebView 基础 1 UIWebView 与 WKWebView 基本使用 https blog csdn net article details UIWebView 与 JS 交互本人使用的是原生的 JavaScriptCo 库或者第三方 WebViewJavas 第三方 WebViewJavas

    2025年7月21日
    7
  • git 更新代码到本地

    git 更新代码到本地正规流程gitstatus(查看本地分支文件信息,确保更新时不产生冲突)gitcheckout–[filename](若文件有修改,可以还原到最初状态;若文件需要更新到服务器上,应该先merge到服务器,再更新到本地)gitbranch(查看当前分支情况)gitcheckoutremotebranch(若分支为本地分支,则需切换到服务器的远程分支)git…

    2022年6月15日
    103
  • mysql添加索引造成的影响

    mysql添加索引造成的影响尽管添加索引可以优化SQL语句的性能,但是添加索引的同时也会带来不小的开销。尤其是在有大量的索引的情况下。mysql添加索引造成的影响如下:1、DML(数据操作语言)影响,在表上添加缩影会直接影响写操作性能(因为添加记录的同时还有创建相应记录的索引,这也是要耗资源的。)。2、DDL(数据定义语言)影响,随着表大小的不断增加,对性能的影响也会不断增加。比如:ALTER语句会耗费更多的时间…

    2022年5月8日
    155
  • 用ESC/P控制码,怎样向喷墨打印机传送图形数据啊,包括颜色信息?

    用ESC/P控制码,怎样向喷墨打印机传送图形数据啊,包括颜色信息?

    2021年7月28日
    54
  • Qt QStringList的简单使用方法「建议收藏」

    Qt QStringList的简单使用方法「建议收藏」从QList继承而来,它提供快速索引为基础的接入以及快速插入和清除其成员函数用于操作这个字符串列表如append(),insert(),replace(),removeAll(),removeAt(),removeFirst(),removeLast(),andremoveOne()等1.  增加字符串  可以通过append(),或使用  QString

    2022年6月4日
    99

发表回复

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

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