コード例 #1
0
ファイル: Channel.php プロジェクト: ebeyrent/mopsy
 /**
  * Overrides parent method and creates messages of type \Mopsy\Message
  * instead of AMQPMessage to gain extra functionality
  *
  * (non-PHPdoc)
  * @see \PhpAmqpLib\Channel\AbstractChannel::wait_content()
  *
  * @return Message|\PhpAmqpLib\Message\AMQPMessage
  * 
  * @throws \PhpAmqpLib\Exception\AMQPRuntimeException
  */
 public function wait_content()
 {
     $frame = $this->next_frame();
     $frame_type = $frame[0];
     $payload = $frame[1];
     if ($frame_type != 2) {
         throw new AMQPRuntimeException("Expecting Content header");
     }
     /* @var $payload_reader \PhpAmqpLib\Wire\AMQPReader */
     $payload_reader = $this->container->newInstance('PhpAmqpLib\\Wire\\AMQPReader', array(substr($payload, 0, 12)));
     // read_short() is like readline
     // calls must be made - but assignment is not used
     $payload_reader->read_short();
     // $class_id =
     $payload_reader->read_short();
     // $weight =
     $body_size = $payload_reader->read_longlong();
     /* @var $msg Message */
     $msg = $this->container->newInstance('Mopsy\\Message', array(array()));
     $msg->load_properties(substr($payload, 12));
     $body_parts = array();
     $body_received = 0;
     while (bccomp($body_size, $body_received) == 1) {
         $frame = $this->next_frame();
         $frame_type = $frame[0];
         $payload = $frame[1];
         if ($frame_type != 3) {
             throw new AMQPRuntimeException("Expecting Content body, received frame type {$frame_type} (" . self::$FRAME_TYPES[$frame_type] . ")");
         }
         $body_parts[] = $payload;
         $body_received = bcadd($body_received, strlen($payload));
     }
     $msg->body = implode("", $body_parts);
     if ($this->auto_decode && isset($msg->content_encoding)) {
         try {
             $msg->body = $msg->body->decode($msg->content_encoding);
         } catch (\Exception $e) {
             if ($this->debug) {
                 MiscHelper::debug_msg("Ignoring body decoding exception: " . $e->getMessage());
             }
         }
     }
     return $msg;
 }
コード例 #2
0
ファイル: Connection.php プロジェクト: ebeyrent/mopsy
 /**
  * Class constructor
  *
  * @param Container $container
  * @param Configuration $configuration
  * @param Channel|null $channel
  */
 public function __construct(Container $container, Configuration $configuration, Channel $channel = null)
 {
     $this->container = $container;
     $this->configuration = $configuration;
     // Create a new instance of the AMQPConnection object
     /** @var \PhpAmqpLib\Connection\AMQPConnection $conn */
     $conn = $container->newInstance('PhpAmqpLib\\Connection\\AMQPConnection', array($configuration->getHost(), $configuration->getPort(), $configuration->getUser(), $configuration->getPass()));
     // Override the default library properties
     $conn::$LIBRARY_PROPERTIES = array('library' => array('S', 'Mopsy PHP Client'), 'library_version' => array('S', '0.1'));
     $this->connection = $conn;
     if ($channel === null) {
         //$this->channel = $this->connection->channel();
         $this->channel = $container->newInstance('Mopsy\\Channel', array($this, $this->connection->get_free_channel_id(), true));
     } else {
         $this->channel = $channel;
     }
     $this->channels[$this->channel->getChannelId()] = $this->channel;
     $this->connection->channels[$this->channel->getChannelId()] = $this->channel;
     /** @var Channel\Options queueOptions */
     $this->exchangeOptions = $container->newInstance('Mopsy\\Channel\\Options');
     /** @var Channel\Options queueOptions */
     $this->queueOptions = $container->newInstance('Mopsy\\Channel\\Options');
     /*
      * Queues will expire after 30 minutes of being unused, meaning it has
      * no consumers, has not been redeclared, and basic.get has not been
      * invoked.
      *
      * Messages will be discard from this queue if they haven't been
      * acknowledged after 60 seconds.
      */
     $this->queueOptions->setArguments(array('x-message-ttl', 60000, 'x-expires' => 1800000));
 }