1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
#ifndef PLUGIN_RABBITMQ_HANDLER_RABBITMQ_HANDLER_H
6
#define PLUGIN_RABBITMQ_HANDLER_RABBITMQ_HANDLER_H
9
#include <amqp_framing.h>
12
* exception thrown by the rabbitmq handler
15
class rabbitmq_handler_exception: public std::exception
20
rabbitmq_handler_exception(const char* m):message(m) {};
21
rabbitmq_handler_exception(std::string m):message(m.c_str()) {};
22
virtual const char* what() const throw()
30
* @brief wrapper around librabbitmq, hides error handling and reconnections etc
31
* TODO: add reconnection handling
36
amqp_connection_state_t rabbitmqConnection;
37
int sockfd; ///< the socket file desc to the rabbitmq server,
38
///< need this to be able to close() it.
43
const char* virtualhost;
47
* Constructs a new RabbitMQHandler, purpose is to
48
* hide away the error handling, reconnections etc.
51
* Connects to the given rabbitmq server on the virtualhost
52
* with the given username/password.
54
* @param[in] hostname the host to connect to.
55
* @param[in] port the port.
56
* @param[in] username the username to use when logging in.
57
* @param[in] password the password to use.
58
* @param[in] virtualhost the rabbitmq virtual host.
59
* @throw exception if we cannot connect to rabbitmq server
61
RabbitMQHandler(const char* hostname,
65
const char* virtualhost) throw(rabbitmq_handler_exception);
70
* Publishes the message to the server
73
* publishes the given message
75
* @param[in] message the message to send
76
* @param[in] length the length of the message
77
* @param[in] exchangeName name of the exchange to publish to
78
* @param[in] routingKey the routing key to use
79
* @throw exception if there is a problem publishing
81
void publish(const uint8_t *message,
83
const char* exchangeName,
84
const char* routingKey) throw(rabbitmq_handler_exception);
90
* Handles errors produced by librabbitmq
93
* If an error occurs, an error string is thrown.
95
* @param[in] x the response from librabbitmq
96
* @param[in] context the context the call occured, simply appended to the error message.
98
* @throw exception with the message unless the command was successful
100
void handleAMQPError(amqp_rpc_reply_t x, std::string context) throw(rabbitmq_handler_exception);