openstack性能测试器(3):移植rabbitmq-c

rabbitmq

rabbitmq是AMQP的一个具体实现。与之类似的还有apache的qpid。rabbitmq的官网是http://www.rabbitmq.com/

我要做的是一个收发消息的模拟器,那么就用client就可以了。rabbitmq提供了各种语言的client版本,其中JAVA、C#、ErLang是官方维护的亲儿子版本。至于C语言的版本,则被归类到了other languages,下载链接是http://www.rabbitmq.com/devtools.html,C版本的链接是https://github.com/alanxz/rabbitmq-c

移植

编译rabbitmq-c

生产环境用的是suse,那边哥们给我的测试环境无法mount到我的本机,所以,只能在我docker ubuntu14.04来先验证一下。

CMake

下载https://cmake.org/files/v3.4/cmake-3.4.0-rc2.tar.gz

1
2
3
4
wget https://cmake.org/files/v3.4/cmake-3.4.0-rc2.tar.gz
tar -xzvf cmake-3.4.0-rc2.tar.gz
cd cmake-3.4.0-rc2
./bootstrap && make && sudo make install

./bootstrap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
Curses libraries were not found. Curses GUI for CMake will not be built.
-- Looking for elf.h
-- Looking for elf.h - found
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - NOTFOUND
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
-- Performing Test run_pic_test
-- Performing Test run_pic_test - Success
-- Performing Test run_inlines_hidden_test
-- Performing Test run_inlines_hidden_test - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xh/save/code/cmake-3.4.0-rc2
---------------------------------------------
CMake has bootstrapped. Now run make.

make

1
2
3
4
5
6
7
8
9
10
11
[ 61%] Built target cmjsoncpp
Scanning dependencies of target CMakeLib
[ 61%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmArchiveWrite.cxx.o
[ 61%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmBootstrapCommands1.cxx.o
[ 61%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmBootstrapCommands2.cxx.o
[ 61%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmCacheManager.cxx.o
[ 61%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmCommands.cxx.o
[ 61%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmCLocaleEnvironmentScope.cxx.o
[ 62%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmCommandArgumentLexer.cxx.o
[ 62%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmCommandArgumentParser.cxx.o
[ 62%] Building CXX object Source/CMakeFiles/CMakeLib.dir/cmCommandArgumentParserHelper.cxx.o

make install

1
2
3
4
-- Installing: /usr/local/share/cmake-3.4/Templates/UtilityHeader.dsptemplate
-- Installing: /usr/local/share/cmake-3.4/Templates/CTestScript.cmake.in
-- Installing: /usr/local/share/cmake-3.4/Templates/CPack.GenericDescription.txt
-- Installing: /usr/local/share/cmake-3.4/Templates/CPack.GenericLicense.txt

version

1
2
cmake --version
# cmake version 3.4.0-rc2

openssl

1
2
3
4
5
6
7
wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
tar -xzvf openssl-1.0.2d
cd openssl-1.0.2d
./config
make
make test
make install

version一下看看

1
2
openssl version
# OpenSSL 1.0.1f 6 Jan 2014

make

1
2
3
4
5
git clone git@github.com:alanxz/rabbitmq-c.git
cd rabbitmq-c
mkdir build && cd build
cmake ..
cmake --build . --config BUILD_TOOLS=OFF

cmake ..时会提示找不到xmlto等等,因为我不需要生成辅助工具(文档、命令行工具等等),暂时不管它。
BUILD_TOOLS=OFF就表示不生成辅助工具

一路编译没有报错,至此,我们的rabbitmq就编译成功了,接下来就是要把librabbitmq移植到现有代码中。

移植过程

  • 拷贝librabbitmq到原有代码中
  • 在makefile里加上librabbitmq的路径
  • make,提示说找不到amqp_framing.h,原因是include用的是<>,而amqp_framing.h就在同一个目录。
  • sed -i s/<amqp_framing.h>/\”amqp_framing.h\”/g改成相对路径,再次make,不报这个错了。
  • 找不到threads.h,原因是没有把librabbitmq/unix-I,所以需要改以下路径为unix/threads.h
  • 找不到AMQP_PLATFORM,这个是在config.h里定义的。看了下报错的c文件,确实有include了config.h,但为什么还报这个错呢?

    1
    2
    3
    #ifdef HAVE_CONFIG_H
    #include "config.h"
    #endif
  • 原因就在于HAVE_CONFIG_H了,在makefile的gcc后加上-DHAVE_CONFIG_H,再次编译,就OK了。

在ubuntu上已经搞定,接下来就是迁移到suse上。
关键点就在于config.h,因为config.h包含了内核版本以及epoll等等,所以需要在suse上编译一下rabbitmq-c,然后把suse上的config.h替换ubuntu上的config.h,编译就OK了。


本博客欢迎转发,但请保留原作者信息
github:codejuan
博客地址:http://blog.decbug.com/