【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)
        {
        }
    };
};
相关推荐
SunkingYang12 分钟前
程序崩溃闪退——MFC共享内存多次OpenFileMapping和MapViewOfFile而没有相应的UnmapViewOfFile和CloseHandle
c++·mfc·共享内存·崩溃·闪退·close·openfilemapping
问君能有几多愁~22 分钟前
C++ 日志实现
java·前端·c++
JANGHIGH1 小时前
c++ 多线程(二)
开发语言·c++
珑墨1 小时前
【浏览器】页面加载原理详解
前端·javascript·c++·node.js·edge浏览器
Surpass余sheng军2 小时前
AI 时代下的网关技术选型
人工智能·经验分享·分布式·后端·学习·架构
a伊雪2 小时前
c++ 引用参数
c++·算法
应茶茶3 小时前
从 C 到 C++:详解不定参数的两种实现方式(va_args 与参数包)
c语言·开发语言·c++
code bean4 小时前
【C++】Scoop 包管理器与 MinGW 工具链详解
开发语言·c++
hetao17338374 小时前
2025-12-11 hetao1733837的刷题笔记
c++·笔记·算法
saltymilk5 小时前
C++ 语言特性的变更可能让你的防御成为马奇诺防线
c++