【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)
        {
        }
    };
};
相关推荐
极客BIM工作室16 小时前
OCCT gp_Trsf 三维变换类深度剖析:经典设计与底层陷阱
c++
醉城夜风~16 小时前
类和对象III
开发语言·c++
kyle~17 小时前
DDS分布式实时系统---自省机制
开发语言·分布式·机器人·c#·接口·ros2
alwaysrun17 小时前
C++之常量体系const
c++·后端·程序员
郝学胜_神的一滴17 小时前
CMake 016:深入浅出变量核心用法
c++·cmake
学逆向的17 小时前
C++模板
开发语言·c++·网络安全
凡人叶枫18 小时前
Effective C++ 条款24:若所有参数皆须要类型转换,请为此采用 non-member 函数
linux·前端·c++·算法·嵌入式开发
q210306337218 小时前
kafka启动几秒后挂了,重启多次无果
分布式·kafka
j7~18 小时前
【C++】STL--string类--拆析解剖string类的实现以及string类的底层详解(2)
开发语言·c++·浅拷贝·深拷贝·string类的实现·string拷贝构造·string赋值重载
DogDaoDao18 小时前
C++核心技术深度剖析:从底层原理到工程实践
开发语言·c++·面试·程序员·指针·虚函数