操作系统环境:Ubuntu 10.04的桌面
下载源码:RabbitMQ的-C
RabbitMQ的Ç客户端已经搬迁到了链接地址https://github.com/alanxz/rabbitmq-c
移植到嵌入式目标板OpenWRT的上,本身的Ubuntu 10.04已经编译过的OpenWRT。
操作步骤:
leekwen@iots01:~$ cat /etc/issue
Ubuntu 10.04.4 LTS \n \l
leekwen@iots01:~$ git clone https://github.com/alanxz/rabbitmq-c
Initialized empty Git repository in /home/leekwen/rabbitmq-c/.git/
remote: Counting objects: 4336, done.
remote: Compressing objects: 100% (1778/1778), done.
remote: Total 4336 (delta 2521), reused 4328 (delta 2515)
Receiving objects: 100% (4336/4336), 2.25 MiB | 85 KiB/s, done.
Resolving deltas: 100% (2521/2521), done.
leekwen@iots01:~/rabbitmq-c$ cat README.md
# RabbitMQ C AMQP client library
[![Build Status](https://secure.travis-ci.org/alanxz/rabbitmq-c.png?branch=master)](http://travis-ci.org/alanxz/rabbitmq-c)
## Introduction
This is a C-language AMQP client library for use with v2.0+ of the
[RabbitMQ](http://www.rabbitmq.com/) broker.
-
Announcements regarding the library are periodically made on the
rabbitmq-discuss mailing list:
-
## Latest Stable Version
The latest stable release of [rabbitmq-c is v0.5.0](https://github.com/alanxz/rabbitmq-c/releases/tag/v0.5.0).
A complete list of changes can be found in the [Change Log](ChangeLog.md)
The v0.5.0 source tarball can be downloaded from:
API documentation for v0.5.0+ can viewed from:
## Getting started
### Building and installing
#### Prereqs:
- [CMake v2.6 or better](http://www.cmake.org/)
- A C compiler (GCC 4.4+, clang, and MSVC are test. Other compilers may also
work)
- *Optionally* [OpenSSL](http://www.openssl.org/) v0.9.8+ to enable support for
connecting to RabbitMQ over SSL/TLS
- *Optionally* [POpt](http://freecode.com/projects/popt) to build some handy
command-line tools.
- *Optionally* [XmlTo](https://fedorahosted.org/xmlto/) to build man pages for
the handy command-line tools
- *Optionally* [Doxygen](http://www.stack.nl/~dimitri/doxygen/) to build
developer API documentation.
After downloading and extracting the source from a tarball to a directory.
([see above][Latest Stable Version]), the commands to build rabbitmq-c on most
systems are:
mkdir build && cd build
cmake ..
cmake --build [--config Release] .
The --config Release flag should be used in multi-configuration generators e.g.,
Visual Studio or XCode.
It is also possible to point the CMake GUI tool at the CMakeLists.txt in the root of
the source tree and generate build projects or IDE workspace
Installing the library and optionally specifying a prefix can be done with:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
cmake --build . [--config Release] --target install
More information on CMake can be found on its FAQ (http://www.cmake.org/Wiki/CMake_FAQ)
Other interesting flags that can be passed to CMake:
* `BUILD_EXAMPLES=ON/OFF` toggles building the examples. ON by default.
* `BUILD_SHARED_LIBS=ON/OFF` toggles building rabbitmq-c as a shared library.
ON by default.
* `BUILD_STATIC_LIBS=ON/OFF` toggles building rabbitmq-c as a static library.
OFF by default.
* `BUILD_TESTS=ON/OFF` toggles building test code. ON by default.
* `BUILD_TOOLS=ON/OFF` toggles building the command line tools. By default
this is ON if the build system can find the POpt header and library.
* `BUILD_TOOLS_DOCS=ON/OFF` toggles building the man pages for the command line
tools. By default this is ON if BUILD_TOOLS is ON and the build system can
find the XmlTo utility.
* `ENABLE_SSL_SUPPORT=ON/OFF` toggles building rabbitmq-c with SSL support. By
default this is ON if the OpenSSL headers and library can be found.
* `ENABLE_THREAD_SAFETY=ON/OFF` toggles OpenSSL thread-safety. By default this
is ON
* `BUILD_API_DOCS=ON/OFF` - toggles building the Doxygen API documentation, by
default this is OFF
#### autotools
For legacy purposes, a GNU autotools based build system is also maintained. The required
utilities you need are autoconf v2.59+, automake v1.9+, libtool v2.2+, and pkg-config.
Then the standard autotools build procedure will build rabbitmq-c:
autoreconf -i
./configure
make
make install
## Running the examples
Arrange for a RabbitMQ or other AMQP server to be running on
`localhost` at TCP port number 5672.
In one terminal, run
./examples/amqp_listen localhost 5672 amq.direct test
In another terminal,
./examples/amqp_sendstring localhost 5672 amq.direct test "hello world"
You should see output similar to the following in the listener's
terminal window:
Result 1
Frame type 1, channel 1
Method AMQP_BASIC_DELIVER_METHOD
Delivery 1, exchange amq.direct routingkey test
Content-type: text/plain
----
00000000: 68 65 6C 6C 6F 20 77 6F : 72 6C 64 hello world
0000000B:
## Writing applications using `librabbitmq`
Please see the `examples` directory for short examples of the use of
the `librabbitmq` library.
### Threading
You cannot share a socket, an `amqp_connection_state_t`, or a channel
between threads using `librabbitmq`. The `librabbitmq` library is
built with event-driven, single-threaded applications in mind, and
does not yet cater to any of the requirements of `pthread`ed
applications.
Your applications instead should open an AMQP connection (and an
associated socket, of course) per thread. If your program needs to
access an AMQP connection or any of its channels from more than one
thread, it is entirely responsible for designing and implementing an
appropriate locking scheme. It will generally be much simpler to have
a connection exclusive to each thread that needs AMQP service.
leekwen@iots01:~/rabbitmq-c/build$ vi ToolChain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_C_COMPILER "/home/leekwen/attitude_adjustment_37375/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc")
set(CMAKE_CXX_COMPILER "/home/leekwen/attitude_adjustment_37375/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++")
SET(CMAKE_FIND_ROOT_PATH "/home/leekwen/attitude_adjustment_37375/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(OPENSSL_INCLUDE_DIR "/home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e/include/openssl")
SET(OPENSSL_LIBARAIES "/home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e")
SET(OPENSSL_ROOT_DIR "/home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e/ipkg-install/usr/bin")
SET(OPENSSL_CRYPTO_LIBRARIES "/home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e/libcrypto.a" )
SET(OPENSSL_SSL_LIBRARIES "/home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e/libssl.a")
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
不同目标系统的移植,需要的交叉编译器也是不同的,需要指定相应的交叉编译器的对应目录和库文件,大家请自行修改!
-- checking for one of the modules 'QUIET;popt'
-- REQUIRED_VARS (missing: POPT_INCLUDE_DIR POPT_LIBRARY VERSION_VAR PC_POPT_VERSION)
-- REQUIRED_VARS (missing: XMLTO_EXECUTABLE)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Found OpenSSL: /home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e/libssl.a;/home/leekwen/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/openssl-1.0.1e/libcrypto.a
-- Building rabbitmq as a shared library - yes
-- Building rabbitmq as a static library - no
-- Configuring done
-- Generating done
-- Build files have been written to: /home/leekwen/rabbitmq-c/build
[ 15%] Built target rabbitmq
[ 20%] Built target amqp_bind
[ 24%] Built target amqp_connect_timeout
[ 28%] Built target amqp_consumer
[ 32%] Built target amqp_exchange_declare
[ 37%] Built target amqp_listen
[ 41%] Built target amqp_listenq
[ 45%] Built target amqp_producer
[ 50%] Built target amqp_rpc_sendstring_client
[ 54%] Built target amqp_sendstring
[ 58%] Built target amqp_unbind
[ 62%] Built target amqps_bind
[ 67%] Built target amqps_connect_timeout
[ 71%] Built target amqps_consumer
[ 75%] Built target amqps_exchange_declare
[ 80%] Built target amqps_listen
[ 84%] Built target amqps_listenq
[ 88%] Built target amqps_producer
[ 92%] Built target amqps_sendstring
[ 97%] Built target amqps_unbind
[ 98%] Built target test_parse_url
[100%] Built target test_tables
leekwen@iots01:~/rabbitmq-c/build$ ls examples/ -l
total 324
-rwxr-xr-x 1 leekwen leekwen 11222 2014-02-20 11:10 amqp_bind
-rwxr-xr-x 1 leekwen leekwen 10548 2014-02-20 11:10 amqp_connect_timeout
-rwxr-xr-x 1 leekwen leekwen 14074 2014-02-20 11:10 amqp_consumer
-rwxr-xr-x 1 leekwen leekwen 11224 2014-02-20 11:10 amqp_exchange_declare
-rwxr-xr-x 1 leekwen leekwen 12539 2014-02-20 11:10 amqp_listen
-rwxr-xr-x 1 leekwen leekwen 11811 2014-02-20 11:10 amqp_listenq
-rwxr-xr-x 1 leekwen leekwen 13214 2014-02-20 11:10 amqp_producer
-rwxr-xr-x 1 leekwen leekwen 13280 2014-02-20 11:10 amqp_rpc_sendstring_client
-rwxr-xr-x 1 leekwen leekwen 11674 2014-02-20 11:10 amqps_bind
-rwxr-xr-x 1 leekwen leekwen 11167 2014-02-20 11:10 amqps_connect_timeout
-rwxr-xr-x 1 leekwen leekwen 14478 2014-02-20 11:10 amqps_consumer
-rwxr-xr-x 1 leekwen leekwen 11198 2014-02-20 11:10 amqp_sendstring
-rwxr-xr-x 1 leekwen leekwen 11708 2014-02-20 11:10 amqps_exchange_declare
-rwxr-xr-x 1 leekwen leekwen 12927 2014-02-20 11:10 amqps_listen
-rwxr-xr-x 1 leekwen leekwen 12279 2014-02-20 11:10 amqps_listenq
-rwxr-xr-x 1 leekwen leekwen 13410 2014-02-20 11:10 amqps_producer
-rwxr-xr-x 1 leekwen leekwen 11650 2014-02-20 11:10 amqps_sendstring
-rwxr-xr-x 1 leekwen leekwen 11678 2014-02-20 11:10 amqps_unbind
-rwxr-xr-x 1 leekwen leekwen 11226 2014-02-20 11:10 amqp_unbind
drwxr-xr-x 21 leekwen leekwen 4096 2014-02-20 12:35 CMakeFiles
-rw-r--r-- 1 leekwen leekwen 1171 2014-02-20 11:08 cmake_install.cmake
-rw-r--r-- 1 leekwen leekwen 57814 2014-02-20 11:08 Makefile
leekwen@iots01:~/rabbitmq-c/build$ file examples/amqp_bind
examples/amqp_bind: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses
shared libs), with unknown capability 0x41000000 = 0xf676e75, not stripped
leekwen@iots01:~/rabbitmq-c/build$ ls librabbitmq/ -l
total 1536
drwxr-xr-x 3 leekwen leekwen 4096 2014-02-20 12:35 CMakeFiles
-rw-r--r-- 1 leekwen leekwen 2905 2014-02-20 11:08 cmake_install.cmake
-rw-r--r-- 1 leekwen leekwen 181 2014-02-20 09:11 config.h
lrwxrwxrwx 1 leekwen leekwen 16 2014-02-20 11:10 librabbitmq.so -> librabbitmq.so.1
lrwxrwxrwx 1 leekwen leekwen 20 2014-02-20 11:10 librabbitmq.so.1 -> librabbitmq.so.1.2.0
-rwxr-xr-x 1 leekwen leekwen 1536892 2014-02-20 11:10 librabbitmq.so.1.2.0
-rw-r--r-- 1 leekwen leekwen 16943 2014-02-20 11:08 Makefile
$ ln -s /lib/librabbitmq.so.1.2.0 /lib/librabbitmq.so
$ ln -s /lib/librabbitmq.so.1.2.0 /lib/librabbitmq.so.1
拷贝build/examples目录下的二进制文件到目标板的/usr/bin/目录
$chmod 755 /usr/bin/amq*
注意:本文章中最主要的步骤为ToolChain.cmake的编写,此文件中的目录为交叉编译器所在目录,最主要的在OPENSSL的目录指定上,否则会编译出现如下的错误。
**********************************
-- checking for one of the modules 'QUIET;popt'
-- REQUIRED_VARS (missing: POPT_INCLUDE_DIR POPT_LIBRARY VERSION_VAR PC_POPT_VERSION)
-- REQUIRED_VARS (missing: XMLTO_EXECUTABLE)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
CMake Error at /usr/share/cmake-2.8/Modules/FindOpenSSL.cmake:93 (MESSAGE):
Could NOT find OpenSSL
Call Stack (most recent call first):
CMakeLists.txt:240 (find_package)
-- Configuring incomplete, errors occurred!
**********************************
-- checking for one of the modules 'QUIET;popt'
-- REQUIRED_VARS (missing: POPT_INCLUDE_DIR POPT_LIBRARY VERSION_VAR PC_POPT_VERSION)
-- REQUIRED_VARS (missing: XMLTO_EXECUTABLE)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Building rabbitmq as a shared library - yes
-- Building rabbitmq as a static library - no
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENSSL_SSL_LIBRARIES (ADVANCED)
linked by target "rabbitmq" in directory /home/leekwen/rabbitmq-c/librabbitmq
-- Configuring incomplete, errors occurred!
**************************************