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 5

shengzhe8688 / RabbitmqConnect
Closed

forked from 寻根 / RabbitmqConnect
Closed
 
Gitee — Enterprise-level DevOps R&D management platform
Join Gitee
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
readme.md

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下载

Repository Comments ( 0 )

Sign in for post a comment

About

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

Releases

No release

Contributors

All

Activities

load more
can not load any more
C++
1
https://gitee.com/shengzhe8688/rabbitmqconnect.git
git@gitee.com:shengzhe8688/rabbitmqconnect.git
shengzhe8688
rabbitmqconnect
RabbitmqConnect
master

Search

181749 a2d7925e 1850385 181749 9f8568a7 1850385