From 443bbe73d228a40409f70f69b41696f2af9530f2 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 25 Nov 2015 06:26:06 +0200 Subject: [PATCH] Mqfilter is built if possible The mqfilter was not built by default even though it should have been. This has been fixed but the filter is built only if librabbitmq is found. This was done to avoid having the librabbitmq and its development headers as a hard dependency. --- CMakeLists.txt | 1 + ...RabbitMQ-Setup-And-MaxScale-Integration.md | 72 +------------------ cmake/FindRabbitMQ.cmake | 13 ++-- cmake/macros.cmake | 2 +- server/modules/filter/CMakeLists.txt | 13 ++-- 5 files changed, 19 insertions(+), 82 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa801353c..f0fd0c65f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ find_package(TCMalloc) find_package(Jemalloc) find_package(Git) find_package(CURL) +find_package(RabbitMQ) # Build PCRE2 # Read BuildPCRE2 for details about how to add pcre2 as a dependency to a target diff --git a/Documentation/Tutorials/RabbitMQ-Setup-And-MaxScale-Integration.md b/Documentation/Tutorials/RabbitMQ-Setup-And-MaxScale-Integration.md index f5a6b57af..d71ea6321 100644 --- a/Documentation/Tutorials/RabbitMQ-Setup-And-MaxScale-Integration.md +++ b/Documentation/Tutorials/RabbitMQ-Setup-And-MaxScale-Integration.md @@ -160,77 +160,7 @@ Delivery 1, exchange foo routingkey k1 Content-type: text/plain ``` -## Step 4 - MaxScale integration with librabbitmq-c - -A new filter (mqfilter.c) is implemented in order to send messages to the rabbitmq server and a message consumer (rabbitmq_consumer/consumer.c) program will get messages and store them into a MySQL/MariaDB database. -A quick way to install MaxScale with the RabbitMQ filter is to go to the MaxScale source directory and run the following commands: - -``` -mkdir build -cd build -cmake .. -DBUILD_RABBITMQ=Y -make -make install -``` - -To build the RabbitMQ filter CMake needs an additional parameter: - -``` --DBUILD_RABBITMQ=Y -``` - -If the librabbitmq-c library is manually compiled it may be necessary to manually pass the location of the libraries and header files to CMake. - -Libraries: - -``` --DRABBITMQ_LIBRARIES= -``` - -Headers: - -``` --DRABBITMQ_HEADERS= -``` - -Please note, Message Queue Consumer (consumer.c) also needs to be compiled with MySQL/MariaDB client libraries in addition to the RabbitMQ-c libraries. If you have your MySQL/MariaDB client libraries and headers in non-standard locations, you can pass them manually to CMake: - -Libraries: - -``` --DMYSQLCLIENT_LIBRARIES= -``` - -Headers: - -``` --DMYSQLCLIENT_HEADERS= -``` - -The message queue consumer must be also built as a separate task, it’s not built as part of MaxScale build system. To build it, run the following commands in the rabbitmq_consumer directory in the MaxScale source folder: - -``` -mkdir build -cd build -cmake .. -make -``` - -To install it: - -``` -make install -``` - -To build packages: - -``` -make package -``` - -This generates RPM or DEB packages based on your system. These packages can then be installed on remote systems for easy access to the data generated by the consumer client. - -## Step 5 - Configure new applications +## Step 4 - Configure new applications The new filter needs to be configured in maxscale.cnf. diff --git a/cmake/FindRabbitMQ.cmake b/cmake/FindRabbitMQ.cmake index 5f984e79a..c5ea62be6 100644 --- a/cmake/FindRabbitMQ.cmake +++ b/cmake/FindRabbitMQ.cmake @@ -1,11 +1,12 @@ -# This CMake file tries to find the the RabbitMQ library +# This CMake file tries to find the the RabbitMQ 0.5 library # The following variables are set: # RABBITMQ_FOUND - System has RabbitMQ client # RABBITMQ_LIBRARIES - The RabbitMQ client library # RABBITMQ_HEADERS - The RabbitMQ client headers + include(CheckCSourceCompiles) find_library(RABBITMQ_LIBRARIES NAMES rabbitmq) -find_path(RABBITMQ_HEADERS amqp.h PATH_SUFFIXES mysql mariadb) +find_path(RABBITMQ_HEADERS amqp.h) if(${RABBITMQ_LIBRARIES} MATCHES "NOTFOUND") set(RABBITMQ_FOUND FALSE CACHE INTERNAL "") @@ -17,7 +18,9 @@ else() endif() set(CMAKE_REQUIRED_INCLUDES ${RABBITMQ_HEADERS}) + check_c_source_compiles("#include \n int main(){if(AMQP_DELIVERY_PERSISTENT){return 0;}return 1;}" HAVE_RABBITMQ50) -if(NOT HAVE_RABBITMQ50) - message(FATAL_ERROR "Old version of RabbitMQ-C library found. Version 0.5 or newer is required.") -endif() \ No newline at end of file + +if(RABBITMQ_FOUND AND NOT HAVE_RABBITMQ50) + message(WARNING "Old version of RabbitMQ-C library found. Version 0.5 or newer is required.") +endif() diff --git a/cmake/macros.cmake b/cmake/macros.cmake index d9e840442..f64654c6b 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -57,7 +57,7 @@ macro(set_variables) set(STATIC_EMBEDDED TRUE CACHE BOOL "Use static version of libmysqld") # Build RabbitMQ components - set(BUILD_RABBITMQ FALSE CACHE BOOL "Build RabbitMQ components") + set(BUILD_RABBITMQ TRUE CACHE BOOL "Build RabbitMQ components") # Build the binlog router set(BUILD_BINLOG TRUE CACHE BOOL "Build binlog router") diff --git a/server/modules/filter/CMakeLists.txt b/server/modules/filter/CMakeLists.txt index 2a79547ef..aa87d85ea 100644 --- a/server/modules/filter/CMakeLists.txt +++ b/server/modules/filter/CMakeLists.txt @@ -1,9 +1,12 @@ if(BUILD_RABBITMQ) - find_package(RabbitMQ) - include_directories(${RABBITMQ_HEADERS}) - add_library(mqfilter SHARED mqfilter.c) - target_link_libraries(mqfilter query_classifier log_manager ${RABBITMQ_LIBRARIES}) - install(TARGETS mqfilter DESTINATION ${MAXSCALE_LIBDIR}) + if(RABBITMQ_FOUND) + include_directories(${RABBITMQ_HEADERS}) + add_library(mqfilter SHARED mqfilter.c) + target_link_libraries(mqfilter query_classifier log_manager ${RABBITMQ_LIBRARIES}) + install(TARGETS mqfilter DESTINATION ${MAXSCALE_LIBDIR}) + else() + message(WARNING "Could not find librabbitmq, the mqfilter will not be built.") + endif() endif() add_library(regexfilter SHARED regexfilter.c)