Beispiel #1
0
 public function deleteQueue(Request $request, Response $response, array $args)
 {
     global $database;
     $err = new \Malmanger\Mpmq\Util\ErrorHandler();
     $data = $request->getParsedBody();
     $this->log->debug("deleteQueue args=" . print_r($args, true));
     $queue = new DbQueue($args['id']);
     if (!$queue->queueExists()) {
         $err->addNotFound($args['id']);
     }
     if (!$queue->delete()) {
         $err->addDbUpdate("deleteQueue");
     }
     if ($err->getLevel() > 0) {
         return $err->getErrorResponse($response);
     } else {
         $resp = new \Malmanger\Mpmq\Util\ResponseHandler();
         return $resp->setStatus(204, 'Queue deleted')->getResponse($response);
     }
 }
Beispiel #2
0
 /**
  * Add new message to queue
  *
  * @param Psr\Http\Message\RequestInterface $request
  * @param Psr\Http\Message\ResponseInterface $response 
  * @param array $args
  * 
  * @return Psr\Http\Message\ResponseInterface
  */
 public function newMessage(Request $request, Response $response, array $args)
 {
     global $database;
     $err = new \Malmanger\Mpmq\Util\ErrorHandler();
     $data = $request->getParsedBody();
     $this->log->debug("newMessage data=" . print_r($data, true));
     // Check for mandatory parameters and set defaults
     $id = $args['id'];
     $queue = new DbQueue($id);
     if (!$queue->queueExists()) {
         $err->addNotFound("queue with id=" . $id);
     }
     $messageId = null;
     $title = null;
     $payload = null;
     $timeout = null;
     //        $key = "id";
     //        if (!array_key_exists($key, $data)) {
     //            $err->addMissing($key);
     //        } else {
     //            $id = $data["id"];
     //        }
     $key = "title";
     if (!array_key_exists($key, $data)) {
         $err->addMissing($key);
     } else {
         $title = $data[$key];
     }
     $key = "payload";
     if (array_key_exists($key, $data)) {
         $payload = $data[$key];
     }
     $key = "timeout";
     if (array_key_exists($key, $data)) {
         $timeout = $data[$key];
     } else {
         $timeout = $queue->getTimeout();
     }
     $message = new DbMessage($id, $messageId, $title, $payload, $timeout);
     //        if ($queue->queueExists()) {
     //            $err->addExists($id);
     //        }
     if ($err->getLevel() > 0) {
         return $err->getErrorResponse($response);
     }
     $messageId = $message->save();
     if (!$messageId) {
         $err->addDbUpdate("newMessage");
     }
     if ($err->getLevel() > 0) {
         return $err->getErrorResponse($response);
     } else {
         $data = array();
         $data['id'] = $message->getQueueId();
         $data['messageId'] = $message->getMessageId();
         $data['title'] = $message->getTitle();
         $data['payload'] = $message->getPayload();
         $data['timeout'] = $message->getTimeout();
         $data['inFlight'] = $message->getInFlight();
         $resp = new \Malmanger\Mpmq\Util\ResponseHandler($data);
         return $resp->getResponse($response);
     }
 }