public function initialize($drop = FALSE) { // TODO: $this->cnn = AMQPConnect::getInstance()->getConnection(); // binding queue $this->queue = new \AMQPQueue($this->cnn); $this->queue->declare($this->userid); $this->queue->purge($this->userid); try { // gameroom //$this->queue->bind($this->gameid, 'bingo.#'); $this->queue->bind($this->gameid, \Constant\AMQPCommand::BingoBroadcast); $this->queue->bind($this->gameid, \Constant\AMQPCommand::BingoPrivatePrefix . $this->userid . '.#'); // amf /* $this->queue->bind(\Constant\AMQPChannelConstant::AMF, \Constant\AMQPCommand::BingoBroadcast); $this->queue->bind(\Constant\AMQPChannelConstant::AMF, $this->gameid); $this->queue->bind(\Constant\AMQPChannelConstant::AMF, $this->gameid . '.' . $this->userid); */ } catch (Exception $e) { // TODO throw $e; } $this->consumeOption = array('min' => 1, 'max' => 20); $this->_initialized = true; }
public function __construct($channelName, $declare = TRUE) { $connect = AMQPConnect::getInstance(); $this->cnn = $connect->getConnection(); $this->channel = new \AMQPExchange($this->cnn, $channelName); if ($declare) { $this->channel->declare($channelName, AMQP_EX_TYPE_TOPIC); } }
<?php use Utility\AMQPConnect; error_reporting(E_ALL | E_STRICT); require_once 'bingo/odmconfig.php'; require_once __DIR__ . '/BingoStreamAMQPQueue.php'; use Constant\ErrorCode, Doctrine\Common\ClassLoader, Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\IndexedReader, Doctrine\ODM\MongoDB\DocumentManager, Doctrine\MongoDB\Connection, Doctrine\ODM\MongoDB\Configuration, Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; // Initialize set_time_limit(0); // Create a new queue $amqpcon = AMQPConnect::getInstance(); $cnn = $amqpcon->getConnection(); $q1 = new AMQPQueue($cnn); $q1->declare('queue1'); $options = array('min' => 1, 'max' => 20); // Bind it on the exchange to routing.key //$q1->bind(\Constant\AMQPChannelConstant::AMF, \Constant\AMQPCommand::BingoBroadcast); //$q1->bind(\Constant\AMQPChannelConstant::AMF, '4ebe6492aeac033931000000'); //$q1->bind(\Constant\AMQPChannelConstant::AMF, '#'); $q1->bind('4ebe6492aeac033931000000', 'bingo.#'); $logger = new \Utility\KLogger('/var/log/bingo/teststream.log', \Utility\GlobalConfiguration::GetInstance()->Config[\Constant\SectionType::Logging][\Constant\ConfigKey::LoggingLevel]); do { // Read from the queue $messages = $q1->consume($options); if ($messages != NULL) { foreach ($messages as $msg) { echo $msg['message_body']; $logger->LogDebug($msg['message_body'] . PHP_EOL); } } } while (1);
public function TearDown() { AMQPConnect::getInstance()->disconnect(); }