Skip to content

Instantly share code, notes, and snippets.

@Avalarion
Created December 8, 2012 21:58
Show Gist options
  • Save Avalarion/4242155 to your computer and use it in GitHub Desktop.
Save Avalarion/4242155 to your computer and use it in GitHub Desktop.
Simple Way to Read and Write RabbitMQ Messages without a framework
<?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