Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function create()
 {
     if ($this->options['push_notifications']) {
         $params = ['type' => $this->options['push_type'], 'push' => ['rate_limit' => $this->options['rate_limit'], 'retries' => $this->options['notification_retries'], 'retries_delay' => $this->options['notification_retries_delay'], 'subscribers' => []]];
         foreach ($this->options['subscribers'] as $subscriber) {
             if ($subscriber['protocol'] == "email") {
                 throw new \InvalidArgumentException('IronMQ only supports `http` or `https` subscribers!');
             }
             $params['push']['subscribers'][] = ['url' => $subscriber['endpoint']];
         }
     } else {
         $params = ['type' => 'pull'];
     }
     $queueName = $this->getNameWithPrefix();
     $this->queue = $this->ironmq->createQueue($queueName, $params);
     $this->cache->save($queueName, json_encode($this->queue));
     $this->log(200, "Queue has been created.", $params);
     return true;
 }
 * @link http://www.iron.io/products/mq
 * @link http://dev.iron.io/
 * @license BSD License
 * @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
 */
/**
 * For more information about push queues and subscribers, visit http://dev.iron.io/mq/reference/push_queues/
 */
require_once __DIR__ . '/../vendor/autoload.php';
use IronMQ\IronMQ;
$ironMQ = new IronMQ();
//$ironMQ->debug_enabled = true;
$ironMQ->ssl_verifypeer = false;
// Generating a random queue so we don't collide with any existing queues. Feel free to use a proper name
$queueName = md5(rand() . time());
// We add a 'type' => 'multicast' to turn this into a push queue, and attach a single subscriber
$queueOptions = array('message_expiration' => 3600, 'type' => 'multicast', 'push' => array('subscribers' => array(array('url' => 'http://domain0.com/endpoint', 'name' => 'Sub 0'))));
$ironMQ->createQueue($queueName, $queueOptions);
// Add a single subscriber
$singleAddResponse = $ironMQ->addSubscriber($queueName, array('url' => 'http://domain.com/endpoint', 'name' => 'Sub 1'));
var_dump($singleAddResponse);
$subscribers = array(array('url' => 'http://domain2.com/endpoint', 'name' => 'Sub 4'), array('url' => 'http://domain3.com/endpoint', 'name' => 'Sub 3'));
$multiAddResponse = $ironMQ->addSubscribers($queueName, $subscribers);
var_dump($multiAddResponse);
// Replace the list of subscribers. You can also replace multiple with IronMQ::replaceSubscribers()
// THIS DOES NOT UPDATE, BUT REPLACE THE ENTIRE LIST. To update a URL, you will need to remove and re-add the subscriber
$updateSingleResponse = $ironMQ->replaceSubscriber($queueName, array('url' => 'http://newdomain.com/endpoint', 'name' => 'Sub 1'));
// Remove a subscriber
$removeResponse = $ironMQ->removeSubscriber($queueName, array('name' => 'Sub 3'));
// Clean up our tests
$ironMQ->deleteQueue($queueName);
/**
 * PHP client for IronMQ
 * IronMQ is a scalable, reliable, high performance message queue in the cloud.
 *
 * @link https://github.com/iron-io/iron_mq_php
 * @link http://www.iron.io/products/mq
 * @link http://dev.iron.io/
 * @license BSD License
 * @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
 */
require_once __DIR__ . '/../vendor/autoload.php';
use IronMQ\IronMQ;
$ironMQ = new IronMQ();
//$ironMQ->debug_enabled = true;
$ironMQ->ssl_verifypeer = false;
// Get a list of queues that are currently in our project
$queues = $ironMQ->getQueues();
var_dump($queues);
// Create a new queue
$queueName = md5(rand() . time());
$result = $ironMQ->createQueue($queueName, array('message_expiration' => 3600));
var_dump($result);
// Clear a queue of all it's messages, but do not delete the queue
$result = $ironMQ->clearQueue($queueName);
var_dump($result);
$result = $ironMQ->updateQueue($queueName, array('message_expiration' => 3600 * 2));
var_dump($result);
// Delete a queue
$result = $ironMQ->deleteQueue($queueName);
var_dump($result);
 * @link http://www.iron.io/products/mq
 * @link http://dev.iron.io/
 * @license BSD License
 * @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
 */
/**
 * For more information about alerts, please visit http://dev.iron.io/mq/reference/queue_alerts/
 */
require_once __DIR__ . '/../vendor/autoload.php';
use IronMQ\IronMQ;
$ironMQ = new IronMQ();
//$ironMQ->debug_enabled = true;
$ironMQ->ssl_verifypeer = false;
// Generating a random queue so we don't collide with any existing queues. Feel free to use a proper name
$queueName = md5(rand() . time());
$ironMQ->createQueue($queueName, array('message_expiration' => 3600));
// Generate a queue to hold the alerts that will be generated
$alertQueueName = $queueName . '_alerts';
$ironMQ->createQueue($alertQueueName, array('message_expiration' => 3600));
// Every 200 messages, generate an alert
$alert = array('type' => 'progressive', 'direction' => 'asc', 'trigger' => 200, 'queue' => $alertQueueName);
$addResponse = $ironMQ->addAlerts($queueName, array($alert));
var_dump($addResponse);
// Our Alert queue should be empty
$messages = $ironMQ->peekMessage($alertQueueName);
var_dump($messages);
// Let's generate a bunch of messages to trigger an alert
for ($i = 0; $i < 250; $i++) {
    $ironMQ->postMessage($queueName, 'Test Message' . $i);
}
// We should now have one