1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Marcus Eriksson
8
* Marcus Eriksson <krummas@gmail.com>
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.
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.
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
25
#ifndef PLUGIN_RABBITMQ_RABBITMQ_HANDLER_H
26
#define PLUGIN_RABBITMQ_RABBITMQ_HANDLER_H
31
#include <amqp_framing.h>
34
* exception thrown by the rabbitmq handler
37
class rabbitmq_handler_exception: public std::exception
42
rabbitmq_handler_exception(const char* m):message(m) {};
43
rabbitmq_handler_exception(std::string m):message(m.c_str()) {};
44
virtual const char* what() const throw()
52
* @brief wrapper around librabbitmq, hides error handling and reconnections etc
53
* TODO: add reconnection handling
58
amqp_connection_state_t rabbitmqConnection;
59
int sockfd; ///< the socket file desc to the rabbitmq server,
60
///< need this to be able to close() it.
65
const char* virtualhost;
69
* Constructs a new RabbitMQHandler, purpose is to
70
* hide away the error handling, reconnections etc.
73
* Connects to the given rabbitmq server on the virtualhost
74
* with the given username/password.
76
* @param[in] hostname the host to connect to.
77
* @param[in] port the port.
78
* @param[in] username the username to use when logging in.
79
* @param[in] password the password to use.
80
* @param[in] virtualhost the rabbitmq virtual host.
81
* @throw exception if we cannot connect to rabbitmq server
83
RabbitMQHandler(const char* hostname,
87
const char* virtualhost) throw(rabbitmq_handler_exception);
92
* Publishes the message to the server
95
* publishes the given message
97
* @param[in] message the message to send
98
* @param[in] length the length of the message
99
* @param[in] exchangeName name of the exchange to publish to
100
* @param[in] routingKey the routing key to use
101
* @throw exception if there is a problem publishing
103
void publish(const uint8_t *message,
105
const char* exchangeName,
106
const char* routingKey) throw(rabbitmq_handler_exception);
112
* Handles errors produced by librabbitmq
115
* If an error occurs, an error string is thrown.
117
* @param[in] x the response from librabbitmq
118
* @param[in] context the context the call occured, simply appended to the error message.
120
* @throw exception with the message unless the command was successful
122
void handleAMQPError(amqp_rpc_reply_t x, std::string context) throw(rabbitmq_handler_exception);
125
#endif /* PLUGIN_RABBITMQ_RABBITMQ_HANDLER_H */