Skip to content

Instantly share code, notes, and snippets.

@andypiper
Created June 25, 2012 12:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andypiper/2988379 to your computer and use it in GitHub Desktop.
Save andypiper/2988379 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment