Ejemplo n.º 1
0
 /**
  * @inheritdoc
  *
  * @throws SqsException
  */
 public function addMessage($queueName, $message, $priority = null)
 {
     if (null === $priority) {
         $priority = $this->priorityHandler->getDefault();
     }
     if (empty($queueName)) {
         throw new InvalidArgumentException('Parameter queueName empty or not defined.');
     }
     if (empty($message)) {
         throw new InvalidArgumentException('Parameter message empty or not defined.');
     }
     $message = serialize($message);
     $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl');
     $this->sqsClient->sendMessage(['QueueUrl' => $queueUrl, 'MessageBody' => $message]);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function addMessage($queueName, $message, $priority = null)
 {
     if (null === $priority) {
         $priority = $this->priorityHandler->getDefault();
     }
     if (empty($queueName)) {
         throw new InvalidArgumentException('Parameter queueName empty or not defined.');
     }
     if (!isset($this->queues[$queueName])) {
         throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it.");
     }
     if (empty($message)) {
         throw new InvalidArgumentException('Parameter message empty or not defined.');
     }
     if (isset($this->queues[$queueName][$priority])) {
         $new_message = ['id' => uniqid($queueName . $priority, true), 'time-in-flight' => null, 'Body' => serialize($message)];
         /** @var SplQueue $splQueue */
         $splQueue = $this->queues[$queueName][$priority];
         $splQueue->enqueue($new_message);
     } else {
         throw new \Exception('priority ' . $priority . ' unknown.');
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  * @throws InvalidMessageException
  * @throws QueueAccessException
  * @throws InvalidPriorityException
  */
 public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0)
 {
     if (empty($queueName)) {
         throw new \InvalidArgumentException('Queue name empty or not defined.');
     }
     if (empty($message)) {
         throw new InvalidMessageException($message, 'Message empty or not defined.');
     }
     if (null === $priority) {
         $priority = $this->priorityHandler->getDefault();
     }
     if (!isset($this->queues[$queueName])) {
         throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it.");
     }
     if (isset($this->queues[$queueName][$priority->getName()])) {
         $new_message = ['id' => uniqid($queueName . $priority->getName(), true), 'time-in-flight' => null, 'delayed-until' => time() + $delaySeconds, 'Body' => serialize($message)];
         /** @var SplQueue $splQueue */
         $splQueue = $this->queues[$queueName][$priority->getName()];
         $splQueue->enqueue($new_message);
     } else {
         throw new InvalidPriorityException('Unknown priority: ' . $priority->getName());
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function addMessage($queueName, $message, $priority = null)
 {
     if (null === $priority) {
         $priority = $this->priorityHandler->getDefault();
     }
     if (empty($queueName)) {
         throw new InvalidArgumentException('Parameter queueName empty or not defined.');
     }
     if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) {
         throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it.");
     }
     if (empty($message)) {
         throw new InvalidArgumentException('Parameter message empty or not defined.');
     }
     $this->addMessageLock($queueName, $message, $priority);
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  * @throws InvalidMessageException
  * @throws QueueAccessException
  */
 public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0)
 {
     if (empty($queueName)) {
         throw new \InvalidArgumentException('Queue name empty or not defined.');
     }
     if (empty($message)) {
         throw new InvalidMessageException($message, 'Message empty or not defined.');
     }
     if (null === $priority) {
         $priority = $this->priorityHandler->getDefault();
     }
     if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) {
         throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it.");
     }
     $this->addMessageLock($queueName, $message, $priority);
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  * @throws \InvalidArgumentException
  * @throws QueueAccessException
  */
 public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0)
 {
     if (empty($queueName)) {
         throw new \InvalidArgumentException('Queue name empty or not defined.');
     }
     if (empty($message)) {
         throw new InvalidMessageException($message, 'Message empty or not defined.');
     }
     if (null === $priority) {
         $priority = $this->priorityHandler->getDefault();
     }
     $message = serialize($message);
     try {
         $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl');
         $this->sqsClient->sendMessage(['QueueUrl' => $queueUrl, 'MessageBody' => $message, 'delaySeconds' => $delaySeconds]);
     } catch (SqsException $e) {
         throw new QueueAccessException('Cannot add message in queue.', 0, $e);
     }
     return $this;
 }