Drizzled Public API Documentation

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 <krummas@gmail.com>
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 <amqp.h>
30 #include <amqp_framing.h>
31 #include <netinet/in.h>
32 
33 namespace drizzle_plugin {
34 namespace rabbitmq {
35 
40 class rabbitmq_handler_exception : public std::exception
41 {
42 private:
43  const char* message;
44 public:
45  rabbitmq_handler_exception(const char* m):message(m) {};
46  rabbitmq_handler_exception(std::string m):message(m.c_str()) {};
47  virtual const char* what() const throw()
48  {
49  return message;
50  }
51 };
52 
53 
59 {
60 private:
61  amqp_connection_state_t rabbitmqConnection;
62  int sockfd;
63  const std::string &hostname;
65  const in_port_t port;
66  const std::string &username;
67  const std::string &password;
68  const std::string &virtualhost;
69  const std::string &exchange;
70  const std::string &routingKey;
71  pthread_mutex_t publishLock;
72 public:
73  bool rabbitmq_connection_established;
90  RabbitMQHandler(const std::string &hostname,
91  const in_port_t port,
92  const std::string &username,
93  const std::string &password,
94  const std::string &virtualhost,
95  const std::string &exchange,
96  const std::string &routingKey)
98 
99  ~RabbitMQHandler();
100 
112  void publish(void *message,
113  const int length)
115 
116  void reconnect() throw(rabbitmq_handler_exception);
117  void disconnect() throw(rabbitmq_handler_exception);
118  void connect() throw(rabbitmq_handler_exception);
119 
120 private:
133  void handleAMQPError(amqp_rpc_reply_t x, std::string context) throw(rabbitmq_handler_exception);
134 
135 };
136 
137 } /* namespace rabbitmq */
138 } /* namespace drizzle_plugin */
139 
void handleAMQPError(amqp_rpc_reply_t x, std::string context)
Handles errors produced by librabbitmq.
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...
wrapper around librabbitmq, hides error handling and reconnections etc TODO: add reconnection handlin...
void publish(void *message, const int length)
Publishes the message to the server.