Permalink
Browse files

Merge pull request #27 from freeman1988/master

Adding Delete Multiple Messages from a Queue method with example
  • Loading branch information...
thousandsofthem committed Feb 7, 2014
2 parents 0efb789 + 170d35e commit b1860e167cebc65ee1b422aedb2e45728d2ee489
Showing with 50 additions and 0 deletions.
  1. +24 −0 IronMQ.class.php
  2. +15 −0 README.md
  3. BIN iron_mq.phar
  4. +11 −0 testMessages.php
View
@@ -385,6 +385,30 @@ public function deleteMessage($queue_name, $message_id)
return $this->apiCall(self::DELETE, $url);
}
+ /**
+ * Delete Messages from a Queue
+ * This call will delete the messages. Be sure you call this after you’re done with a message,
+ * or it will be placed back on the queue.
+ *
+ * @param $queue_name
+ * @param $message_ids
+ * @return mixed
+ */
+ public function deleteMessages($queue_name, $message_ids)
+ {
+ $req = array(
+ "ids" => array()
+ );
+ foreach ($message_ids as $message_id) {
+ array_push($req['ids'], $message_id);
+ }
+ $this->setCommonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/messages";
+ $result = $this->apiCall(self::DELETE, $url, $req);
+ return self::json_decode($result);
+ }
+
/**
* Peek Messages on a Queue
* Peeking at a queue returns the next messages on the queue, but it does not reserve them.
View
@@ -121,6 +121,13 @@ $ironmq->getMessage($queue_name);
When you pop/get a message from the queue, it will NOT be deleted.
It will eventually go back onto the queue after a timeout if you don't delete it (default timeout is 60 seconds).
+Get multiple messages in one API call:
+
+```php
+<?php
+$ironmq->getMessage($queue_name, 3);
+```
+
--
### Delete a Message from the Queue
@@ -131,6 +138,14 @@ $ironmq->deleteMessage($queue_name, $message_id);
```
Delete a message from the queue when you're done with it.
+Delete multiple messages in one API call:
+
+```php
+<?php
+$ironmq->deleteMessages($queue_name, array("xxxxxxxxx", "xxxxxxxxx"));
+```
+Delete multiple messages specified by messages id array.
+
--
View
Binary file not shown.
View
@@ -40,6 +40,17 @@
$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 "\n------$i-------\n";
}

0 comments on commit b1860e1

Please sign in to comment.