六、RabbitMQ-客户端源码之AMQCommand
AMQCommand是用来处理AMQ命令的,其包含了Method, Content Heaeder和Content Body.
下面是通过wireshark抓包的AMQP协议

上图中的Basic.Publish命令就包含Method, Content header以及Content body。
AMQCommand不是直接包含Method等成员变量的,而是通过CommandAssembler又做了一次封装。
接下来先看下CommandAssembler类。此类中有这些成员变量:
/** Current state, used to decide how to handle each incoming frame. */
private enum CAState {
EXPECTING_METHOD, EXPECTING_CONTENT_HEADER, EXPECTING_CONTENT_BODY, COMPLETE
private CAState state;
/** The method for this command */
private Method method;
/** The content header for this command */
private AMQContentHeader contentHeader;
/** The fragments of this command's content body - a list of byte[] */
private final List
bodyN;
/** sum of the lengths of all fragments */
private int bodyLength;
/** No bytes of content body not yet accumulated */
private long remainingBodyBytes;
- CAState state标识这此Command目前的状态,是准备处理Method(EXPECTING_METHOD),还是处理Content header(EXPECTING_CONTENT_HEADER),还是准备处理Content body(EXPECTING_CONTENT_BODY),还是以及完成了(COMPLETE)。