Created
June 25, 2012 12:46
-
-
Save andypiper/2988379 to your computer and use it in GitHub Desktop.
RabbitMQ test scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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