5.2.3. Publishing Messages to a Direct Exchange
The second program in the point-to-point example, direct_producer.cpp, publishes messages to the amq.direct exchange using the routing key routing_key.
First, create a message and set a routing key. The same routing key will be used for each message we send, so you only need to set this property once.
message.getDeliveryProperties().setRoutingKey("routing_key");
Now send some messages:
for (int i=0; i<10; i++) {
stringstream message_data;
message_data << "Message " << i;
message.setData(message_data.str());
session.messageTransfer(arg::content=message, arg::destination="amq.direct");
}
Send a final message to indicate termination.
message.setData("That's all, folks!");
session.messageTransfer(arg::content=message, arg::destination="amq.direct");