Vertx eventbus模块解析

eventbus 事件總線

協議棧

TCP分包,粘包解決採用方案: 消息定长(定義消息体總长度),消息分为消息头和消息体

dataTypebytesdescription
int4包体总大小 code: << buffer.setInt(0, buffer.length() - 4) >>
byte1棧協議版本
byte1消息類型 codec 的路徑 io.vertx.core.eventbus.impl.codecs
自定義消息 val: -1
byte1發鬆模型 false Publish/subscribe , true Point/Point
int4send eventAddr 的長度
String?send eventAddr 內容
int4replyAddress 的長度 , 無需 Response 長度爲 0
String?replyAddress 內容, cluster模式爲 UUID , local模式採用 AtomicLong,保证全局唯一性
int4tcp服務 port
int4tcp服務 host 長度
String?tcp服務 host 地址
int4headers exists 標志位, 不存在 appendInt 4 , 存在 appendInt 0
int4headers不爲null , headers 总大小
List<Map>?headers 採用key/val , Map type : String/String
body?根據消息類型 append 內容, 不同類型具體實現 
io.vertx.core.eventbus.impl.codecs 包中 encodeToWire method
集羣模式
cluster model 目前 4種

1、Hazelcast 2、Infinispan 3、Apache Ignite 4、Apache Zookeeper

Apache Zookeeper 事件注冊流程

image

注册事件

image

一、point-to-point

send message

image

reply message

 

image

 

note: 1. point-point 核心点 replyAddress 全局唯一标识(UUID),根据标识确定链路point-point.    2. HandlerRegistration Class的 context(上下文),同一线程处理(vertx存在多实例的情况下).    3. HandlerRegistration Claass的 maxBufferedMessages最大消息数(DEFAULT:1000),设置可能       导致消息丢失,超过size直接poll丢弃,超过将丢弃消;防止消息丢失,send端需要超时机制.防止buffer堆积过大,最终导致OOM.    4. ConnectionHolder class 中 writeMessage方法(参考2-1) //TODO optimise this (contention on monitor)    5.如果是单向send message ,replyAddress 为 NULL.

2-1、default transports TCP send mechanism :

image

note: 1、 有丟失消息的風險(网络故障导致丢包).
二、publish-subscribe

image

转载于:https://www.cnblogs.com/cmfa/p/10529026.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值