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 public:
00086 RabbitMQHandler(const std::string &hostname,
00087 const in_port_t port,
00088 const std::string &username,
00089 const std::string &password,
00090 const std::string &virtualhost)
00091 throw(rabbitmq_handler_exception);
00092
00093 ~RabbitMQHandler();
00094
00108 void publish(void *message,
00109 const int length,
00110 const std::string &exchangeName,
00111 const std::string &routingKey)
00112 throw(rabbitmq_handler_exception);
00113
00114
00115 private:
00128 void handleAMQPError(amqp_rpc_reply_t x, std::string context) throw(rabbitmq_handler_exception);
00129 };
00130
00131 }
00132