[rabbitmq-discuss] Routing Key issue

lngphp lngphp at gmail.com
Sat Oct 1 08:34:15 BST 2011


Hi

I'm trying to figure out how RabbitMQ/php-amqplib work and have issue
with Routing Keys.
Two messages are sent to 'Queue' queue using Routing Keys:
'server1.info' and 'server1.error':

$server = 1;
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $conn->channel();
$channel->exchange_declare(XCHANGE_NAME, 'topic', false, true, false);
$msg = new AMQPMessage('Server '.$server.' INFO'
, array('content_type' => 'text/plain'));
$channel->basic_publish($msg, XCHANGE_NAME
, 'server'.$server.'.info');
$msg = new AMQPMessage('Server '.$server.' ERROR'
, array('content_type' => 'text/plain'));
$channel->basic_publish($msg, XCHANGE_NAME
, 'server'.$server.'.error');

On the other end, I use '#.error' in consumer-error.php and '#.info'
in consumer-info.php, but both messages are appeared if I run any of
the consumers:

$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $conn->channel();
$channel->exchange_declare(XCHANGE_NAME, 'topic', false, true, false);
$channel->queue_declare(QUEUE_NAME, false, true, false, false);
$channel->queue_bind(QUEUE_NAME, XCHANGE_NAME, '#.info');
function process_message($msg) {
echo $msg->body."\n";
$msg->delivery_info['channel']->
basic_ack($msg->delivery_info['delivery_tag']);
}
$channel->basic_consume(QUEUE_NAME, 'consumer', false, false, false,
false, 'process_message');
while(count($channel->callbacks)) {
$channel->wait();
}

I'm expecting the separation by this key, but it doesn't happen. What
am I doing wrong?

Regards,
Roman


More information about the rabbitmq-discuss mailing list