【RabbitMQ 项目】客户端:消费者模块

和服务端的消费者实现方式一模一样,只不过服务端的消费者的回调函数是把消息封装成响应并发送,固定都是这个动作,而客户端消费者回调是用来处理消息,是用户自己设置的。

cpp 复制代码
#pragma once
#include "../common/Log.hpp"
#include "../common/message.pb.h"
#include <functional>
#include <memory>
#include <atomic>
#include <mutex>
#include <vector>
#include <unordered_map>
namespace ns_consumer
{
    using namespace ns_log;

    struct Consumer;
    using ConsumerPtr = std::shared_ptr<Consumer>;
    using ConsumerCallback_t = std::function<void(const ns_data::Message& msg)>;
    struct Consumer
    {
        std::string _id;
        std::string _qname;
        ConsumerCallback_t _callback;
        bool _autoAck;

        Consumer(const std::string id, const std::string &qname, ConsumerCallback_t callback, bool autoAck)
            : _id(id),
              _qname(qname),
              _callback(callback),
              _autoAck(autoAck)
        {
        }
    };
};
相关推荐
零号全栈寒江独钓17 小时前
基于c/c++实现linux/windows跨平台ntp时间戳服务器
linux·c语言·c++·windows
ulias21217 小时前
进程初识(1)
linux·运维·服务器·网络·c++
t***54417 小时前
Orwell Dev-C++ 和 Embarcadero Dev-C++ 哪个更好
开发语言·c++
BestOrNothing_201518 小时前
C++零基础到工程实战(4.3.4):vector数组搜索、删除、插入与排序
c++·vector·sort·find·insert·动态数组·erase
未秃头的程序猿18 小时前
从零到一:深入浅出分布式锁原理与Spring Boot实战(Redis + ZooKeeper)
spring boot·分布式·后端
Fuyo_111918 小时前
带你了解C++的类与对象(中)
c++
小苗卷不动18 小时前
UDP服务端收发流程
linux·c++·udp
Xiu Yan18 小时前
Java 转 C++ 系列:函数模板
java·开发语言·c++
小苗卷不动19 小时前
OJ练习之加减(中等偏难)
c++
我能坚持多久19 小时前
String类常用接口的实现
c语言·开发语言·c++