-
-
Save jcnevado/5936958 to your computer and use it in GitHub Desktop.
This file contains 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 | |
//Worker.php | |
/* Create a connection using all default credentials: */ | |
$connection = new AMQPConnection(); | |
$connection->connect(); | |
$channel = new AMQPChannel($connection); | |
/* create a queue object */ | |
$queue = new AMQPQueue($channel); | |
$queue->setName('elements'); | |
//declare the queue | |
$queue->declare(); | |
$ex = new AMQPExchange($channel); | |
//declare the queue | |
$ex->setName('md'); | |
$ex->setType(AMQP_EX_TYPE_DIRECT); | |
$ex->declare(); | |
$queue->bind('md', 'md:send'); | |
$i = 0; | |
function processMessage($envelope, $queue) { | |
global $i; | |
echo "Message $i: " . print_r(json_decode($envelope->getBody()), true) . "\n"; | |
$i++; | |
if ($i > 10) { | |
// Bail after 10 messages | |
return false; | |
} | |
} | |
// Consume messages on queue | |
$queue->consume("processMessage"); | |
//Send.php | |
/* Create a connection using all default credentials: */ | |
$connection = new AMQPConnection(); | |
$connection->connect(); | |
$channel = new AMQPChannel($connection); | |
/* create a queue object */ | |
$ex = new AMQPExchange($channel); | |
//declare the queue | |
$ex->setName('md'); | |
$ex->setType(AMQP_EX_TYPE_DIRECT); | |
$ex->declare(); | |
$ex->publish(json_encode(array('Julio')), 'md:send'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment