5.2.2. Declaring and Binding a Queue

5.2.2. Declaring and Binding a Queue

The first program in the direct example, declare_queues.cpp, adds only a few lines to the basic skeleton. It creates a queue named message_queue, then binds it to the amq.direct exchange using the binding key routing_key.

session.queueDeclare(arg::queue="message_queue");
session.exchangeBind(arg::exchange="amq.direct", arg::queue="message_queue", arg::bindingKey="routing_key");

The queue created by this program continues to exist after the configuration program exits, and any message whose routing key matches the key specified in the binding will be routed to the corresponding queue by the broker.

Note that the configuration program could easily bind other queues using the same routing key, so that multiple queues would receive the same message, or change the queues to which messages with a given routing key are sent. This can be done without affecting producers or consumers.