int main(int argc, const char *argv[])
{
// need an ip
if (argc != 2)#include <amqpcpp.h>
namespace CPPExample
{
class RabbitMQConnectionHandler : public AMQP::ConnectionHandler {
/**
{
* Method that is called by// thereport AMQPerror
library every time it has data
std::cerr << "usage: " *<< argv[0] available<< that" should<ip>" be sent to RabbitMQ.
<< std::endl;
* @param connection pointer to// thedone
main connection object
return -1;
* @param}
data else
{
memory buffer with the data that should// be sent to RabbitMQcreate connection
* @param sizeMyConnection connection(argv[1]);
// size ofstart the buffer
main event loop
*/
virtual void onData(AMQP::Connection *connection, const char *data, size_t size)
{
Event::MainLoop::instance()->run();
// @todo done
return //0;
Add your own implementation, for example by doing a call to the
// send() system call. But be aware that the send() call may not
// send all data at once, so you also need to take care of buffering
// the bytes that could not immediately be sent, and try to send
// them again when the socket becomes writable again
}
/**
* Method that is called by the AMQP library when the login attempt
* succeeded. After this method has been called, the connection is ready
* to use.
* @param connection The connection that can now be used
*/
virtual void onConnected(Connection *connection)
{
// @todo
// add your own implementation, for example by creating a channel
// instance, and start publishing or consuming
}
/**
* Method that is called by the AMQP library when a fatal error occurs
* on the connection, for example because data received from RabbitMQ
* could not be recognized.
* @param connection The connection on which the error occured
* @param message A human readable error message
*/
virtual void onError(Connection *connection, const std::string &message)
{
// @todo
// add your own implementation, for example by reporting the error
// to the user of your program, log the error, and destruct the
// connection object because it is no longer in a usable state
}
};
} |