【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)
        {
        }
    };
};
相关推荐
苏宸啊3 小时前
IPC管道
linux·c++
BestOrNothing_20154 小时前
ROS2 话题通信实战:消息对象、Publisher 发布器与 Subscriber 订阅器保姆级教程
c++·ros2·subscriber·publisher·话题通信
周末也要写八哥5 小时前
分布式技术之单机锁
分布式
艾iYYY5 小时前
string 类的模拟实现
android·服务器·c语言·c++·算法
为何创造硅基生物5 小时前
C++ virtual void StartNetwork() = 0; // 纯虚:子类必须实现,否则不能 new。
c++
知无不研6 小时前
对套接字的深入理解
linux·服务器·网络·c++·socket·网络套接字
hai3152475437 小时前
FlashAttention C语言(C++)实现(展示版)
c语言·开发语言·c++·人工智能·算法
Shan12057 小时前
浅谈:分布式锁的系统分类
分布式
阿文的代码库7 小时前
干货分享——分布式锁的典型案例
分布式
wuminyu8 小时前
Java锁机制之Java对象重量级锁源码剖析
java·linux·c语言·jvm·c++