Example #1
0
 /**
  * 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));
 }