amqp_basic_publish报错AMQP_STATUS_TABLE_TOO_BIG

RabbitMQ消息属性填充问题解决
博客讲述在填充消息的amqp_basic_properties_t属性时加入header信息并填充很多未使用字段的情况。因amqp_table_t是其结构体成员,去掉AMQP_BASIC_HEADERS_FLAG标志后,release模式下消息可正常发送。

amqp_basic_publish报错AMQP_STATUS_TABLE_TOO_BIG


今天在做业务的时候,碰到一个奇怪的现象,发送同样属性和内容的消息,到相同的交换机上,debug模式下能发送成功,release模式下发送失败,并且报错AMQP_STATUS_TABLE_TOO_BIG,查看rabbitmq源码解释这个报错如下:
在这里插入图片描述
简单解释就是:由于消息体太小,amqp_table_t不能被序列化,因此消息不能被发送。
我的消息内容为:

{"hq_cate":"0","exchange_type":"1","stock_code":"519000","last_price":"100.0","close_price":"","close_flag":"1"}

在填充消息的amqp_basic_properties_t属性时,我加入了header信息,并且填充了很多字段:

properties._flags = AMQP_BASIC_DELIVERY_MODE_FLAG
		| AMQP_BASIC_CONTENT_TYPE_FLAG		//content_type属性有效
		| AMQP_BASIC_HEADERS_FLAG
		| AMQP_BASIC_TYPE_FLAG;

这些字段实际上并没有使用到,当时也只是测试使用,而amqp_table_t刚好是amqp_basic_properties_t的一个结构体成员:

typedef struct amqp_basic_properties_t_ {
  amqp_flags_t _flags;           /**< bit-mask of set fields */
  amqp_bytes_t content_type;     /**< content-type */
  amqp_bytes_t content_encoding; /**< content-encoding */
  amqp_table_t headers;          /**< headers */
  uint8_t delivery_mode;         /**< delivery-mode */
  uint8_t priority;              /**< priority */
  amqp_bytes_t correlation_id;   /**< correlation-id */
  amqp_bytes_t reply_to;         /**< reply-to */
  amqp_bytes_t expiration;       /**< expiration */
  amqp_bytes_t message_id;       /**< message-id */
  uint64_t timestamp;            /**< timestamp */
  amqp_bytes_t type;             /**< type */
  amqp_bytes_t user_id;          /**< user-id */
  amqp_bytes_t app_id;           /**< app-id */
  amqp_bytes_t cluster_id;       /**< cluster-id */
} amqp_basic_properties_t;

因此去掉了AMQP_BASIC_HEADERS_FLAG标志,release模式下消息也能正常发送。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Simple Simple

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值