Ejemplo n.º 1
0
 /**
  * Makes sure that the array copy of a messages matches the data supplied, and is in the proper format
  *
  * @since 2015-07-20
  */
 public function testCreatesArrayCopyProperly()
 {
     $data = array('body' => 'This is the message body', 'properties' => array('timeout' => 500, 'delay' => 450, 'expires_in' => 400));
     $message = new IronMQMessage($data['body'], $data['properties']);
     $arrayCopy = $message->asArray();
     $this->assertEquals($data['body'], $arrayCopy['body']);
     $this->assertEquals($data['properties']['timeout'], $arrayCopy['timeout']);
     $this->assertEquals($data['properties']['delay'], $arrayCopy['delay']);
     $this->assertEquals($data['properties']['expires_in'], $arrayCopy['expires_in']);
 }
Ejemplo n.º 2
0
 /**
  * Push multiple messages on the queue
  *
  * Example:
  * <code>
  * $ironmq->postMessages("test_queue", array("Lorem", "Ipsum"), array(
  *   'timeout' => 120,
  *   'delay' => 2,
  *   'expires_in' => 2*24*3600 # 2 days
  * ));
  * </code>
  *
  * @param string $queue_name Name of the queue.
  * @param array $messages array of messages, each message same as for postMessage() method
  * @param array $properties array of message properties, applied to each message in $messages
  * @return mixed
  */
 public function postMessages($queue_name, $messages, $properties = array())
 {
     $req = array("messages" => array());
     foreach ($messages as $message) {
         $msg = new IronMQMessage($message, $properties);
         array_push($req['messages'], $msg->asArray());
     }
     $this->setJsonHeaders();
     $queue = rawurlencode($queue_name);
     $url = "projects/{$this->project_id}/queues/{$queue}/messages";
     $res = $this->apiCall(self::POST, $url, $req);
     return self::json_decode($res);
 }