linux下SimpleAmqpClient的函数参数解释

来源:互联网 发布:whisper是什么软件 编辑:程序博客网 时间:2024/06/07 17:07

一. Channel类

1.创建Channel对象来创建与AMQP代理的连接

static ptr_t    Create (const std::string &host="127.0.0.1",                         int port=5672,                         const std::string &username="guest",                         const std::string &vhost="/",                         int frame_max=131072)host: 主机名或者AMQP代理的IP地址port: 连接AMQP代理的接口username: 用于认证AMQP代理的用户password: 用户的密码vhost: 我们要连接的AMQP的虚拟主机frame_max: 框架的最大值

2.在AMQP代理中创建一个队列(若存在便是声明)

std::string AmqpClient::Channel::DeclareQueue(const std::string & queue_name,                                              bool passive,                                              bool durable,                                              bool exclusive,                                              bool auto_delete,                                              const Table & arguments                                               ) queue_name: 队列的名字, 不能定义相同名字的队列(指的是名字相同性质却不同), 如果为空字符串, 则AMQP          `         会给我们生成一个临时队列, 它有一个系统给的名字passive: 如果为true, 但是队列之前并不存在, 就会返回false durable: 耐用性, 如果为true, 在AMQP代理restart后仍然存在, 为false就不存在了exclusive: 专用的, 只有唯一的client可以使用队列, 当连接断开后队列将被删除auto_delete: 当没有exchange绑定queue后, 队列将被删除arguments: 声明队列时需要的额外参数

3.传递消息给exchange

void AmqpClient::Channel::BasicPublish(const std::string & exchange_name,                                       const std::string & routing_key,                                       const BasicMessage::ptr_t message,                                       bool mandatory = false,                                       bool immediate = false                                        )exchange_name: 要接收消息的exchangerouting_key: 发消息时附带的路线值, 是为了发送到正确的队列message: 含有消息的 BasicMessage 对象mandatory: 若为true, 强制性, 如果消息不能给到指定队列会抛出异常immediate: 若为true, 消费者不能快速拿到消息会抛出异常 


图中的error. info. warning就是routing_key, x就是exchange

4.消费消息

std::string AmqpClient::Channel::BasicConsume(const std::string & queue,                                              const std::string & consumer_tag = "",                                              bool no_local = true,                                              bool no_ack = true,                                              bool exclusive = true,                                              boost::uint16_t message_prefetch_count=1                                               ) queue: 订阅的队列的名称consumer_tag: 消费者的名称no_local: 官方文档没有解释...no_ack: 若为false, 当消息收到后会通知队列exclusive: 若为true, 则只有这个消费者可以订阅这个队列message_prefetch_count: AMQP代理会发送的未确认接收的消息的次数, 值为0意为没有限制, 如果超过1`                      ,AMQP代理就可以在消息被一个用户处理时(还没处理完)继续发给另一个用户, 谁`                       先处理完给谁          

5.从使用这个channel的消费者拿到消息

bool AmqpClient::Channel::BasicConsumeMessage(Envelope::ptr_t & envelope,                                              int timeout = -1                                               ) envelope: 接受的消息对象timeout: 接收消息等待的时间(单位是毫秒), 0为非阻塞(瞬间)读, -1为不限时长

二. BasicMessage类

  1. 创建BasicMessage对象
static ptr_t AmqpClient::BasicMessage::Create(const std::string & body) 

2.获得消息内容

std::string AmqpClient::BasicMessage::Body() const

三.Envelope类

  1. 获得BasicMessage对象
BasicMessage::ptr_t AmqpClient::Envelope::Message() const