Springcloud (6) bus message bus

Odousang 2021-05-04 10:49:30
springcloud bus message bus


Bus The message bus

summary

Distributed auto refresh configuration function
Spring Cloud Bus coordination Spring Cloud Config Can be used Realize the dynamic refresh of configuration

Bus Two kinds of message agents are supported :RabbitMQ and Kafka
Spring Cloud Bus It's for A framework that links nodes of a distributed system to a lightweight messaging system , It integrated. Java Event handling mechanism and message middleware function

SpringCloud Bus It can manage and disseminate messages between distributed systems , It's like a distributed actuator , Can be used for broadcast state change 、 Event push, etc , It can also be used as a communication channel between microservices

Bus concept

In the system of microservice Architecture , You usually use Lightweight message broker to build a common message topic , And connect all micro service instances in the system , Because messages generated in this topic will be listened and consumed by all instances , So it's called the message bus
Each instance on the bus , Fine Conveniently broadcast messages that need to be known to other instances connected to the topic

The basic principle

ConfigClient Instances are listening to MQ The same one topic( The default is springCloudBus). When a service refreshes data , It will put this information into Topic in , So the other monitors are the same Topic The service will be informed , Then update your configuration

RabbitMQ Environment configuration

Erlang install

RabbitMQ Official recommended download address :https://www.erlang-solutions.com/resources/download.html

RabbitMQ install

Download address :https://www.rabbitmq.com/install-windows.html#installer
The installation is complete. The service in task manager can see

To configure RabbitMQ

  1. Get into RabbitMQ Install under directory sbin Catalog

  2. install RabbitMQ-Plugins, Start management function
    Start in the current directory cmd

rabbitmq-plugins enable rabbitmq_management

After the service starts , visit http://localhost:15672( Default address )
Default account :guest, Default password :guest

Global broadcast

Demonstrate the broadcast effect , Increase complexity , Create another client , Now we have two clients , A server

design idea

  • The first one is : Using message bus Trigger a server ConfigServer Of /bus/refresh Endpoint , And refresh the configuration of all clients

  • The second kind : Using message bus Trigger a client /bus/refresh, And refresh the configuration of all clients

Compare two design ideas , The first is more appropriate
The second reason is not suitable :

  • Breaking the single responsibility of microservices , Because microservices themselves are business modules , It should not be responsible for configuration refresh
  • Destroy the peer-to-peer of each microservice node
  • There are certain limitations . for example , When microservices migrate , Its network address often changes , At this point, if you want to achieve automatic refresh , That would add more changes

Server side

  1. increase pom rely on
<!-- The message bus RabbitMQ Support -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
  1. To configure yml file
spring:
application:
name: Config-center
# rabbitmq Related configuration
rabbitmq:
host: localhost
port: 5672
username: guest
password: guset
# rabbitmq Related configuration , expose bus Refresh configured endpoints
management:
endpoints:
# expose bus Refresh configured endpoints
web:
exposure:
include: 'bus-refresh'

client

  1. increase pom rely on
<!-- The message bus RabbitMQ Support -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
  1. To configure yml file
spring:
application:
name: Config-client
# rabbitmq Related configuration
rabbitmq:
host: localhost
port: 5672
username: guest
password: guset

modify github On application The content of , Send it once POST request , Implement global modification , Directly in Server side Send a request , The global modification can be achieved

curl -X POST "http://localhost:3344/actuator/bus-refresh"

Fixed point notification

Specify that some instances take effect instead of all

http://localhost: Configure the central port number /actuator/bus-refresh/{destination}

/bus/refresh Requests are no longer sent to specific service instances , It is issue configserver adopt destination The parameter class specifies the service or instance that needs to update the configuration

We're here to refresh the run in 3355 On port config-client For example , Notice only 3355, Without notice 3366

http://localhost: Configure the central port number /actuator/bus-refresh/ service name : Port number
curl -X POST http://localhost:3344/actuator/bus-refresh/Config-client:3355

版权声明
本文为[Odousang]所创,转载请带上原文链接,感谢
https://javamana.com/2021/05/20210504104735418f.html

  1. java call dll
  2. 用Java构建反应式REST API - Kalpa Senanayake
  3. The relationship between httpsession object and cooike and the construction of cookie object
  4. Grpc Web: a JavaScript library package to replace rest grpc
  5. java call dll
  6. Building reactive rest API with Java - kalpa Senanayake
  7. Five wonders. Feeling of visiting villa in spring
  8. Spring will be far away
  9. 最全面的SpringBoot配置文件详解
  10. 最全面的SpringBoot配置文件详解
  11. 微服务开发神器之JRebel 插件破解和实现本地及远程热部署教程
  12. 漫画 | 你还记得原生的JDBC怎么连接数据库吗?
  13. Java流及流操作示例
  14. The most comprehensive spring boot configuration file
  15. The most comprehensive spring boot configuration file
  16. Cracking and implementing jrebel plug-in of microservice development artifact
  17. Comic | do you remember how the native JDBC connects to the database?
  18. Java stream and stream operation example
  19. ftp连接windows与linux
  20. 装饰器设计模式 - Gene Zeiniss
  21. Spring 3中异步方法调用
  22. AOP相关讨论
  23. jf能支持的表现层目前只有struts 1.x么?
  24. 在j2ee中实现一般java对象数据库的方法。
  25. FTP connecting windows and Linux
  26. Decorator design pattern - gene zeiniss
  27. Asynchronous method call in spring 3
  28. Discussion on AOP
  29. Is struts 1. X the only presentation layer supported by JF?
  30. The method of realizing general Java object database in J2EE.
  31. PDF转HTML工具——用springboot包装pdf2htmlEX命令行工具
  32. Pdf to HTML tool -- Wrapping pdf2htmlex command line tool with springboot
  33. MySQL 的 in 查询不走索引?我拿什么拯救你!
  34. MySQL in query does not go index? What can I do to save you!
  35. PDF转HTML工具——用springboot包装pdf2htmlEX命令行工具
  36. Pdf to HTML tool -- Wrapping pdf2htmlex command line tool with springboot
  37. Java小白入门必学!最全数据类型和运算符笔记,附实例
  38. Java Xiaobai introduction must learn! Notes on the most complete data types and operators, with examples
  39. Spring MVC请求与响应
  40. Spring MVC request and response
  41. Java 11已经不再完全免费,不要陷入Oracle的Java 11陷阱
  42. Vue.js比jQuery更容易学习
  43. 启动/删除Docker容器时出现问题 - 如何修复
  44. eclipse run on server时出现了错误信息.求急!!
  45. 请教高手一个关于lunce的问题:java.io.IOException: Cannot rename ...\segments.new
  46. Java 11 is no longer completely free. Don't fall into the Java 11 trap of Oracle
  47. Vue. JS is easier to learn than jQuery
  48. Problem starting / deleting docker container - how to fix it
  49. There is an error message in eclipse run on server!!
  50. Ask a question about lunce: java.io.ioexception: cannot rename... \ segments.new
  51. 从零搭建Spring Boot脚手架(2):集成mybatis
  52. 从零搭建Spring Boot脚手架(4):手写Mybatis通用Mapper
  53. 只知道java反射,宁知道内省吗?
  54. Build spring boot scaffold from scratch (2): integrate mybatis
  55. Build spring boot scaffold from scratch (4): handwritten mybatis general mapper
  56. Do you prefer introspection to reflection?
  57. ASP调用SDK微信分享好友、朋友圈
  58. ASP calls SDK wechat to share friends and circle of friends
  59. BAT 必问的 MySQL 面试题你都会吗?
  60. Do you know all the MySQL interview questions that bat must ask?