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模式下消息也能正常发送。