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

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

mysql设置时区

mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0