andypiper
6/25/2012 - 12:46 PM

RabbitMQ test scripts

RabbitMQ test scripts

<?php

$cnn = new AMQPConnection();
$cnn->setLogin("guest");
$cnn->setPassword("guest");
$cnn->setHost("localhost");

if ($cnn->connect()) {
    echo "Established a connection to the broker\n";
}
else {
    echo "Cannot connect to the broker\n";
}

    $channel = new AMQPChannel($cnn);
    $queue = new AMQPQueue($channel);
    $queue->setName('myqueue');

    // the default / nameless) exchange does not require a binding
    // as the broker declares a binding for each queue with key
    // identical to the queue name. error 403 if you try yourself.
    //$queue->bind('', 'myqueue');

$msg=$queue->get(AMQP_AUTOACK);

echo $msg->getBody();
echo "\n";

?>
#!/usr/bin/python

import pika

message='hello world'

credentials = pika.PlainCredentials('guest', 'guest')

connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='myqueue')
channel.basic_publish(exchange='',routing_key='myqueue',body=message)
connection.close()