【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)
        {
        }
    };
};
相关推荐
D_evil__10 分钟前
[C++高频精进] 并发编程:线程基础
c++
赞奇科技Xsuperzone44 分钟前
【首发】DGX Spark 三机互连跑 Qwen3-235B-A22B-FP8!
大数据·分布式·spark
Mr_WangAndy1 小时前
C++17 新特性_第二章 C++17 语言特性_std::any和string_view
c++·string_view·c++40周年·c++17新特性·c++新特性any
e***98571 小时前
RabbitMQ HAProxy 负载均衡
rabbitmq·负载均衡·ruby
水天需0102 小时前
C++ 三种指针转换深度解析
c++
言言的底层世界3 小时前
c++中STL容器及算法等
开发语言·c++·经验分享·笔记
Mr_WangAndy3 小时前
C++17 新特性_第一章 C++17 语言特性___has_include,u8字符字面量
c++·c++40周年·c++17新特性·__has_include·u8字面量
liu****3 小时前
八.函数递归
c语言·开发语言·数据结构·c++·算法
Vanranrr4 小时前
C++临时对象与悬空指针:一个导致资源加载失败的隐藏陷阱
服务器·c++·算法