@param string $exchange
@param int    $type
@param bool   $passive
@param bool   $durable
@param bool   $autoDelete
@param bool   $internal
@param bool   $nowait
@param array  $arguments
@param string $ticket

@return \AMQP\Wire\Writer
338359
public function exchangeDeclare($exchange, $type, $options = array())
    {
        $args = new Writer();
        $args->writeShort($options['ticket'])
            ->writeShortStr($exchange)
            ->writeShortStr($type)
            ->writeBit($options['passive'])
            ->writeBit($options['durable'])
            ->writeBit($options['auto_delete'])
            ->writeBit($options['internal'])
            ->writeBit($options['no_wait'])
            ->writeTable($options['arguments']);
        return $args;
    }
1302769
public static function buildAsync(
        $host,
        $port,
        $user,
        $pass,
        $exchangeName,
        $escapeMode = self::ESCAPE_MODE_SERIALIZE,
        $timeout = 0
    ) {
        return self::build($host, $port, $user, $pass, $exchangeName, false, $escapeMode, $timeout);
    }
1223838
private static function build(
        $host,
        $port,
        $user,
        $pass,
        $exchangeName,
        $sync,
        $escapeMode,
        $timeout
    ) {
        $driver = DriverFactory::getDriver([
            'host' => $host,
            'port' => $port,
            'user' => $user,
            'pwd'  => $pass
        ]);

        $publisher = ($sync) ?
            new SyncPublisher($driver, $exchangeName, $timeout):
            new AsyncPublisher($driver, $exchangeName);

        if ($escapeMode === self::ESCAPE_MODE_NONE) {
            return $publisher;
        }

        if ($escapeMode === self::ESCAPE_MODE_JSON) {
            return new SerializingPublisher($publisher, new JsonSerializer());
        }

        if ($escapeMode === self::ESCAPE_MODE_SERIALIZE) {
            return new SerializingPublisher($publisher, new PhpSerializer());
        }

        throw new \InvalidArgumentException('Bad serializer name');
    }
895547
public function listen($exchange, $routing_key, $callback, $type = self::TYPE_TOPIC)
    {
        list ($queueName) = $this->channel->queue_declare();
        if ($type == Amqp::TYPE_DIRECT) {
            $this->channel->exchange_declare($exchange, $type, false, true, false);
        }
        $this->channel->queue_bind($queueName, $exchange, $routing_key);
        $this->channel->basic_consume($queueName, '', false, true, false, false, $callback);

        while (count($this->channel->callbacks)) {
            $this->channel->wait();
        }

        $this->channel->close();
        $this->connection->close();
    }
447067
def publish(self, msg, exchange, routing_key, mandatory=False,
                immediate=False, ticket=None):
        '''
        
        '''
        args = Writer()
        args.write_short(ticket or self.default_ticket).\
            write_shortstr(exchange).\
            write_shortstr(routing_key).\
            write_bits(mandatory, immediate)

        self.send_frame(MethodFrame(self.channel_id, 60, 40, args))
        self.send_frame(
            HeaderFrame(self.channel_id, 60, 0, len(msg), msg.properties))

        f_max = self.channel.connection.frame_max
        for f in ContentFrame.create_frames(self.channel_id, msg.body, f_max):
            self.send_frame(f)
596296
public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/)
    {
        if (func_num_args() >= 3) {
            $priority = func_get_arg(2);
        } else {
            if (__CLASS__ !== get_class($this)) {
                $r = new \ReflectionMethod($this, __FUNCTION__);
                if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
                    @trigger_error(sprintf('Method %s() will have a third `int $priority = 0` argument in version 4.0. Not defining it is deprecated since Symfony 3.2.', __METHOD__), E_USER_DEPRECATED);
                }
            }

            $priority = 0;
        }

        $property = $type.'Passes';
        if (!isset($this->$property)) {
            throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
        }

        $passes = &$this->$property;

        if (!isset($passes[$priority])) {
            $passes[$priority] = array();
        }
        $passes[$priority][] = $pass;
    }
64726
@SneakyThrows
    protected Ticket encodeTicket(final Ticket ticket) {
        if (!isCipherExecutorEnabled()) {
            LOGGER.trace(MESSAGE);
            return ticket;
        }
        if (ticket == null) {
            LOGGER.debug("Ticket passed is null and cannot be encoded");
            return null;
        }
        LOGGER.debug("Encoding ticket [{}]", ticket);
        val encodedTicketObject = SerializationUtils.serializeAndEncodeObject(this.cipherExecutor, ticket);
        val encodedTicketId = encodeTicketId(ticket.getId());
        val encodedTicket = new EncodedTicket(encodedTicketId, ByteSource.wrap(encodedTicketObject).read());
        LOGGER.debug("Created encoded ticket [{}]", encodedTicket);
        return encodedTicket;
    }
633305
protected function publishToExchange(Message $message, \AMQPExchange $exchange)
    {
        $isPublished = $exchange->publish(
            $message->getMessage(),
            $message->getRoutingKey(),
            $message->getFlags(),
            $message->getAttributes()
        );

        if (!$isPublished) {
            throw FailedToPublishException::fromMessage($message);
        }

        return $isPublished;
    }
247471
public function basicPublish($options)
    {
        $args = new Writer();
        $args->writeShort($options['ticket'])
            ->writeShortStr($options['exchange'])
            ->writeShortStr($options['routing_key'])
            ->writeBit($options['mandatory'])
            ->writeBit($options['immediate']);
        return $args;
    }
211189
public function send(string $type, array $options = []): bool
    {
        $type = $this->typeRegistry->get($type);
        $builder = MessageBuilder::fromType($type, $options);
        $message = ResolvedMessage::fromBuilder($builder);

        return $this->driver->send($message);
    }
