RabbitmqClient.hpp
4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include <string>
#include <memory>
#include <vector>
typedef void (*RABBITMQ_CALLBACK)(void* contex, const char * msg);
class CRabbitmqClient
{
/**
* @brief not single instance;
*
*/
public:
static CRabbitmqClient* get_instance();
static void destory(CRabbitmqClient *instance);
virtual int Connect(const std::string &strHostname, int iPort, const std::string &strUser, const std::string &strPasswd, const std::string &vhost = "/") = 0;
/**
* @brief Disconnect 关闭连接
*
* @return int 等于0值成功, 小于0代表错误
*/
virtual int Disconnect() = 0;
/**
* @brief ExchangeDeclare 声明exchange
* @param [in] strExchange
* @param [in] strType
* @return 等于0值代表成功创建exchange,小于0代表错误
*/
virtual int ExchangeDeclare(const std::string &strExchange, const std::string &strType, const bool durable = false) = 0;
/**
* @brief QueueDeclare 声明消息队列
* @param [in] strQueueName 消息队列实例
* @param
* @return 等于0值代表成功创建queue,小于0代表错误
*/
virtual int QueueDeclare(const std::string &strQueueName, const bool durable = false) = 0;
/**
* @brief QueueBind 将队列,交换机和绑定规则绑定起来形成一个路由表
* @param [in] strQueueName 消息队列
* @param [in] strExchange 交换机名称
* @param [in] strBindKey 路由名称 “msg.#” “msg.weather.**”
* @return 等于0值代表成功绑定,小于0代表错误
*/
virtual int QueueBind(const std::string &strQueueName, const std::string &strExchange, const std::string &strBindKey) = 0;
/**
* @brief QueueUnbind 将队列,交换机和绑定规则绑定解除
* @param [in] strQueueName 消息队列
* @param [in] strExchange 交换机名称
* @param [in] strBindKey 路由名称 “msg.#” “msg.weather.**”
* @return 等于0值代表成功绑定,小于0代表错误
*/
virtual int QueueUnbind(const std::string &strQueueName, const std::string &strExchange, const std::string &strBindKey) = 0;
/**
* @brief QueueDelete 删除消息队列。
* @param [in] strQueueName 消息队列名称
* @param [in] iIfUnused 消息队列是否在用,1 则论是否在用都删除
* @return 等于0值代表成功删除queue,小于0代表错误
*/
virtual int QueueDelete(const std::string &strQueueName, int iIfUnused) = 0;
/**
* @brief Publish 发布消息
* @param [in] strMessage 消息实体
* @param [in] strExchange 交换器
* @param [in] strRoutekey 路由规则
* 1.Direct Exchange – 处理路由键。需要将一个队列绑定到交换机上,要求该消息与一个特定的路由键完全匹配。
* 2.Fanout Exchange – 不处理路由键。将队列绑定到交换机上。一个发送到交换机的消息都会被转发到与该交换机绑定的所有队列上。
* 3.Topic Exchange – 将路由键和某模式进行匹配。此时队列需要绑定要一个模式上。符号“#”匹配一个或多个词,符号“*”匹配不多不少一个词。
* 因此“audit.#”能够匹配到“audit.irs.corporate”,但是“audit.*” 只会匹配到“audit.irs”
* @return 等于0值代表成功发送消息实体,小于0代表发送错误
*/
virtual int Publish(const std::string &strMessage, const std::string &strExchange, const std::string &strRoutekey) = 0;
/**
* @brief consumer 消费消息
* @param [in] strQueueName 队列名称
* @param [out] message_array 获取的消息实体
* @param [int] GetNum 需要取得的消息个数
* @param [int] timeout 取得的消息是延迟,若为NULL,表示持续取,无延迟,阻塞状态
* @return 等于0值代表成功,小于0代表错误,错误信息从ErrorReturn返回
*/
virtual int Consumer_limit(const std::string &strQueueName, std::vector<std::string> &message_array, int GetNum = 1, struct timeval *timeout = NULL) = 0;
/**
* @brief consumer 消费消息
* @param [in] strQueueName 队列名称
* @param [out] message_array 获取的消息实体
* @param [int] GetNum 需要取得的消息个数
* @param [int] timeout 取得的消息是延迟,若为NULL,表示持续取,无延迟,阻塞状态
* @return 等于0值代表成功,小于0代表错误,错误信息从ErrorReturn返回
*/
virtual int Consumer(const std::string &strQueueName, RABBITMQ_CALLBACK callback, void * contex, struct timeval *timeout = NULL) = 0;
};