I'm using AMQPCPP for my project. and suing following code to publish message on amq.direct exchange.
#include <iostream>
#include <sstream>
#include <vector>
#include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <thread>
#include <amqpcpp.h>
#include <amqpcpp/libboostasio.h>
void publish_event_to_rabbitmq(AMQP::TcpChannel* channel,std::vector<std::string> routing_keys)
{
//value of routing_keys = {"TRIGGER","EVENTS"}
for (auto key : routing_keys)
{
std :: cout << key << " routing key" <<std :: endl;
channel->publish("",key, key);
}
}
int main()
{
boost::asio::io_service service(4);
AMQP::LibBoostAsioHandler handler(service);
AMQP::TcpConnection connection(&handler, AMQP::Address("
amqp://user:password@localhost/"));
AMQP::TcpChannel channel(&connection);
while(true)
{
publish_event_to_rabbitmq(&channel,{"TRIGGER","EVENTS});
sleep(10);
}
service.run();
}
###############################################################