Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#12 Support for push queues

  • Loading branch information...
commit 3374c5b030a0b1523129c9277c4dc56ba0c6eec4 1 parent 7c7905f
@thousandsofthem thousandsofthem authored
View
75 IronMQ.class.php
@@ -6,7 +6,7 @@
* @link https://github.com/iron-io/iron_mq_php
* @link http://www.iron.io/products/mq
* @link http://dev.iron.io/
- * @version 1.4.0
+ * @version 1.4.1
* @package IronMQPHP
* @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
*/
@@ -117,7 +117,7 @@ public function asArray() {
class IronMQ extends IronCore {
- protected $client_version = '1.4.0';
+ protected $client_version = '1.4.1';
protected $client_name = 'iron_mq_php';
protected $product_name = 'iron_mq';
protected $default_values = array(
@@ -377,8 +377,8 @@ public function peekMessages($queue_name, $count) {
* Touch a Message on a Queue
* Touching a reserved message extends its timeout by the duration specified when the message was created, which is 60 seconds by default.
*
- * @param $queue_name
- * @param $message_id
+ * @param string $queue_name
+ * @param string $message_id
* @return mixed
*/
public function touchMessage($queue_name, $message_id) {
@@ -392,8 +392,8 @@ public function touchMessage($queue_name, $message_id) {
* Release a Message on a Queue
* Releasing a reserved message unreserves the message and puts it back on the queue as if the message had timed out.
*
- * @param $queue_name
- * @param $message_id
+ * @param string $queue_name
+ * @param string $message_id
* @return mixed
*/
public function releaseMessage($queue_name, $message_id) {
@@ -403,6 +403,69 @@ public function releaseMessage($queue_name, $message_id) {
return self::json_decode($this->apiCall(self::POST, $url));
}
+ /**
+ * Updates the queue object
+ *
+ * @param string $queue_name
+ * @param array $options Parameters to change. keys:
+ * - "subscribers" url's to subscribe to
+ * - "push_type" multicast (default) or unicast.
+ * - "retries" Number of retries. 3 by default
+ * - "retries_delay" Delay between retries. 60 (seconds) by default
+ */
+ public function updateQueue($queue_name, $options) {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue";
+ return self::json_decode($this->apiCall(self::POST, $url, $options));
+ }
+
+ /**
+ * Add Subscriber to a Queue
+ *
+ * Example:
+ * <code>
+ * $ironmq->addSubscriber("test_queue", array("url" => "http://example.com"));
+ * </code>
+ *
+ * @param string $queue_name
+ * @param array $subscriber_hash Subscriber. keys:
+ * - "url" Subscriber url
+ * @return mixed
+ */
+ public function addSubscriber($queue_name, $subscriber_hash) {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/subscribers";
+ $options = array(
+ 'subscribers' => array($subscriber_hash)
+ );
+ return self::json_decode($this->apiCall(self::POST, $url, $options));
+ }
+
+ /**
+ * Remove Subscriber from a Queue
+ *
+ * Example:
+ * <code>
+ * $ironmq->removeSubscriber("test_queue", array("url" => "http://example.com"));
+ * </code>
+ *
+ * @param string $queue_name
+ * @param array $subscriber_hash Subscriber. keys:
+ * - "url" Subscriber url
+ * @return mixed
+ */
+ public function removeSubscriber($queue_name, $subscriber_hash) {
+ $this->setJsonHeaders();
+ $queue = rawurlencode($queue_name);
+ $url = "projects/{$this->project_id}/queues/$queue/subscribers";
+ $options = array(
+ 'subscribers' => array($subscriber_hash)
+ );
+ return self::json_decode($this->apiCall(self::DELETE, $url, $options));
+ }
+
/* PRIVATE FUNCTIONS */
View
0  simpleTest.php → testMessages.php
File renamed without changes
View
49 testPushQueues.php
@@ -0,0 +1,49 @@
+<?php
+
+#require("phar://iron_mq.phar");
+require("../iron_core_php/IronCore.class.php");
+require("IronMQ.class.php");
+
+$ironmq = new IronMQ();
+#$ironmq->debug_enabled = true;
+$ironmq->ssl_verifypeer = false;
+
+
+$queue_name = "push-queue-".rand(0, 100);
+
+$subscribers = array();
+for ($i = 0; $i < 5; $i++){
+ $subscribers[$i] = array(
+ 'url' => "http://rest-test.iron.io/code/200?store=$queue_name-$i"
+ );
+}
+
+
+# enable push queue
+$res = $ironmq->updateQueue($queue_name, array(
+ 'subscribers' => $subscribers,
+ 'push_type' => "unicast"
+));
+#print_r($res);
+
+$res = $ironmq->getQueue($queue_name);
+echo "Queue enabled, ".count($res->subscribers)." subscribers\n";
+
+# Add one more subscriber
+$res = $ironmq->addSubscriber($queue_name, array('url' => 'http://example.com'));
+#print_r($res);
+
+
+$res = $ironmq->getQueue($queue_name);
+echo "Added subscriver, ".count($res->subscribers)." subscribers\n";
+
+$subscribers = $res->subscribers;
+# Remove all subscribers
+foreach ($subscribers as $subscriber){
+ echo "- ".$subscriber->url."\n";
+ $ironmq->removeSubscriber($queue_name, array('url' => $subscriber->url));
+}
+
+$res = $ironmq->getQueue($queue_name);
+echo "Queue info:\n";
+print_r($res);
Please sign in to comment.
Something went wrong with that request. Please try again.