AMQP协议—帧

AMQP帧

AMQP is a binary protocol. Information is organised into "frames", of various types. Frames carry protocol methods and other information. All frames have the same general format: frame header, payload,and frame end. The frame payload format depends on the frame type.

AMQP是一个二进制协议。信息被组织成各种类型的帧。帧携带协议方法和其他信息。所有的帧具有相同的格式:帧头、载荷、帧尾。不同类型的帧的载荷格式不同。

Frame

Within a single socket connection, there can be multiple independent threads of control, called "channels".Each frame is numbered with a channel number. By interleaving their frames, different channels share the connection. For any given channel, frames run in a strict sequence that can be used to drive a protocol
parser (typically a state machine).

在单个socket连接中,可以有多个独立的控制线程,称为“channel”。每个帧都有一个channel号By interleaving their frames(翻译得有点尴尬,还是保留~),不同的channel共享这个连接。对于任何给定的channel,帧以严格的顺序运行(参考 rabbitmq-java-client 中 CommandAssembler 实现),可用于驱动协议解析器(通常是一个状态机)。

帧类型

There are 5 types of frames defined in the AMQP specification, they are:

Protocol header: This is the frame sent to establish a new connection between the broker (RabbitMQ) and a client. It will not be used anymore after the connection.

协议头,只在客户端和broker建立连接时用到。

Method frame(方法帧): Carries a RPC request or response. AMQP uses a remote procedure call (RPC) pattern for nearly all kind of communication between the broker and the client. For example, when we are publishing a message, our application calls Basic.Publish, and this message is carried in a method frame, that will tell RabbitMQ that a client is going to publish a message.

方法帧携带RPC请求或响应。 Broker和client之间几乎所有类型的通信,AMQP使用远程过程调用(RPC)模式来进行。例如当我们发布消息时,我们的应用程序调用Basic.Publish(这条AMQP命令),并且它携带在一个方法帧中,这将告诉RabbitMQ,客户端将要发布一条消息。

Content header(内容头帧): Certain specific methods carry a content (like Basic.Publish, for instance, that carries a message to be published), and the content header frame is used to send the properties of this content. For example, this frame may have the content-type of a message that is going to be published and a timestamp.

某些特定方法会携带内容(例如,Basic.Publish会携带将要发送的一条消息),并且内容头帧用于发送此内容的属性。例如,该帧可能会有将要发布的消息的content-type和timestamp。

Body(内容帧): This is the frame with the actual content of your message, and can be split into multiple different frames if the message is too big .

Heartbeat(心跳帧): Used to confirm that a given client is still alive. If RabbitMQ sends a heartbeat to a client and it does not respond in timely fashion, the client will be disconnected, as it’s considered dead.

示例

publish a message

发布消息时,client至少需要发送3个帧:方法帧(Basic.Publish),内容头帧和一个或多个body帧,具体取决于消息的大小:

publish

consume a message

消费消息时,broker同样至少需要发送3个帧:方法帧(Basic.Deliver),内容头帧和一个或多个body帧:

Deliver

参考

amqp0-9-1
A look into AMQP’s frame structure

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,340评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,762评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,329评论 0 329
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,678评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,583评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,995评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,493评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,145评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,293评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,250评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,267评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,973评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,556评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,648评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,873评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,257评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,809评论 2 339

推荐阅读更多精彩内容