rabbitmq-c
C AMQP Client library for RabbitMQ
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rabbitmq-c Documentation

![Build Status](https://secure.travis-ci.org/alanxz/rabbitmq-c.png?branch=master)

Introduction

This is a C-language AMQP client library for use with v2.0+ of the RabbitMQ broker.

Announcements regarding the library are periodically made on the rabbitmq-discuss mailing list:

Latest Stable Version

The latest stable version of rabbitmq-c is v0.4.0. A complete list of changes can be found in the Change Log

The v0.4.0 source tarball can be downloaded from: https://github.com/alanxz/rabbitmq-c/

API documentation for v0.4.0 can viewed here: http://alanxz.github.io/rabbitmq-c/docs/0.4.0/

Getting started

Building and installing

Prereqs:

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:

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:

./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 pthreaded 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.