Spring Cloud系列--Spring Cloud Bus
之前在网上找了很多关于Spring Cloud Bus相关文章,发现大多都是基于Spring boot 1.5.X实现的,很少有基于Spring boot 2.x 实现的文章,没办法,只能自己翻文档,自己搞了。在了解Spring Cloud Bus 之前,我们需要了解一下必要知识。
事件驱动架构(Event Driven Architecture,EDA)
事件驱动架构(Event Driven Architecture,EDA)一个事件驱动框架(EDA)定义了一个设计和实现一个应用系统的方法学,在这个系统里事件可传输于松散耦合的组件和服务之间。一个事件驱动系统典型地由事件消费者和事件产生者组成。事件消费者向事件管理器订阅事件,事件产生者向事件管理器发布事件。当事件管理器从事件产生者那接收到一个事件时,事件管理把这个事件转送给相应的事件消费者。如果这个事件消费者是不可用的,事件管理者将保留这个事件,一段间隔之后再次转送该事件消费者。这种事件传送方法在基于消息的系统里就是:储存(store)和转送(forward)。 ---- 百度百科
具体架构流程如下图所示
EDA.jpg以上参考 Event-Driven Data Management for Microservices
事件的发布与监听
在Spring中,我们可以通过对应的API进行本地的事件监听。
- 事件源 : ApplicationEvent
- 监听 : ApplicationListener/@EventListener
- 事件发布 : ApplicationEventPublisher
使用场景
用于广播应用状态变更到分布式系统中的各个关联的节点。应用节点间不直接相互通讯,而通过消息总线来实现通知。 每个节点即使消息的接收者也是消息的发布者。
默认实现
- AMQP: RabbitMQ
- Kafka
简单实现
实现Spring Cloud Bus 事件的发布监听,我们需要之前的三个组件以及kafka和Spring Cloud bus即可。(以下组件在上一章中已经有介绍搭建,这里就不做赘述了)。
- demo-register
- demo-provider
- demo-consumer
- kafka
具体流程图如下
springbus.jpg更新demo-provider/demo-consumer
pom.xml
增加如下组件:
<!-- 依赖 Spring Cloud Stream Binder Kafka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
</dependency>
<!--健康检查-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
yaml 文件修改
增加kafka 配置。
spring:
application:
name: 模块名(这里包括demo-provider/demo-consumer)
kafka:
bootstrap-servers: xx.xxx.xx.xxx:9092 # spring bus需要配置的 kafka 地址
cloud:
stream:
bindings: #Binder相关配置
input:
destination: users # 监听的topic
contentType: text/plain # 传送类型(选填)
kafka:
binder:
brokers: xx.xxx.xx.xx:9092 #Spring Binder 需要配置的 Kafka 地址
bus:
trace:
enabled: true #开启追踪
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka/
management:
endpoints:
web:
exposure:
include: '*' #开放消息更新接口
trace:
http:
enabled: true #开启追踪
这里除了端口配置以外,我已经把其他的配置都贴了上来,需要更新demo-provider
以及demo-consumer
两个组件。
启动以及事件的发布与监听
接下来我们就需要启动所修改的几个组件,注意启动顺序:
- kafka
- demo-register
- demo-provider
- demo-consumer
注意这里我demo-provider启动了两个,以保证消息发布时的单一发布和广播。
这里我在demo-provider中 定义了两个yml文件,除了端口不一致以外,其他的都一致。至于如何使用IDEA启动两个应用,可以自行百度。
启动先后我们先来看一段文档
发布单一通知
Addressing an Instance
Each instance of the application has a service ID, whose value can be set with
spring.cloud.bus.id
and whose value is expected to be a colon-separated list of identifiers, in order from least specific to most specific. The default value is constructed from the environment as a combination of thespring.application.name
andserver.port
(orspring.application.index
, if set). The default value of the ID is constructed in the form ofapp:index:id
, where:
app
is thevcap.application.name
, if it exists, orspring.application.name
index
is thevcap.application.instance_index
, if it exists,spring.application.index
,local.server.port
,server.port
, or0
(in that order).id
is thevcap.application.instance_id
, if it exists, or a random value.The HTTP endpoints accept a “destination” path parameter, such as
/bus-refresh/customers:9000
, wheredestination
is a service ID. If the ID is owned by an instance on the bus, it processes the message, and all other instances ignore it.
广播发布
Addressing All Instances of a Service
The “destination” parameter is used in a Spring
PathMatcher
(with the path separator as a colon —:
) to determine if an instance processes the message. Using the example from earlier,/bus-env/customers:**
targets all instances of the “customers” service regardless of the rest of the service ID.
我们通过这个可以看到。
- 单一发布: /bus-refresh/customers:9000
- 广播发布:/bus-refresh/customers:**
接着我们来启动程序,我们只需要看到使用Spring Cloud Bus 上的组件console出打印出这样的日志,表示启动成功。
kafka.jpg简单运行
我们这里会展示单一发布和广播发布。我们需要打开postman
进行请求。
单一发布
我们首先需要将编译器的console输出全部清除。
从demo-consumer通知到 demo-provider1
demo-consumer:8082
- > demo-provider1:8088
。
我们经过postman将事件发布后,查看两个console输出。由于输出太多,我这里不截图了,直接贴出来。可能有些冗余,我们主要看两者日志的差别即可。
发布源(demo-consumer)
2019-08-04 21:55:36.254 INFO 13692 --- [nio-8082-exec-2] o.a.k.clients.producer.ProducerConfig : ProducerConfig values:
acks = 1
batch.size = 16384
bootstrap.servers = [47.95.240.23:9092]
buffer.memory = 33554432
client.id =
compression.type = none
connections.max.idle.ms = 540000
enable.idempotence = false
interceptor.classes = []
key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
linger.ms = 0
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 0
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = https
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
transaction.timeout.ms = 60000
transactional.id = null
value.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
2019-08-04 21:55:36.256 INFO 13692 --- [nio-8082-exec-2] o.a.kafka.common.utils.AppInfoParser : Kafka version : 2.0.1
2019-08-04 21:55:36.256 INFO 13692 --- [nio-8082-exec-2] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : fa14705e51bd2ce5
2019-08-04 21:55:36.333 INFO 13692 --- [ad | producer-2] org.apache.kafka.clients.Metadata : Cluster ID: hr_cV3Y5Raue26J4-4EYOw
2019-08-04 21:55:36.622 INFO 13692 --- [nio-8082-exec-2] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$ca319019] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-04 21:55:36.760 INFO 13692 --- [nio-8082-exec-2] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2019-08-04 21:55:36.764 INFO 13692 --- [nio-8082-exec-2] o.s.boot.SpringApplication : Started application in 0.369 seconds (JVM running for 266.046)
2019-08-04 21:55:36.943 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2019-08-04 21:55:39.943 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Unregistering ...
2019-08-04 21:55:39.955 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-CONSUMER/DESKTOP-0MC990D:demo-consumer:8082 - deregister status: 200
2019-08-04 21:55:39.970 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2019-08-04 21:55:39.979 INFO 13692 --- [nio-8082-exec-2] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-08-04 21:55:39.981 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-08-04 21:55:39.985 INFO 13692 --- [nio-8082-exec-2] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-08-04 21:55:39.985 INFO 13692 --- [nio-8082-exec-2] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-08-04 21:55:39.985 INFO 13692 --- [nio-8082-exec-2] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-08-04 21:55:39.985 INFO 13692 --- [nio-8082-exec-2] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-08-04 21:55:40.066 INFO 13692 --- [nio-8082-exec-2] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-08-04 21:55:40.068 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-08-04 21:55:40.074 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-08-04 21:55:40.075 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2019-08-04 21:55:40.076 INFO 13692 --- [nio-8082-exec-2] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-08-04 21:55:40.077 INFO 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1564926940077 with initial instances count: 3
2019-08-04 21:55:40.085 INFO 13692 --- [nio-8082-exec-2] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application DEMO-CONSUMER with eureka with status DOWN
2019-08-04 21:55:40.085 WARN 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1564926940085, current=DOWN, previous=STARTING]
2019-08-04 21:55:40.086 INFO 13692 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-CONSUMER/DESKTOP-0MC990D:demo-consumer:8082: registering service...
2019-08-04 21:55:40.086 INFO 13692 --- [nio-8082-exec-2] o.s.c.n.e.s.EurekaServiceRegistry : Registering application DEMO-CONSUMER with eureka with status UP
2019-08-04 21:55:40.087 WARN 13692 --- [nio-8082-exec-2] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1564926940087, current=UP, previous=DOWN]
2019-08-04 21:55:40.089 INFO 13692 --- [nio-8082-exec-2] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
2019-08-04 21:55:40.094 INFO 13692 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-CONSUMER/DESKTOP-0MC990D:demo-consumer:8082 - registration status: 204
2019-08-04 21:55:40.094 INFO 13692 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-CONSUMER/DESKTOP-0MC990D:demo-consumer:8082: registering service...
2019-08-04 21:55:40.103 INFO 13692 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-CONSUMER/DESKTOP-0MC990D:demo-consumer:8082 - registration status: 204
2019-08-04 22:00:40.070 INFO 13692 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
接收者(demo-provider1)
2019-08-04 21:55:36.674 INFO 12868 --- [container-0-C-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$1a26ce66] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-04 21:55:36.812 INFO 12868 --- [container-0-C-1] o.s.boot.SpringApplication : The following profiles are active: p1
2019-08-04 21:55:36.819 INFO 12868 --- [container-0-C-1] o.s.boot.SpringApplication : Started application in 0.297 seconds (JVM running for 228.316)
2019-08-04 21:55:36.914 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2019-08-04 21:55:39.917 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Unregistering ...
2019-08-04 21:55:39.936 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-PROVIDER/DESKTOP-0MC990D:demo-provider:8088 - deregister status: 200
2019-08-04 21:55:39.953 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2019-08-04 21:55:39.967 INFO 12868 --- [container-0-C-1] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-08-04 21:55:39.969 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-08-04 21:55:39.974 INFO 12868 --- [container-0-C-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-08-04 21:55:39.974 INFO 12868 --- [container-0-C-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-08-04 21:55:39.974 INFO 12868 --- [container-0-C-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-08-04 21:55:39.974 INFO 12868 --- [container-0-C-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-08-04 21:55:40.045 INFO 12868 --- [container-0-C-1] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-08-04 21:55:40.046 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-08-04 21:55:40.052 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-08-04 21:55:40.053 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2019-08-04 21:55:40.054 INFO 12868 --- [container-0-C-1] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-08-04 21:55:40.054 INFO 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1564926940054 with initial instances count: 3
2019-08-04 21:55:40.058 INFO 12868 --- [container-0-C-1] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application DEMO-PROVIDER with eureka with status DOWN
2019-08-04 21:55:40.058 WARN 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1564926940058, current=DOWN, previous=STARTING]
2019-08-04 21:55:40.058 INFO 12868 --- [container-0-C-1] o.s.c.n.e.s.EurekaServiceRegistry : Registering application DEMO-PROVIDER with eureka with status UP
2019-08-04 21:55:40.059 WARN 12868 --- [container-0-C-1] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1564926940059, current=UP, previous=DOWN]
2019-08-04 21:55:40.059 INFO 12868 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-PROVIDER/DESKTOP-0MC990D:demo-provider:8088: registering service...
2019-08-04 21:55:40.059 INFO 12868 --- [container-0-C-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
2019-08-04 21:55:40.067 INFO 12868 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-PROVIDER/DESKTOP-0MC990D:demo-provider:8088 - registration status: 204
2019-08-04 21:55:40.067 INFO 12868 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-PROVIDER/DESKTOP-0MC990D:demo-provider:8088: registering service...
2019-08-04 21:55:40.072 INFO 12868 --- [container-0-C-1] o.a.k.clients.producer.ProducerConfig : ProducerConfig values:
acks = 1
batch.size = 16384
bootstrap.servers = [47.95.240.23:9092]
buffer.memory = 33554432
client.id =
compression.type = none
connections.max.idle.ms = 540000
enable.idempotence = false
interceptor.classes = []
key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
linger.ms = 0
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 0
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = https
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
transaction.timeout.ms = 60000
transactional.id = null
value.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
2019-08-04 21:55:40.073 INFO 12868 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DEMO-PROVIDER/DESKTOP-0MC990D:demo-provider:8088 - registration status: 204
2019-08-04 21:55:40.074 INFO 12868 --- [container-0-C-1] o.a.kafka.common.utils.AppInfoParser : Kafka version : 2.0.1
2019-08-04 21:55:40.074 INFO 12868 --- [container-0-C-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : fa14705e51bd2ce5
2019-08-04 21:55:40.149 INFO 12868 --- [ad | producer-2] org.apache.kafka.clients.Metadata : Cluster ID: hr_cV3Y5Raue26J4-4EYOw
2019-08-04 22:00:40.049 INFO 12868 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
我们可以明显看到两者日志输出的不一样。主要的是在这里
p2.jpg因为这里只是简单的演示,因此没有发布任何消息信息,所以接受为空。
广播发布
广播发布与单一发布唯一不同的就是通知的端口改为**
demo-consumer
-> demo-provider1
,demo-provider2
这里就不贴日志了,只要单一发布成功,广播发布就没什么问题了。
总结
这里只是简单的介绍了 Spring Cloud Bus的搭建和简单测试。之后会有其他自定义事件等相关操作的介绍。