Exemple #1
0
 /**
  * @return \AMQP\Message
  * @throws \Exception
  */
 public function waitContent()
 {
     $frm = $this->nextFrame();
     $frameType = $frm[0];
     $payload = $frm[1];
     if ($frameType != 2) {
         throw new \Exception("Expecting Content header");
     }
     $payloadReader = new Reader(substr($payload, 0, 12));
     $classId = $payloadReader->readShort();
     $weight = $payloadReader->readShort();
     $bodySize = $payloadReader->readLonglong();
     $msg = new Message();
     $msg->load_properties(substr($payload, 12));
     $bodyParts = array();
     $bodyReceived = 0;
     while (bccomp($bodySize, $bodyReceived) == 1) {
         $frm = $this->nextFrame();
         $frameType = $frm[0];
         $payload = $frm[1];
         /*
          * @todo add constants for the frameType identification
          */
         if ($frameType != 3) {
             throw new \Exception(sprintf('Expecting Content body, received frame type %s', $frameType));
         }
         $bodyParts[] = $payload;
         $bodyReceived = bcadd($bodyReceived, strlen($payload));
     }
     $msg->body = implode('', $bodyParts);
     if ($this->autoDecode && isset($msg->content_encoding)) {
         try {
             $msg->body = $msg->decode();
         } catch (\Exception $e) {
             if ($this->debug) {
                 Helper::debugMsg(sprintf('Ignoring body decoding exception: %s', $e->getMessage()));
             }
         }
     }
     return $msg;
 }
Exemple #2
0
 /**
  * @param Message $msg
  * @param array   $options
  *
  * basicPublish($msg,
  *  array(
  *      'exchange' => '',
  *      'routing_key' => '',
  *      'mandatory' => false,
  *      'immediate' => false,
  *      'ticket' => null)
  * )
  */
 public function basicPublish(\AMQP\Message $msg, $options = array())
 {
     $default = array('exchange' => '', 'routing_key' => '', 'mandatory' => false, 'immediate' => false, 'ticket' => null);
     $options = array_merge($default, $options);
     $options['ticket'] = $this->getTicket($options['ticket']);
     $args = $this->frameBuilder->basicPublish($options);
     $this->sendMethodFrame(array(60, 40), $args);
     $this->connection->sendContent($this->channelId, 60, 0, strlen($msg->body), $msg->serializeProperties(), $msg->body);
 }