00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #pragma once
00026
00027 #include <exception>
00028 #include <string>
00029 #include <amqp.h>
00030 #include <amqp_framing.h>
00031 #include <netinet/in.h>
00032
00033 namespace drizzle_plugin
00034 {
00035
00040 class rabbitmq_handler_exception : public std::exception
00041 {
00042 private:
00043 const char* message;
00044 public:
00045 rabbitmq_handler_exception(const char* m):message(m) {};
00046 rabbitmq_handler_exception(std::string m):message(m.c_str()) {};
00047 virtual const char* what() const throw()
00048 {
00049 return message;
00050 }
00051 };
00052
00053
00058 class RabbitMQHandler
00059 {
00060 private:
00061 amqp_connection_state_t rabbitmqConnection;
00062 int sockfd;
00063
00064 const std::string &hostname;
00065 const in_port_t port;
00066 const std::string &username;
00067 const std::string &password;
00068 const std::string &virtualhost;
00069 const std::string &exchange;
00070 const std::string &routingKey;
00071 pthread_mutex_t publishLock;
00072 public:
00089 RabbitMQHandler(const std::string &hostname,
00090 const in_port_t port,
00091 const std::string &username,
00092 const std::string &password,
00093 const std::string &virtualhost,
00094 const std::string &exchange,
00095 const std::string &routingKey)
00096 throw(rabbitmq_handler_exception);
00097
00098 ~RabbitMQHandler();
00099
00111 void publish(void *message,
00112 const int length)
00113 throw(rabbitmq_handler_exception);
00114
00115 void reconnect() throw(rabbitmq_handler_exception);
00116 void disconnect() throw(rabbitmq_handler_exception);
00117
00118 private:
00131 void handleAMQPError(amqp_rpc_reply_t x, std::string context) throw(rabbitmq_handler_exception);
00132
00133 void connect() throw(rabbitmq_handler_exception);
00134
00135 };
00136
00137 }
00138