The current repo belongs to Closed status, and some functions are restricted. For details, please refer to the description of repo status
1 Star 0 Fork 6

freehu/RabbitmqConnect
Closed

forked from 寻根/RabbitmqConnect
Closed
 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

RabbitmqConnect介绍

1、RabbitmqConnect是基于C++11实现的简单易用的rabbitmq客户端。

2、源码只包含一个头文件与一个示例代码,无需编译安装,真正做到零依赖。

3、RabbitmqConnect针对RabbitMQ C Client进行封装,提供给用户更友好的接口。

4、RabbitmqConnect追求极简易用,只提供了以下方法:

  • send发送消息
  • recv接收消息
  • login身份认证
  • close关闭连接
  • connect连接服务器

安装方法

1、下载源码

git clone https://gitee.com/xungen/rabbitmqconnect.git

2、直接在工程中包含RabbitmqConnect.h头文件

3、利用RabbitmqConnect发送与接收消息示例代码如下

1.发送消息
RabbitmqConnect conn;

if (conn.connect(host, port) && conn.login(user, passwd))
{
	cout << "连接消息队列成功" << endl;

	if (conn.send(exchange, queuename, "message") < 0)
	{
		cout << "发送消息成功" << endl;
	}
	else
	{
		cout << "发送消息失败" << endl;
	}
}
2.接收消息
while (true)
{
	RabbitmqConnect conn;

	if (conn.connect(host, port) && conn.login(user, passwd))
	{
		cout << "开始监听消息队列[" << exchange << "][" << queuename << "]" << endl;

		while (true)
		{
			conn.recv(exchange, queuename, [](const char* data, int len){
				string msg(data, data + len);

				cout << "收到消息[" << msg << "]" << endl;
			});
			
			//连接异常需要重连
			if (conn.getErrorCode() == AMQP_STATUS_SOCKET_ERROR) break;
		}

		cout << "监听消息队列失败[" << conn.getErrorString() << "]" << endl;
	}
	else
	{
		cout << "连接消息队列[" << host << ":" << port << "][" << user << "]失败" << endl;
	}

	sleep(5);
}



RabbitMQ官网
RabbitMQ客户端
RabbitMQ C Client下载

Empty file

About

基于C++11的RabbitmqConnect客户端封装 expand collapse
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/freehu/rabbitmqconnect.git
git@gitee.com:freehu/rabbitmqconnect.git
freehu
rabbitmqconnect
RabbitmqConnect
master

Search

Dd8185d8 1850385 E526c682 1850385