/** * 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; }
* @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); } // Put a new message in the queue for us to work with $ironMQ->postMessage($queueName, 'This is a sample message'); // Retrieve a message from a queue $message = $ironMQ->reserveMessage($queueName); var_dump($message); // Touch a message to keep it around longer, in case you are nearing the timeout echo 'Touching a message'; $reservationID = $ironMQ->touchMessage($queueName, $message->id, $message->reservation_id, IronMQ::GET_MESSAGE_TIMEOUT); var_dump($reservationID);