Ai
1 Star 0 Fork 0

*&c++/webdisk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mq.h 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
geoff 提交于 2023-08-09 23:32 +08:00 . initialize webdisk project
#ifndef __WD_MQ_HPP__
#define __WD_MQ_HPP__
#include <string>
#include <SimpleAmqpClient/SimpleAmqpClient.h>
using std::string;
struct AmqpInfo{
string url = "amqp://guest:guest@localhost:5672";
string exchanger = "uploadserver.trans";
string ossqueue = "uploadserver.trans.oss";
string routingkey = "oss";
};
class MessagePublisher
{
public:
MessagePublisher(const AmqpInfo & info, const string & msg)
: _info(info)
, _msg(msg)
, _channel(AmqpClient::Channel::Create())
{
}
void doPublish()
{
AmqpClient::BasicMessage::ptr_t message = AmqpClient::BasicMessage::Create(_msg);
_channel->BasicPublish(_info.exchanger, _info.routingkey, message);
}
private:
AmqpInfo _info;
string _msg;
AmqpClient::Channel::ptr_t _channel;
};
class MessageConsumer
{
public:
MessageConsumer(const AmqpInfo & info)
: _info(info)
, _channel(AmqpClient::Channel::Create())
{
_channel->BasicConsume(_info.ossqueue);
}
bool doConsume(string & msg) {
AmqpClient::Envelope::ptr_t envelope;
bool flag = _channel->BasicConsumeMessage(envelope, 3000);
if(flag == false) {
printf("consume message timeout\n");
return false;
}
msg = envelope->Message()->Body();
return true;
}
private:
AmqpInfo _info;
AmqpClient::Channel::ptr_t _channel;
};
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/learntocodewithc/webdisk.git
git@gitee.com:learntocodewithc/webdisk.git
learntocodewithc
webdisk
webdisk
master

搜索帮助