Permalink
Browse files

adding Delete Multiple Messages from a Queue method with example

  • Loading branch information...
1 parent 0efb789 commit 861d29faa66586f78ecc336272f54483742d2963 @freeman1988 freeman1988 committed Feb 7, 2014
Showing with 35 additions and 0 deletions.
  1. +24 −0 IronMQ.class.php
  2. BIN iron_mq.phar
  3. +11 −0 testMessages.php
View
24 IronMQ.class.php
@@ -386,6 +386,30 @@ public function deleteMessage($queue_name, $message_id)
}
/**
+ * 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
BIN iron_mq.phar
Binary file not shown.
View
11 testMessages.php
@@ -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 861d29f

Please sign in to comment.