2026-06-24 16:37:32 +08:00
|
|
|
|
#ifndef SIMPLEPRODUCER_H
|
|
|
|
|
|
#define SIMPLEPRODUCER_H
|
2025-05-09 16:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2026-06-24 16:37:32 +08:00
|
|
|
|
|
2025-01-16 16:17:01 +08:00
|
|
|
|
#include "../json/mms_json_inter.h"
|
2026-06-24 16:37:32 +08:00
|
|
|
|
|
2026-04-28 11:44:40 +08:00
|
|
|
|
#include "../rocketmq/DefaultMQProducer.h"
|
|
|
|
|
|
#include "../rocketmq/MQMessage.h"
|
|
|
|
|
|
#include "../rocketmq/SendResult.h"
|
|
|
|
|
|
#include "../rocketmq/SessionCredentials.h"
|
|
|
|
|
|
#include "../rocketmq/MQMessageExt.h"
|
|
|
|
|
|
#include "../rocketmq/ConsumeType.h"
|
|
|
|
|
|
#include "../rocketmq/MQMessageListener.h"
|
2025-05-09 16:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
2025-05-12 16:43:42 +08:00
|
|
|
|
#include <iostream>
|
2026-04-28 11:44:40 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
2026-06-24 16:37:32 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* lnk20260622 修改:
|
|
|
|
|
|
* 支持 RocketMQ / Redis Streams 双后端。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 编译时:两套源码都编译进去。
|
|
|
|
|
|
* 运行时:通过配置文件 [MQ] Backend=rocketmq 或 redisstream 选择。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 业务层仍然使用:
|
|
|
|
|
|
* rocketmq::MQMessageExt
|
|
|
|
|
|
* rocketmq::ConsumeStatus
|
|
|
|
|
|
* Subscription
|
|
|
|
|
|
* InitializeProducer()
|
|
|
|
|
|
* rocketmq_producer_send()
|
|
|
|
|
|
* InitializeConsumer()
|
|
|
|
|
|
*
|
|
|
|
|
|
* 不需要业务层判断当前走 RocketMQ 还是 RedisStream。
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 关键:
|
|
|
|
|
|
* mq_compat.h 里必须定义兼容的:
|
|
|
|
|
|
* namespace rocketmq {
|
|
|
|
|
|
* enum ConsumeStatus;
|
|
|
|
|
|
* class MQMessageExt;
|
|
|
|
|
|
* }
|
|
|
|
|
|
*
|
|
|
|
|
|
* 如果实际编译 RocketMQ,也可以让 mq_compat.h 内部 include RocketMQ 原头。
|
|
|
|
|
|
*/
|
|
|
|
|
|
//#include "../mq/mq_compat.h"
|
|
|
|
|
|
#include "../rocketmq/SimpleProducer.h"
|
|
|
|
|
|
|
2026-04-28 11:44:40 +08:00
|
|
|
|
using namespace rocketmq;
|
2025-05-09 16:53:07 +08:00
|
|
|
|
|
2026-06-24 16:37:32 +08:00
|
|
|
|
void RocketMQ_rocketmq_producer_send(const std::string& body,
|
2026-04-28 11:44:40 +08:00
|
|
|
|
const std::string& topic,
|
|
|
|
|
|
const std::string& tags,
|
|
|
|
|
|
const std::string& keys);
|
2026-06-24 16:37:32 +08:00
|
|
|
|
|
2025-05-09 16:53:07 +08:00
|
|
|
|
extern "C" {
|
|
|
|
|
|
void rocketmq_test_rt();
|
|
|
|
|
|
void rocketmq_test_ud();
|
|
|
|
|
|
void rocketmq_test_rc();
|
|
|
|
|
|
void rocketmq_test_log();
|
|
|
|
|
|
void rocketmq_test_set();
|
|
|
|
|
|
void rocketmq_test_only();
|
2026-06-24 16:37:32 +08:00
|
|
|
|
void rocketmq_test_300(int mpnum, int front_index, int type);
|
2025-05-09 16:53:07 +08:00
|
|
|
|
}
|
2026-06-24 16:37:32 +08:00
|
|
|
|
|
2025-05-09 16:53:07 +08:00
|
|
|
|
extern void my_rocketmq_send(Ckafka_data_t& data);
|
|
|
|
|
|
|
2026-06-24 16:37:32 +08:00
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
// 生产者统一入口
|
|
|
|
|
|
void RocketMQ_InitializeProducer();
|
|
|
|
|
|
void RocketMQ_ShutdownAndDestroyProducer();
|
2025-05-09 16:53:07 +08:00
|
|
|
|
|
2026-06-24 16:37:32 +08:00
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
// 消费者统一入口
|
2026-04-28 11:44:40 +08:00
|
|
|
|
typedef ConsumeStatus (*MessageCallBack)(
|
|
|
|
|
|
const MQMessageExt& msg
|
|
|
|
|
|
);
|
2025-05-09 16:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
struct Subscription {
|
|
|
|
|
|
std::string topic;
|
|
|
|
|
|
std::string tag;
|
|
|
|
|
|
MessageCallBack callback;
|
2026-04-28 11:44:40 +08:00
|
|
|
|
|
|
|
|
|
|
Subscription(const std::string& t,
|
|
|
|
|
|
const std::string& tg,
|
|
|
|
|
|
MessageCallBack cb)
|
|
|
|
|
|
: topic(t), tag(tg), callback(cb) {}
|
2025-05-09 16:53:07 +08:00
|
|
|
|
};
|
2026-06-24 16:37:32 +08:00
|
|
|
|
|
|
|
|
|
|
void RocketMQ_InitializeConsumer(const std::string& consumerName,
|
|
|
|
|
|
const std::string& nameServer,
|
|
|
|
|
|
const std::vector<Subscription>& subscriptions);
|
|
|
|
|
|
|
|
|
|
|
|
void RocketMQ_ShutdownAndDestroyConsumer();
|
|
|
|
|
|
|
|
|
|
|
|
void RocketMQ_rocketmq_consumer_receive(
|
|
|
|
|
|
const std::string& consumerName,
|
|
|
|
|
|
const std::string& nameServer,
|
|
|
|
|
|
const std::vector<Subscription>& subscriptions);
|
|
|
|
|
|
|
|
|
|
|
|
void rocketmq_producer_send(const std::string& body,
|
|
|
|
|
|
const std::string& topic,
|
|
|
|
|
|
const std::string& tags,
|
|
|
|
|
|
const std::string& keys);
|
|
|
|
|
|
void InitializeProducer();
|
|
|
|
|
|
void ShutdownAndDestroyProducer();
|
2026-04-28 11:44:40 +08:00
|
|
|
|
void InitializeConsumer(const std::string& consumerName,
|
|
|
|
|
|
const std::string& nameServer,
|
|
|
|
|
|
const std::vector<Subscription>& subscriptions);
|
|
|
|
|
|
void ShutdownAndDestroyConsumer();
|
2025-05-09 16:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
void rocketmq_consumer_receive(
|
|
|
|
|
|
const std::string& consumerName,
|
|
|
|
|
|
const std::string& nameServer,
|
|
|
|
|
|
const std::vector<Subscription>& subscriptions);
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
2026-06-24 16:37:32 +08:00
|
|
|
|
|
|
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SIMPLEPRODUCER_H
|