prcvcc
prcvcc

Reputation: 2230

rabbitmq, not able to send message to specific queue

I'm trying to deliver a message to an exchange and then to a specific queue.

    $conn = new AMQPConnection(RABBITMQ_NODE_IP_ADDRESS, RABBITMQ_PORT, RABBITMQ_USERNAME, RABBITMQ_PASSWORD, RABBITMQ_VHOST);
    $queue = RABBITMQ_QUEUE_CSV;
    $exchange = RABBITMQ_EXCHANGE;
    $ch = $conn->channel();
    $ch->exchange_declare($exchange, 'direct', false, true, false);
    $ch->queue_declare($queue, false, true, false, false);
    $ch->queue_bind($queue, $exchange, $queue);
    $msg = new AMQPMessage(json_encode($params), array('content_type' => 'text/plain', 'delivery_mode' => 2));
    $ch->basic_publish($msg, $exchange);
    $ch->close();
    $conn->close();
    $status = Array("status" => "Job queued");

the type of exchange is 'direct', I have then added a Queue named 'foo_bar' and as 'Routing key' I've used the same 'foo_bar' string.

Just reading the documentation http://www.rabbitmq.com/tutorials/tutorial-four-php.html I cannot understand where I'm doing wrong :(

Upvotes: 1

Views: 3447

Answers (1)

old_sound
old_sound

Reputation: 2313

Here: $ch->queue_bind($queue, $exchange, $queue); you bind the queue using the $queue routing key.

Here: $ch->basic_publish($msg, $exchange); you publish a message with an empty routing key. For the message to reach the queue, the routing key on the binding and on the message publication must match

Upvotes: 6

Related Questions