/**
  * @group testMessage
  */
 public function testMessage()
 {
     $req = new SendMessage($this->queue);
     $req->setMessageBody($this->message);
     /**
      * @var $res SendMessageRes
      */
     $res = $req->send();
     $this->assertEquals(strtoupper(md5('{"nihao":"nihao"}')), $res->getMessageBodyMD5());
     $req = new ReceiveMessage($this->queue);
     /**
      * @var $res ReceiveMessageRes
      */
     $res = $req->send();
     $req = new DeleteMessage($this->queue);
     /**
      * @var $delRes DeleteMessageRes
      */
     $delRes = $req->setReceiptHandle($res->getReceiptHandle())->send();
     $this->assertTrue($delRes->isSuccess());
     $req = new SendMessage($this->queue);
     $req->setMessageBody($this->message);
     /**
      * @var $res SendMessageRes
      */
     $res = $req->send();
     $this->assertTrue($res->isSuccess());
     $peekReq = new PeekMessage($this->queue);
     /**
      * @var $peekRes PeekMessageRes
      */
     $peekRes = $peekReq->send();
     $this->assertTrue($peekRes->isSuccess());
     $this->assertNotEmpty($peekRes->getMessageId());
     $this->assertEquals(strtoupper(md5('{"nihao":"nihao"}')), $peekRes->getMessageBodyMD5());
     $req = new ReceiveMessage($this->queue);
     /**
      * @var $res ReceiveMessageRes
      */
     $res = $req->send();
     $cmvReq = new ChangeMessageVisibility($this->queue);
     $cmvReq->setReceiptHandle($res->getReceiptHandle());
     $cmvReq->setVisibilityTimeout(10);
     /**
      * @var $cmvRes ChangeMessageVisibilityRes
      */
     $cmvRes = $cmvReq->send();
     $this->assertTrue($cmvRes->isSuccess());
 }
Example #2
0
 /**
  * Pop the next job off of the queue.
  *
  * @param  string $queue
  * @return \Illuminate\Queue\Jobs\Job|null
  * @throws RequestException
  * @throws \Exception
  */
 public function pop($queue = null)
 {
     $req = new ReceiveMessage($queue = $this->getQueue($queue));
     $req->setWaitseconds($this->keepAlive);
     try {
         /**
          * @var $res ReceiveMessageRes
          */
         $res = $req->send();
     } catch (RequestException $e) {
         if ($e->type == 'MessageNotExist') {
             return null;
         }
         throw $e;
     }
     if (!$res->isNotFound() and $job = $res->getMessage()) {
         return new MqsJob($this->container, $job, $queue);
     }
 }