欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

MQ!Rabbit-client AMQImpl

程序员文章站 2022-06-10 13:50:35
AMQPImpl类包括AMQP接口(public class AMQImpl implements AMQP)主要囊括了AMQP协议中的通信帧的类别。在学习 channelN类的时候basicQos调用的类实际是AMQImpl的一个内部类的方法。下面是Connection.Start帧,其他帧也都是类似的(我严重怀疑写这个程序的人以前是写C的????)public static class Connection { public static final int INDEX = 10;...

MQ!Rabbit-client AMQImpl

AMQPImpl类包括AMQP接口(public class AMQImpl implements AMQP)主要囊括了AMQP协议中的通信帧的类别。

在学习 channelN类的时候basicQos调用的类实际是AMQImpl的一个内部类的方法。

MQ!Rabbit-client AMQImpl

下面是Connection.Start帧,其他帧也都是类似的(我严重怀疑写这个程序的人以前是写C的????)

public static class Connection {
    public static final int INDEX = 10;

    public static class Start
        extends Method
        implements com.rabbitmq.client.AMQP.Connection.Start
    {
        public static final int INDEX = 10;

        private final int versionMajor;
        private final int versionMinor;
        private final Map<String,Object> serverProperties;
        private final LongString mechanisms;
        private final LongString locales;

        public int getVersionMajor() { return versionMajor; }
        public int getVersionMinor() { return versionMinor; }
        public Map<String,Object> getServerProperties() { return serverProperties; }
        public LongString getMechanisms() { return mechanisms; }
        public LongString getLocales() { return locales; }

        public Start(int versionMajor, int versionMinor, Map<String,Object> serverProperties, LongString mechanisms, LongString locales) {
            if (locales == null)
                throw new IllegalStateException("Invalid configuration: 'locales' must be non-null.");
            if (mechanisms == null)
                throw new IllegalStateException("Invalid configuration: 'mechanisms' must be non-null.");
            this.versionMajor = versionMajor;
            this.versionMinor = versionMinor;
            this.serverProperties = serverProperties==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(serverProperties));
            this.mechanisms = mechanisms;
            this.locales = locales;
        }
        public Start(MethodArgumentReader rdr) throws IOException {
            this(rdr.readOctet(), rdr.readOctet(), rdr.readTable(), rdr.readLongstr(), rdr.readLongstr());
        }

        public int protocolClassId() { return 10; }
        public int protocolMethodId() { return 10; }
        public String protocolMethodName() { return "connection.start";}

        public boolean hasContent() { return false; }

        public Object visit(MethodVisitor visitor) throws IOException
        {   return visitor.visit(this); }

        public void appendArgumentDebugStringTo(StringBuilder acc) {
            acc.append("(version-major=")
                .append(this.versionMajor)
                .append(", version-minor=")
                .append(this.versionMinor)
                .append(", server-properties=")
                .append(this.serverProperties)
                .append(", mechanisms=")
                .append(this.mechanisms)
                .append(", locales=")
                .append(this.locales)
                .append(")");
        }

        public void writeArgumentsTo(MethodArgumentWriter writer)
            throws IOException
        {
            writer.writeOctet(this.versionMajor);
            writer.writeOctet(this.versionMinor);
            writer.writeTable(this.serverProperties);
            writer.writeLongstr(this.mechanisms);
            writer.writeLongstr(this.locales);
        }
    }
 ...   
}

看起来代码好长好长????,但是不用怕(反正怕也得看????)。首先要注意一点内部类Start是继承Method类(注意!!这里的Method类不是反射里面的那个,而是rabbitMq里面的类)。

一些属性

public static final int INDEX = 10;
private final int versionMajor;
private final int versionMinor;
private final Map<String,Object> serverProperties;
private final LongString mechanisms;
private final LongString locales;

一些get方法

public int getVersionMajor() { return versionMajor; }
public int getVersionMinor() { return versionMinor; }
public Map<String,Object> getServerProperties() { return serverProperties; }
public LongString getMechanisms() { return mechanisms; }
public LongString getLocales() { return locales; }

重要的参数:classId,MethodId,hasContent

public int protocolClassId() { return 10; }
public int protocolMethodId() { return 10; }
public boolean hasContent() { return false; }

剩下的都是对应方法中的主要信息。

下表涵盖AQMP协议各个种类的Method以及其一些属性,看完这张表就看完了AMQPImpl的全部。

Method-Name classId methodId hasContent
Connection.Start 10 10 false
Connection.StartOk 10 11 false
Connection.Secure 10 20 false
Connection.SecureOk 10 21 false
Connection.Tune 10 30 false
Connection.TuneOk 10 31 false
Connection.Open 10 40 false
Connection.OpenOk 10 41 false
Connection.Close 10 50 false
Connection.CloseOk 10 51 false
Connection.Blocked 10 60 false
Connection.Unblocked 10 61 false
Channel.Open 20 10 false
Channel.OpenOk 20 11 false
Channel.Flow 20 20 false
Channel.FlowOk 20 21 false
Channel.Close 20 40 false
Channel.CloseOk 20 41 false
Access.Request 30 10 false
Access.RequestOk 30 11 false
Exchange.Declare 40 10 false
Exchange.DeclareOk 40 11 false
Exchange.Delete 40 20 false
Exchange.DeleteOk 40 21 false
Exchange.Bind 40 30 false
Exchange.BindOk 40 31 false
Exchange.Unbind 40 40 false
Exchange.UnbindOk 40 51 false
Queue.Declare 50 10 false
Queue.DeclareOk 50 11 false
Queue.Bind 50 20 false
Queue.BindOk 50 21 false
Queue.Purge 50 30 false
Queue.PurgeOk 50 31 false
Queue.Delete 50 40 false
Queue.DeleteOk 50 41 false
Queue.Unbind 50 50 false
Queue.UnbindOk 50 51 false
Basic.Qos 60 10 false
Basic.QosOk 60 11 false
Basic.Consume 60 20 false
Basic.ConsumeOk 60 21 false
Basic.Cancel 60 30 false
Basic.CancelOk 60 31 false
Basic.Publish 60 40 true
Basic.Return 60 50 true
Basic.Deliver 60 60 true
Basic.Get 60 70 false
Basic.GetOk 60 71 true
Basic.GetEmpty 60 72 false
Basic.Ack 60 80 false
Basic.Reject 60 90 false
Basic.RecoverAsync 60 100 false
Basic.Recover 60 110 false
Basic.RecoverOk 60 111 false
Basic.Nack 60 120 false
Tx.Select 90 10 false
Tx.SelectOk 90 11 false
Tx.Commit 90 20 false
Tx.CommitOk 90 21 false
Tx.Rollback 90 30 false
Tx.RollbackOk 90 31 false
Confirm.Select 85 10 false
Confirm.SelectOk 85 11 false

好的,完美的水了一篇 over????

本文地址:https://blog.csdn.net/qq_15351029/article/details/111952156

相关标签: MQ rabbitmq java