/**
  * @inheritDoc
  */
 public function ack($queueName, Envelope $envelope)
 {
     if (!$envelope instanceof IronEnvelope) {
         throw new InvalidEnvelope(sprintf('%s requires that envelopes be instances of "%s", got "%s"', __CLASS__, IronEnvelope::class, get_class($envelope)));
     }
     $this->iron->deleteMessage($queueName, $envelope->getId(), $envelope->getReservationId());
 }
Example #2
0
 public function testEmptyIron()
 {
     $iron_mq = new IronMQ();
     $i = 0;
     $message = $iron_mq->reserveMessage('MyQueue');
     while ($message !== null) {
         echo "{$i} th message: " . $message->body . "\n";
         $iron_mq->deleteMessage('MyQueue', $message->id, $message->reservation_id);
         //'4a309ef65422643bd14383dee06bed29');
         $i++;
         $message = $iron_mq->reserveMessage('MyQueue');
     }
 }
Example #3
0
 /**
  * Delete a message from the Iron queue.
  *
  * @param string $queue
  * @param string $id
  *
  * @return void
  */
 public function deleteMessage($queue, $id, $reservation_id = null)
 {
     if ($reservation_id) {
         $this->iron->deleteMessage($queue, $id, $reservation_id);
     } else {
         $this->iron->deleteMessage($queue, $id);
     }
 }
 /**
  * Delete a message from the Iron queue.
  *
  * @param  string $queue
  * @param  string $id
  * @param null $reservation_id
  */
 public function deleteMessage($queue, $id, $reservation_id = null)
 {
     if ($reservation_id) {
         $this->iron->deleteMessage($queue, $id, $reservation_id);
     } else {
         // Version 1 of API does not use reservation_id
         $this->iron->deleteMessage($queue, $id);
     }
 }
Example #5
0
 /**
  * Publishes multiple message at once
  *
  * @param array $messages
  * @param array $options
  *
  * @return array
  */
 public function publishMessages(array $messages, array $options = [])
 {
     $options = $this->mergeOptions($options);
     $publishStart = microtime(true);
     if (!$this->queueExists()) {
         $this->create();
     }
     $encodedMessages = [];
     foreach ($messages as $message) {
         $encodedMessages[] = json_encode($message + ['_qpush_queue' => $this->name]);
     }
     $result = $this->ironmq->postMessages($this->getNameWithPrefix(), $encodedMessages, ['timeout' => $options['message_timeout'], 'delay' => $options['message_delay'], 'expires_in' => $options['message_expiration']]);
     $context = ['message_ids' => $result->ids, 'publish_time' => microtime(true) - $publishStart];
     $this->log(200, "Messages have been published.", $context);
     return $result->ids;
 }
Example #6
0
 /**
  * Delete a message from the Iron queue.
  *
  * @param  string  $queue
  * @param  string  $id
  * @return void
  */
 public function deleteMessage($queue, $id)
 {
     $this->iron->deleteMessage($queue, $id);
 }
/**
 * 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. ;)
 */
/**
 * 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
<?php

/**
 * 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);
<?php

/**
 * 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;
// 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));
// Post a message to a queue
$singleMessageResponse = $ironMQ->postMessage($queueName, 'This is a sample message');
var_dump($singleMessageResponse);
// Post multiple messages to a single queue
$multiMessageResponse = $ironMQ->postMessages($queueName, array('Message 1', 'Message 2'));
var_dump($multiMessageResponse);
// Delete these messages one at a time
$ironMQ->deleteMessage($queueName, $singleMessageResponse->id);
foreach ($multiMessageResponse->ids as $messageID) {
    $ironMQ->deleteMessage($queueName, $messageID);
}
Example #10
0
 /**
  * Delete a message from the Iron queue.
  *
  * @param  string  $queue
  * @param  string  $id
  * @param  string  $reservationId
  * @return void
  */
 public function deleteMessage($queue, $id, $reservationId)
 {
     $this->iron->deleteMessage($queue, $id, $reservationId);
 }
Example #11
0
 public function ack($identifier, $internals)
 {
     $this->queue->deleteMessage($this->queueName, $identifier, $internals['reservation_id']);
 }
/**
 * 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. ;)
 */
/**
 * 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);
Example #13
0
 /**
  * Makes sure that a blank project ID cannot be set
  * The Project ID is required during initialization, so setting it manually will not be used directly.
  * setProjectId() is normally called during the constructor.
  *
  * @since 2015-07-20
  */
 public function testSettingBlankProjectIDThrowsException()
 {
     $this->setExpectedException('\\InvalidArgumentException', 'token or project_id not found in any of the available sources');
     $ironMQ = new IronMQ(array('project_id' => '', 'token' => 'Token'));
     $ironMQ->setProjectId('');
 }