Created
October 28, 2012 10:13
-
-
Save ludofleury/3968239 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 | |
include(__DIR__ . '/config.php'); | |
use PhpAmqpLib\Connection\AMQPConnection; | |
$exchange = 'router'; | |
$queue = 'msgs'; | |
$consumer_tag = 'consumer'; | |
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); | |
$ch = $conn->channel(); | |
$ch->queue_declare($queue, false, true, false, false); | |
$ch->exchange_declare($exchange, 'direct', false, true, false); | |
$ch->queue_bind($queue, $exchange); | |
function process_message($msg) | |
{ | |
$msg->delivery_info['channel']-> | |
basic_nack($msg->delivery_info['delivery_tag']); | |
// Send a message with the string "quit" to cancel the consumer. | |
if ($msg->body === 'quit') { | |
$msg->delivery_info['channel']-> | |
basic_cancel($msg->delivery_info['consumer_tag']); | |
} | |
} | |
$ch->basic_consume($queue, $consumer_tag, false, false, false, false, 'process_message'); | |
function shutdown($ch, $conn) | |
{ | |
$ch->close(); | |
$conn->close(); | |
} | |
register_shutdown_function('shutdown', $ch, $conn); | |
// Loop as long as the channel has callbacks registered | |
while (count($ch->callbacks)) { | |
$ch->wait(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment