Exemplo n.º 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));
 }
Exemplo n.º 2
0
 /**
  * This method declares a new queue
  *
  * @param Options $options
  *
  * @return string
  */
 public function declareQueue(Options $options)
 {
     $queue = $this->queue_declare($options->getName(), $options->getPassive(), $options->getDurable(), $options->getExclusive(), $options->getAutoDelete(), $options->getNowait(), $options->getArguments(), $options->getTicket());
     if (!empty($queue)) {
         $queueName = array_shift($queue);
     } else {
         $queueName = $options->getName();
     }
     return $queueName;
 }
Exemplo n.º 3
0
 /**
  * This method declares a new exchange
  *
  * @param Options $options
  *
  * @return $this - Channel - Provides fluent interface
  */
 public function declareExchange(Options $options)
 {
     $this->exchangeOptions = $options;
     $this->exchange_declare($this->exchangeOptions->getName(), $this->exchangeOptions->getType(), $this->exchangeOptions->getPassive(), $this->exchangeOptions->getDurable(), $this->exchangeOptions->getAutoDelete(), $this->exchangeOptions->getInternal(), $this->exchangeOptions->getNowait(), $this->exchangeOptions->getArguments(), $this->exchangeOptions->getTicket());
     return $this;
 }
Exemplo n.º 4
0
 /**
  *
  * @param Options $options
  *
  * @throws InvalidArgumentException
  *
  * @return $this Connection - Provides fluent interface
  */
 public function setExchangeOptions(Options $options)
 {
     $name = $options->getName();
     $type = $options->getType();
     if (empty($name)) {
         throw new InvalidArgumentException('You must provide an exchange name');
     }
     if (empty($type)) {
         throw new InvalidArgumentException('You must provide an exchange type');
     }
     $this->exchangeOptions = $options;
     return $this;
 }