# the-rabbit-mq **Repository Path**: limou3434/cpp-rabbit-mq ## Basic Information - **Project Name**: the-rabbit-mq - **Description**: 分布式系统消息队列,仿照RQ消息队列进行模拟实现。 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-15 - **Last Updated**: 2025-01-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # [cpp-rabbit-mq](https://gitee.com/limou3434/cpp-rabbit-mq) ## 仓库作者 limou3434 ## 项目概要 消息队列实际上是由阻塞队列封装的一种独立服务器程序,主要是实现跨主机的生产者消费者模型的服务器, 市面常见的消息队列组件有: 1. RabbitMQ(主要模拟对象) 2. Kafka 3. RocketMQ 4. ActiveMQ 本项目所仿照的是 RabbitMQ 中发布订阅的功能。客户端订阅了某个队列的数据,那服务端就把某个队列的数据推送给客户端。 ## 技术选择 1. 开发语言:C99、C++98、C++11 2. 开发环境:CentosOS 7(Linux)、VSCode 1.89.1 3. 编译环境:gcc/g++ 7.3.1 4. 网路通信:自主应用层协议、Protobuf 3.20.2、muduo 5. 源数据库:本地化轻量级 SQLite 3.7.17 数据库(当前无需使用 MySQL 跨主机存储) 6. 单元测试:Gtest 1.6.0 7. 构建工具:CMake 2.8.12.2 8. 传输文件:lrzsz 0.12.20 ## 环境配置 ``` shell # 安装 wget 下载工具 $ sudo yum install wget # 更换软件源 $ sudo mv /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.bak $ sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo $ sudo yum clean all $ sudo yum makecache # 安装 scl 软件源 $ sudo yum install centos-release-scl-rh centos-release-scl $ sudo yum install epel-release # 安装 lrzsz 传输工具 $ sudo yum install lrzsz # 安装 gcc/g++ 编译器 $ sudo yum install devtoolset-7-gcc devtoolset-7-gcc-c++ $ echo "source /opt/rh/devtoolset-7/enable" >> ~/.bashrc $ source ~/.bashrc # 每次使用该版本的 gcc/g++ 时候就需要使用该指令 # 安装 git $ sudo yum install git $ git --version # 检查版本 # 安装 cmake $ sudo yum install cmake $ cmake --version # 检查版本 # 安装 Protobuf $ sudo yum install autoconf automake libtool curl make gcc-c++ unzip # 安装依赖库 $ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.2/protobufall-3.20.2.tar.gz # 下载安装包 $ tar -zxf protobuf-all-3.20.2.tar.gz # 解压安装包 $ cd protobuf-3.20.2 # 进入源代码文件 $ ./autogen.sh # 检测环境 $ ./configure # 设置配置 $ make # 编译 $ sudo make install # 使用 root 进行安装 $ protoc --version # 检查版本 # 安装 Muduo $ git clone https://github.com/chenshuo/muduo.git # 或者使用 wget https://gitee.com/hansionz/mq/raw/master/resource/muduomaster.zip $ unzip muduo-master.zip $ cd muduo-master $ sudo yum install gcc-c++ cmake make zlib zlib-devel boost-devel # 安装 boost 相关依赖 $ ./build.sh # 如果构建失败, 就修改 CMakeLists.txt 文件注释禁用 -Werror 选项再重新执行这个语句 $ sudo ./build.sh install # 安装 $ cd ~/build/release-cpp11/bin # 找到测试程序 $ sudo vim /etc/ld.so.conf # 添加 /usr/local/lib 路径在该文本文件的最上面 $ sudo ldconfig # 加载配置 $ ./protobuf_server 9091 # 运行服务端 $ ./protobuf_client 0.0.0.0 9091 # 运行客户端 # 出现响应即可, 注意 build 库不要被删除 # 安装 SQLite3 $ sudo yum install sqlite-devel $ sqlite3 --version # 检查版本 # 安装 Gtest $ sudo yum install epel-release $ sudo yum install dnf $ sudo dnf install dnf-plugins-core $ sudo dnf install gtest gtest-devel $ gtest-config --version # 检查版本 $ vim test.cpp # 编辑代码进行测试, 写入如下代码 // test.cpp #include int add(int a, int b) { return a + b; } TEST(testCase, test1) { EXPECT_EQ(add(2, 3), 5); } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } $ g++ test.cpp -lgtest -lgtest_main -pthread $ ./a.out [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from testCase [ RUN ] testCase.test1 [ OK ] testCase.test1 (0 ms) [----------] 1 test from testCase (0 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (0 ms total) [ PASSED ] 1 test. ``` ## 代码目录 ``` shell $ tree cpp-rabbit-mq |-- README.md |-- document |-- config |-- include |-- library |-- source `-- vendor ``` ## 使用方法 1. 直接 `git clone` 克隆源代码,但是需要配置相关环境(`shell` 脚本待补充) 2. 直接下载编译好的静态库以及头文件