Created
December 8, 2012 21:58
-
-
Save Avalarion/4242155 to your computer and use it in GitHub Desktop.
Simple Way to Read and Write RabbitMQ Messages without a framework
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 | |
/** | |
* Using lib: https://github.com/videlalvaro/php-amqplib | |
* In Tag "v1.0" | |
*/ | |
require_once(__DIR__.'/lib/php-amqplib/amqp.inc'); | |
class TYPO3_RabbitMQ{ | |
public static function writeMessage($host, $port, $user, $pass, $vhost, $channelID, $message, $restore = FALSE) { | |
$conn = new AMQPConnection($host, $port, $user, $pass, $vhost); | |
$channel = $conn->channel(); | |
$channel->queue_declare($channelID, false, true, false, false); | |
$msg = new AMQPMessage($message, array('delivery_mode' => '2')); | |
$channel->basic_publish($msg, '', $channelID); | |
$channel->close(); | |
$conn->close(); | |
} | |
public static function readMessage($host, $port, $user, $pass, $vhost, $channelID, $callback) { | |
$conn = new AMQPConnection($host, $port, $user, $pass, $vhost); | |
$channel = $conn->channel(); | |
$channel->queue_declare($channelID, false, true, false, false); | |
$channel->basic_consume($channelID, '', false, true, false, false, $callback); | |
while(count($channel->callbacks)) { | |
$channel->wait(); | |
} | |
$channel->close(); | |
$conn->close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment