【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)
        {
        }
    };
};
相关推荐
Abcdzzr9 分钟前
2026/4/6 Windows安装Kafka
分布式·kafka
森G21 分钟前
45、QGraphicsScene 与 QGraphicsView 框架---------绘图
c++·qt
「QT(C++)开发工程师」25 分钟前
C++17三大实用特性详解:折叠表达式、结构化绑定与constexpr if
jvm·c++
zxfBdd25 分钟前
Spark Map算子异常处理方法
大数据·分布式·spark
杜子不疼.26 分钟前
Python + Ollama 本地跑大模型:零成本打造私有 AI 助手
开发语言·c++·人工智能·python
小此方26 分钟前
Re:思考·重建·记录 现代C++ C++11篇 (一) 列表初始化&Initializer_List
开发语言·c++·stl·c++11·现代c++
计算机安禾29 分钟前
【数据结构与算法】第29篇:红黑树原理与C语言模拟
c语言·开发语言·数据结构·c++·算法·visual studio
一个有温度的技术博主42 分钟前
告别单点瓶颈:Redis主从架构与读写分离实战
redis·分布式·缓存·架构
AbandonForce1 小时前
C++ STL list容器模拟实现
开发语言·c++·list
哦豁灬1 小时前
bitbrick_k1集群使用prima_cpp分布式部署大模型推理
分布式