用delphi xe 开发rabbitmq应用(三)

【rabbitmq的核心数据类型】

在AMQP V0.9.1定义了一套核心的数据类型,在delphi中做了如下定义:

type
   amqp_octet = byte;
  amqp_2octet = word;
  amqp_4octet = LongWord;
  amqp_8octet = UInt64;
  amqp_boolean = Boolean;
  amqp_bit = amqp_boolean;


  amqp_short_short_uint = amqp_octet;
  amqp_short_short_int = ShortInt;
  amqp_short_uint = amqp_2octet;
  amqp_class_id = amqp_short_uint;
  amqp_short_int = SmallInt;


  amqp_long_uint = amqp_4octet;
  amqp_long_int = Int32;
  amqp_long_long_uint = amqp_8octet;
  amqp_long_long_int = Int64;
  amqp_float = single;
  amqp_double = double;
  amqp_timestamp = amqp_long_long_uint;
  amqp_string_char = AnsiChar;


  TValueKind = ( vkBool,      vkShortShortInt, vkShortShortUInt, vkShortInt,     vkShortUInt,
                 vkLongInt,   vkLongUInt,      vkLongLongInt,    vkLongLongUInt, vkFloat,
                 vkDouble,    vkDecimalValue,  vkShortString,    vkLongString,   vkFieldArray,

                 vkTimestamp, vkFieldTable,    vkEmpty );

在这个delphimq版本中,所有的AMQP规范数据类型都以Class来做声明:

  TAMQPFieldBoolean        = class;
  TAMQPFieldShortShortInt  = class;
  TAMQPFieldShortShortUInt = class;
  TAMQPFieldShortInt       = class;
  TAMQPFieldShortUInt      = class;
  TAMQPFieldLongInt        = class;
  TAMQPFieldLongUInt       = class;
  TAMQPFieldLongLongInt    = class;
  TAMQPFieldLongLongUInt   = class;
  TAMQPFieldShortString    = class;
  TAMQPFieldLongString     = class;
  TAMQPFieldTable          = class;

  TAMQPFieldArray          = class;

以上Class的祖先是一个名为TAMQPValue的Class,该Class定义如下:

TAMQPValue = Class(TAMQPObject, IAMQPFieldValue),用interface来声明实现一个类,会带来诸多后期的好处,比如实现AOP,便于调用,不用实现destroy,容易跟踪调试。

其中 TAMQPFieldTable是实现properties list的关键类,对于发行者/消费者来说,可以编码/解码相关的必要字段,例如消息ID、消息头、消息持久性等等。

我想说得是用原生的pascal代码,消费(解码)消息非常稳定,在生产环境下(IBM X3850 Server),解码20几万条消息,没有发生异常。原作者的delphi功力是非常高的。

猜你喜欢

转载自blog.csdn.net/sonadorje/article/details/80913912