Vertx eventbus模塊解析


eventbus 事件總線

協議棧

TCP分包,粘包解決採用方案: 消息定長(定義消息體總長度),消息分為消息頭和消息體

dataType bytes description
int 4 包體總大小 code: << buffer.setInt(0, buffer.length() - 4) >>
byte 1 棧協議版本
byte 1 消息類型 codec 的路徑 io.vertx.core.eventbus.impl.codecs
自定義消息 val: -1
byte 1 發鬆模型 false Publish/subscribe , true Point/Point
int 4 send eventAddr 的長度
String ? send eventAddr 內容
int 4 replyAddress 的長度 , 無需 Response 長度爲 0
String ? replyAddress 內容, cluster模式爲 UUID , local模式採用 AtomicLong,保證全局唯一性
int 4 tcp服務 port
int 4 tcp服務 host 長度
String ? tcp服務 host 地址
int 4 headers exists 標志位, 不存在 appendInt 4 , 存在 appendInt 0
int 4 headers不爲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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM