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是一个二进制协议。信息被组织成各种类型的帧。帧携带协议方法和其他信息。所有的帧具有相同的格式:帧头、载荷、帧尾。不同类型的帧的载荷格式不同。
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帧,具体取决于消息的大小:
publishconsume a message
消费消息时,broker同样至少需要发送3个帧:方法帧(Basic.Deliver),内容头帧和一个或多个body帧:
Deliver
网友评论