getName() public method

Get the configured name.
public getName ( ) : string
return string The configured name as a string.
Ejemplo n.º 1
0
 /**
  * Bind queue to exchange using dispatcher event names as routing keys
  *
  * @return void
  * @throws AMQPExchangeException
  */
 public function bind(\AMQPQueue $queue, \AMQPExchange $exchange)
 {
     $events = preg_grep($this->pattern, array_keys($this->getDispatcher()->getListeners()));
     foreach ($events as $eventName) {
         $queue->bind($exchange->getName(), $eventName);
     }
     $this->dispatcher->dispatch(static::BIND_EVENT, new SymfonyEvent($events, ["pattern" => $this->pattern, "exchange" => $exchange->getName(), "queue" => $queue->getName()]));
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function receive(array $eventNames, \Closure $callback)
 {
     $exchangeName = $this->exchange->getName();
     foreach ($eventNames as $eventName) {
         $this->queue->bind($exchangeName, $eventName);
     }
     $this->queue->consume(function (\AMQPEnvelope $envelope, \AMQPQueue $queue) use($callback) {
         $message = $envelope->getBody();
         $messageTag = $envelope->getDeliveryTag();
         $status = call_user_func($callback, $message);
         if ($status) {
             $queue->ack($messageTag);
         } else {
             $queue->nack($messageTag);
         }
     });
 }
 /**
  * @return \AMQPExchange
  * @throws \Exception
  */
 protected function getExchange()
 {
     if (!$this->exchange) {
         $this->exchange = new \AMQPExchange($this->getChannel());
         $this->exchange->setName($this->exchangeConfig['name']);
         $this->exchange->setType($this->exchangeConfig['type']);
         $this->exchange->setArguments($this->exchangeConfig['arguments']);
         $this->exchange->setFlags($this->exchangeConfig['flags']);
         if (!$this->exchange->declareExchange()) {
             throw new \Exception('Can not declare exchange ' . $this->exchange->getName());
         }
     }
     return $this->exchange;
 }
Ejemplo n.º 4
0
 public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     $a += array($prefix . 'name' => $c->getName(), $prefix . 'flags' => self::extractFlags($c->getFlags()), $prefix . 'type' => isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType(), $prefix . 'arguments' => $c->getArguments(), $prefix . 'channel' => $c->getChannel(), $prefix . 'connection' => $c->getConnection());
     return $a;
 }
Ejemplo n.º 5
0
}
$timer = microtime(true) - $timer;
echo '    Get: ', $iterations, ' iterations took ', $timer, 'sec', PHP_EOL;
$q->delete();
$exchange->delete();
echo PHP_EOL;
// ==================================
$exchange = new AMQPExchange($ch);
$exchange->setType(AMQP_EX_TYPE_FANOUT);
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->setName('benchmark_exchange_' . microtime(true));
$exchange->declareExchange();
$q = new AMQPQueue($ch);
$q->setFlags(AMQP_AUTODELETE);
$q->declareQueue();
$q->bind($exchange->getName());
$timer = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
    $exchange->publish($message);
}
$timer = microtime(true) - $timer;
echo 'Publish: ', $iterations, ' iterations took ', $timer, 'sec', PHP_EOL;
$consumer_iterations = $iterations;
$timer = microtime(true);
$q->consume(function () use(&$consumer_iterations) {
    return --$consumer_iterations > 0;
}, AMQP_AUTOACK);
$timer = microtime(true) - $timer;
echo 'Consume: ', $iterations, ' iterations took ', $timer, 'sec', PHP_EOL;
$q->delete();
$exchange->delete();
Ejemplo n.º 6
0
 public function getExchange($name = 'default', $channelName = 'default')
 {
     $key = $channelName . '_' . $name;
     if (!isset($this->exchanges[$key])) {
         $channel = $this->getChannel($channelName);
         if (!isset($this->exchangesSettings[$name])) {
             throw new \LogicException('No settings for exchange ' . $name);
         }
         $settings = $this->exchangesSettings[$name];
         $exchange = new \AMQPExchange($channel);
         $exchange->setName($settings['name']);
         if (strpos($settings['name'], 'amq.') !== 0) {
             $queueFlags = AMQP_NOPARAM;
             if ($settings['durable']) {
                 $queueFlags |= AMQP_DURABLE;
             }
             if ($settings['passive']) {
                 $queueFlags |= AMQP_PASSIVE;
             }
             if ($settings['autoDelete']) {
                 $queueFlags |= AMQP_AUTODELETE;
             }
             $exchange->setType($this->getExchangeType($settings['type']));
             $exchange->setFlags($queueFlags);
             $exchange->declareExchange();
         }
         $this->exchanges[$key] = $exchange;
         //Warning place possible circular links
         if ($settings['to_exchanges'] !== null) {
             foreach ($settings['to_exchanges'] as $binExchangeName => $routingKeys) {
                 $bindExchange = $this->getExchange($binExchangeName, $channelName);
                 foreach ($routingKeys as $routingKey) {
                     $bindExchange->bind($exchange->getName(), $routingKey);
                 }
             }
         }
     }
     return $this->exchanges[$key];
 }
Ejemplo n.º 7
0
 /**
  * @return string
  */
 public function getName()
 {
     return $this->rawExchange->getName();
 }
Ejemplo n.º 8
0
 /**
  * @param \AMQPQueue $queue
  *
  * @return \AMQPExchange
  */
 protected function getExchangeForQueue(\AMQPQueue $queue)
 {
     $amqpExchange = new \AMQPExchange($this->channel);
     $queueOptions = $this->getOptionsForQueue($queue->getName());
     // determine exchange to use
     if (array_key_exists('exchange', $queueOptions) && trim($queueOptions['exchange'])) {
         $amqpExchange->setName((string) $queueOptions['exchange']);
     }
     $options = $this->getOptionsForExchange($amqpExchange->getName());
     $flags = $this->getFlagsFromOptions(['durable', 'passive'], $options);
     $amqpExchange->setFlags($flags);
     $amqpExchange->setType(isset($options['type']) ? $options['type'] : AMQP_EX_TYPE_DIRECT);
     return $amqpExchange;
 }
Ejemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function getName()
 {
     return $this->delegate->getName();
 }
Ejemplo n.º 10
0
 /**
  * @inheritdoc
  */
 public function getName() : string
 {
     return $this->exchange->getName() ?: '';
 }
Ejemplo n.º 11
0
 private function send($msg)
 {
     // Attach to well known server ETL and send message.
     $request_queue = new AMQPQueue($this->channel);
     $request_queue->setName("queue-well-known-rpc-name");
     $request_queue->declareQueue();
     $request_exch = new AMQPExchange($this->channel);
     $request_exch->setName("exchange-well-known-rpc-name");
     $request_exch->setType(AMQP_EX_TYPE_FANOUT);
     $request_exch->declareExchange();
     $request_queue->bind($request_exch->getName());
     $request_exch->publish($msg, null, AMQP_NOPARAM, ['correlation_id' => $this->correlation_id, 'reply_to' => $this->reply_queue->getName()]);
     $request_exch->delete();
 }