I have installed rabbitmq-server on my Linux machine. I have installed the AMQP-CPP client library given on the official website of RABBIRMQ.enter link description here
Now I want to connect to rabbitmq-server as a producer and want to publish a message in the queue. I have made a connection handler and the main file is as follow:
int main(int argc, char ** argv) {
const std:: string exchange = "my-exchange";
const std:: string routingKey = "my-routing-key";
const char* message = "HELLO WORLD";
MyTcpHandler myHandler;
// address of the server
cout << "TcpHandler object created.." << endl;
AMQP:: Address address("amqp://guest:guest@localhost:5672");
//("amqp://guest:guest@localhost/vhost");
cout << "address object created.." << endl;
// create a AMQP connection object
AMQP:: TcpConnection connection(& myHandler, address);
cout << "connection object created.." << endl;
// and create a channel
AMQP:: TcpChannel channel(& connection);
cout << "channel object created.." << endl;
// use the channel object to call the AMQP method you like
channel.declareExchange("my-exchange", AMQP:: fanout);
channel.declareQueue("my-queue");
channel.bindQueue("my-exchange", "my-queue", "my-routing-key");
cout << "before publish.." << endl;
// start a transaction
channel.startTransaction();
int pubVal = channel.publish(exchange, routingKey, message);
I am not able to connect to queue. Maybe I am not implementing the "monitor" method correctly in MyTcpHandler class: virtual void monitor(AMQP::TcpConnection *connection, int fd, int flags) Can anybody help, please?