170002
protected function createExchange($exchangeClass, $channel, array $exchangeOptions)
    {
        /** @var \AMQPExchange $exchange */
        $exchange = new $exchangeClass($channel);
        $exchange->setName($exchangeOptions['name']);

        // If the type is not specified, the exchange must exist
        if (isset($exchangeOptions['type'])) {
            $exchange->setType($exchangeOptions['type']);
            $exchange->setArguments($exchangeOptions['arguments']);
            $exchange->setFlags(
                ($exchangeOptions['passive'] ? AMQP_PASSIVE : AMQP_NOPARAM) |
                ($exchangeOptions['durable'] ? AMQP_DURABLE : AMQP_NOPARAM) |
                ($exchangeOptions['auto_delete'] ? AMQP_AUTODELETE : AMQP_NOPARAM)
            );
            $exchange->declareExchange();
        }

        return $exchange;
    }
1071017
public function getStatus($ticket)
    {
        $sender = new ExtService();
        $sender->setClient($this->wsClient);

        return $sender->getStatus($ticket);
    }
953863
private function saveTicket($ticket, $expire)
    {
        $data   = ['ticket' => $ticket, 'expire' => intval($expire), 'time' => time()];
        return ($this->getFileSystem()->put($this->getTicketFilePath(), serialize($data), true) > 0);
    }
216476
public function queueBind($queue, $exchange, $options)
    {
        $args = new Writer();
        $args->writeShort($options['ticket'])
            ->writeShortStr($queue)
            ->writeShortStr($exchange)
            ->writeShortStr($options['routing_key'])
            ->writeBit($options['no_wait'])
            ->writeTable($options['arguments']);
        return $args;
    }
347625
protected function createExchangeForMessageFromURI(MessageInterface $message, $from)
    {
        $version = $message->getContext()->get(Context::FLOWS_VERSION);
        $params = $this->itineraryResolver->getItineraryParams($from, $version);
        $itinerary = $params[InternalRouter::KEY_ITINERARY];

        $exchange = new Exchange($message, clone $itinerary);
        $exchange->setHeader(Exchange::HEADER_HANDLER, $this->getId());
        $exchange->setHeader(Exchange::HEADER_FROM, $from);

        foreach ($this->itineraryResolver->filterItineraryParamsToPropagate($params) as $key => $value) {
            $exchange->setHeader($key, $value);
        }

        return $exchange;
    }
84397
function(entries, exchangePrefix, connectionFunc, options) {
  events.EventEmitter.call(this);
  assert(options.validator, 'options.validator must be provided');
  this._conn = null;
  this.__reconnectTimer = null;
  this._connectionFunc = connectionFunc;
  this._channel = null;
  this._connecting = null;
  this._entries = entries;
  this._exchangePrefix = exchangePrefix;
  this._options = options;
  this._errCount = 0;
  this._lastErr = Date.now();
  this._lastTime = 0;
  this._sleeping = null;
  this._sleepingTimeout = null;
  if (options.drain || options.component) {
    console.log('taskcluster-lib-stats is now deprecated!\n' +
                'Use the `monitor` option rather than `drain`.\n' +
                '`monitor` should be an instance of taskcluster-lib-monitor.\n' +
                '`component` is no longer needed. Prefix your `monitor` before use.');
  }

  var monitor = null;
  if (options.monitor) {
    monitor = options.monitor;
  }

  entries.forEach((entry) => {
    this[entry.name] = (...args) => {
      // Construct message and routing key from arguments
      var message = entry.messageBuilder.apply(undefined, args);
      common.validateMessage(this._options.rootUrl, this._options.serviceName, this._options.version,
        options.validator, entry, message);

      var routingKey = common.routingKeyToString(entry, entry.routingKeyBuilder.apply(undefined, args));

      var CCs = entry.CCBuilder.apply(undefined, args);
      assert(CCs instanceof Array, 'CCBuilder must return an array');

      // Serialize message to buffer
      var payload = new Buffer(JSON.stringify(message), 'utf8');

      // Find exchange name
      var exchange = exchangePrefix + entry.exchange;

      // Log that we're publishing a message
      debug('Publishing message on exchange: %s', exchange);

      // Return promise
      return this._connect().then(channel => {
        return new Promise((accept, reject) => {
          // Start timer
          var start = null;
          if (monitor) {
            start = process.hrtime();
          }

          // Set a timeout
          let done = false;
          this._sleep12Seconds().then(() => {
            if (!done) {
              let err = new Error('publish message timed out after 12s');
              this._handleError(err);
              reject(err);
            }
          });

          // Publish message
          channel.publish(exchange, routingKey, payload, {
            persistent:         true,
            contentType:        'application/json',
            contentEncoding:    'utf-8',
            CC:                 CCs,
          }, (err, val) => {
            // NOTE: many channel errors will not invoke this callback at all,
            // hence the 12-second timeout
            done = true;
            if (monitor) {
              var d = process.hrtime(start);
              monitor.measure(exchange, d[0] * 1000 + d[1] / 1000000);
              monitor.count(exchange);
            }

            // Handle errors
            if (err) {
              err.methodName = entry.name;
              err.exchange = exchange;
              err.routingKey = routingKey;
              err.payload = payload;
              err.ccRoutingKeys = CCs;
              debug('Failed to publish message: %j and routingKey: %s, ' +
              'with error: %s, %j', message, routingKey, err, err);
              if (monitor) {
                monitor.reportError(err);
              }
              return reject(err);
            }
            accept(val);
          });
        });
      });
    };
  });
}
723539
public function exchange($name, $type = ExchangeType::DIRECT, array $options = [])
    {
        return $this->exchanges[$name] = (new ExchangeBuilder($this, $name, $type))->options($options);
    }