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


相关推荐

  • java对象转json字符串方法_oracle clob转字符串

    java对象转json字符串方法_oracle clob转字符串曾今遇到一个问题,需要将JavaBean转换为Json字符串,用fastjson可以很方便的做到。但是得到的结果是JavaBean成员变量的首字母编程了小写。经过查找资料,原来我们可以使用fastjson的@JsonField注解来自定义json中key的值,这样看来还是很方便的。

    2022年9月22日
    2
  • AbstractInterceptor和Interceptor的区别

    AbstractInterceptor和Interceptor的区别AbstractInterceptor实现了Interceptor接口,并且空实现了init()和destroy()方法。在使用中,如果无需实现init和destroy方法,可以直接实现AbstractInterceptor

    2022年5月15日
    37
  • ADO.net中常用的对象介绍

    ADO.NET的对象主要包括:DataSet,DataTable,DataColumn,DataRow,和DataRelation。DataSet:这个对象是一个集合对象,它可以包含任意数量的数据表

    2021年12月20日
    45
  • netty bytebuffer_netty udp

    netty bytebuffer_netty udpByteBuf正如前面所提到的,网络数据的基本单位总是字节。JavaNIO提供了ByteBuffer作为它的字节容器,但是这个类使用起来过于复杂,而且也有些繁琐。Netty的ByteBuffer替代品是ByteBuf,一个强大的实现,既解决了JDKAPI的局限性,又为网络应用程序的开发者提供了更好的API。Netty的数据处理API通过两个组件暴露——abstractclassByteBuf和interfaceByteBufHolder。优点:它可以被

    2022年9月19日
    3
  • sql语句查询前100条数据_sql取前100条数据

    sql语句查询前100条数据_sql取前100条数据mysql查询前100条数据云服务器(ElasticComputeService,简称ECS)是阿里云提供的性能卓越、稳定可靠、弹性扩展的IaaS(InfrastructureasaService)级别云计算服务。云服务器ECS免去了您采购IT硬件的前期准备,让您像使用水、电、天然气等公共资源一样便捷、高效地使用服务器,实现计算资源的即开即用和弹性伸缩。阿里云ECS持续提供创新型服务器,…

    2025年10月4日
    2
  • @MapperScan 源码解析

    @MapperScan 源码解析aa

    2022年5月18日
    41

发表回复

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

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