/** * Count the total number of messages on the queue. * * @param $queue Queue Name * * @return int Count */ public function getMessagesTotalCountOnQueue($queue) { try { return $this->queue->getQueue($queue)->total_messages; } catch (\Http_Exception $e) { \PHPUnit_Framework_Assert::fail("queue [{$queue}] not found"); } }
/** * Get information about queue. * Also returns queue size. * * @param string $queue_name * @return mixed * @throws CException */ public function getQueue($queue_name) { try { return $this->_mq->getQueue($queue_name); } catch (Exception $e) { Yii::log('Error in IronMQ: ' . $e->getMessage(), 'error', 'ext.yiiron'); throw new CException($e->getMessage()); } }
#require("phar://iron_mq.phar"); require "../iron_core_php/IronCore.class.php"; require "IronMQ.class.php"; $ironmq = new IronMQ(); #$ironmq->debug_enabled = true; $ironmq->ssl_verifypeer = false; $queue_name = "push-queue-" . rand(0, 100); $subscribers = array(); for ($i = 0; $i < 5; $i++) { $subscribers[$i] = array('url' => "http://rest-test.iron.io/code/200?store={$queue_name}-{$i}"); } # enable push queue $res = $ironmq->updateQueue($queue_name, array('subscribers' => $subscribers, 'push_type' => "unicast")); #print_r($res); $res = $ironmq->getQueue($queue_name); echo "Queue enabled, " . count($res->subscribers) . " subscribers\n"; # Add one more subscriber $res = $ironmq->addSubscriber($queue_name, array('url' => 'http://example.com')); #print_r($res); $res = $ironmq->getQueue($queue_name); echo "Added subscriver, " . count($res->subscribers) . " subscribers\n"; $subscribers = $res->subscribers; # Remove all subscribers foreach ($subscribers as $subscriber) { echo "- " . $subscriber->url . "\n"; $ironmq->removeSubscriber($queue_name, array('url' => $subscriber->url)); } $res = $ironmq->getQueue($queue_name); echo "Queue info:\n"; print_r($res);
/** * {@inheritdoc} */ public function count($queue) { $stat = $this->iron->getQueue($queue); return (int) $stat->size; }
$queues = $ironmq->getQueues('n', 25); var_dump($queues); $ironmq->clearQueue("test_queue"); $ironmq->postMessage("test_queue", "Test Message 1"); $ironmq->postMessage("test_queue", "Test Message 2"); $message = $ironmq->reserveMessage("test_queue"); $res = $ironmq->touchMessage("test_queue", $message->id, $message->reservation_id); var_dump($res); $ironmq->clearQueue("test_queue"); $ironmq->postMessage("test_queue", "Test Message 1"); $ironmq->postMessage("test_queue", "Test Message 2"); $message = $ironmq->reserveMessage("test_queue"); $res = $ironmq->releaseMessage("test_queue", $message->id, 0, $message->reservation_id); var_dump($res); $ironmq->clearQueue("test_queue"); $res = $ironmq->getQueue("test_queue"); var_dump($res); $ironmq->postMessage("test_queue_aler", "Test Message 1"); $res = $ironmq->getQueue("test_queue_aler"); var_dump($res); $res = $ironmq->addAlerts("test_queue_aler", array(array('type' => 'progressive', 'direction' => 'asc', 'trigger' => 200, 'queue' => 'ddd'))); var_dump($res); $res = $ironmq->getQueue("test_queue_aler"); var_dump($res); $ironmq->postMessage("test_queue_upd", "Test Message 2"); $res = $ironmq->getQueue("test_queue_upd"); $res = $ironmq->updateQueue("test_queue_upd", array('message_expiration' => 600777)); var_dump($res); $res = $ironmq->createQueue("test_queue_c", array('message_expiration' => 600333)); var_dump($res); $ironmq->deleteQueue("test_queue_push");
$message = $ironmq->getMessage("test_queue"); print_r($message); echo "Getting multiple messages..\n"; $messageIds = array(); $messages = $ironmq->getMessages("test-queue-multi", 2); foreach ($messages as $message) { array_push($messageIds, $message->id); } echo "Deleting messages with ids..\n"; print_r($messageIds); $res = $ironmq->deleteMessages("test-queue-multi", $messageIds); print_r($res); echo "Adding alerts..\n"; $res = $ironmq->postMessage("test_alert_queue", "Test Message 1"); $first_alert = array('type' => 'fixed', 'direction' => 'desc', 'trigger' => 1001, 'snooze' => 10, 'queue' => 'test_alert_queue'); $second_alert = array('type' => 'fixed', 'direction' => 'asc', 'trigger' => 1000, 'snooze' => 5, 'queue' => 'test_alert_queue'); $res = $ironmq->addAlerts("test_alert_queue", array($first_alert, $second_alert)); print_r($res); echo "Deleting alerts with ids..\n"; $message = $ironmq->getQueue("test_alert_queue"); $alert_ids = array(); $alerts = $message->alerts; foreach ($alerts as $alert) { array_push($alert_ids, array('id' => $alert->id)); } print_r($alert_ids); $res = $ironmq->deleteAlerts("test_alert_queue", $alert_ids); print_r($res); echo "\n------{$i}-------\n"; } echo "\n done";