drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
rabbitmq_handler.h
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Marcus Eriksson
5 *
6 * Authors:
7 *
8 * Marcus Eriksson <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#pragma once
26
27#include <exception>
28#include <string>
29#include <rabbitmq-c/amqp.h>
30#include <rabbitmq-c/framing.h>
31#include <rabbitmq-c/tcp_socket.h>
32#include <netinet/in.h>
33
34namespace drizzle_plugin {
35namespace rabbitmq {
36
41class rabbitmq_handler_exception : public std::exception
42{
43private:
44 const char* message;
45public:
46 rabbitmq_handler_exception(const char* m):message(m) {};
47 rabbitmq_handler_exception(std::string m):message(m.c_str()) {};
48 virtual const char* what() const noexcept
49 {
50 return message;
51 }
52};
53
54
60{
61private:
62 amqp_connection_state_t rabbitmqConnection;
63 const std::string &hostname;
64 const in_port_t port;
65 const std::string &username;
66 const std::string &password;
67 const std::string &virtualhost;
68 const std::string &exchange;
69 const std::string &routingKey;
70 pthread_mutex_t publishLock;
71public:
72 bool rabbitmq_connection_established;
89 RabbitMQHandler(const std::string &hostname,
90 const in_port_t port,
91 const std::string &username,
92 const std::string &password,
93 const std::string &virtualhost,
94 const std::string &exchange,
95 const std::string &routingKey);
96
98
110 void publish(void *message,
111 const int length);
112
113 void reconnect();
114 void disconnect();
115 void connect();
116
117private:
130 void handleAMQPError(amqp_rpc_reply_t x, std::string context);
131
132};
133
134} /* namespace rabbitmq */
135} /* namespace drizzle_plugin */
136
RabbitMQHandler(const std::string &hostname, const in_port_t port, const std::string &username, const std::string &password, const std::string &virtualhost, const std::string &exchange, const std::string &routingKey)
Constructs a new RabbitMQHandler, purpose is to hide away the error handling, reconnections etc.
void handleAMQPError(amqp_rpc_reply_t x, std::string context)
Handles errors produced by librabbitmq.
void publish(void *message, const int length)
Publishes the message to the server.