當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AMQPStreamConnection::channel方法代碼示例

本文整理匯總了PHP中PhpAmqpLib\Connection\AMQPStreamConnection::channel方法的典型用法代碼示例。如果您正苦於以下問題:PHP AMQPStreamConnection::channel方法的具體用法?PHP AMQPStreamConnection::channel怎麽用?PHP AMQPStreamConnection::channel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PhpAmqpLib\Connection\AMQPStreamConnection的用法示例。


在下文中一共展示了AMQPStreamConnection::channel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //
     $queue = 'cloudstack';
     $conn = new AMQPStreamConnection(Config::get('rabbitmq.host'), Config::get('rabbitmq.port'), Config::get('rabbitmq.user'), Config::get('rabbitmq.pass'), Config::get('rabbitmq.vhost'));
     $channel = $conn->channel();
     while ($message = $channel->basic_get($queue)) {
         $messageData = json_decode($message->body);
         // Don't think we care about messages that have no status or event
         if (empty($messageData->status) || empty($messageData->event)) {
             $channel->basic_ack($message->delivery_info['delivery_tag']);
             continue;
         }
         // For the moment, we don't care about non-Completed messages.
         if (!in_array($messageData->status, ['Completed', 'Created'])) {
             $channel->basic_ack($message->delivery_info['delivery_tag']);
             continue;
         }
         if (in_array($messageData->event, ['SNAPSHOT.CREATE', 'SNAPSHOT.DELETE', 'VM.CREATE', 'VM.DESTROY'])) {
             $messageHandled = $this->parseMessage($messageData);
         } else {
             $messageHandled = true;
         }
         if ($messageHandled == true) {
             $channel->basic_ack($message->delivery_info['delivery_tag']);
         }
     }
     $channel->close();
     $conn->close();
 }
開發者ID:1stel,項目名稱:stratostack-records-generation,代碼行數:35,代碼來源:ProcessNotifications.php

示例2: getChannel

 protected function getChannel()
 {
     if (null === $this->channel) {
         $this->channel = $this->connection->channel();
     }
     return $this->channel;
 }
開發者ID:evaneos,項目名稱:burrow,代碼行數:7,代碼來源:AmqpTemplate.php

示例3: getChannel

 /**
  * @return ChannelInterface
  */
 public function getChannel()
 {
     if (is_null($this->channel)) {
         $this->channel = new Channel($this, $this->connection->channel());
     }
     return $this->channel;
 }
開發者ID:roryy,項目名稱:flatfishqueue,代碼行數:10,代碼來源:Connection.php

示例4: __construct

 /**
  * @param AMQPStreamConnection $connection
  * @param string $queueName
  */
 public function __construct(AMQPStreamConnection $connection, $queueName)
 {
     $this->connection = $connection;
     $this->channel = $this->connection->channel();
     $this->queueName = $queueName;
     $this->channel->queue_declare($this->queueName, false, true, false, false);
 }
開發者ID:MarvinKlemp,項目名稱:RabbitMq,代碼行數:11,代碼來源:Publisher.php

示例5: connect

 /**
  *
  */
 private function connect()
 {
     if (!$this->connection) {
         $this->connection = new AMQPStreamConnection($this->host, $this->port, 'guest', 'guest');
         $this->channel = $this->connection->channel();
         $this->channel->exchange_declare($this->channel_name, 'fanout', false, false, false);
     }
 }
開發者ID:RepoMon,項目名稱:scheduler,代碼行數:11,代碼來源:QueueClient.php

示例6: reconnect

 /**
  * Reconnect amqp connection
  */
 public function reconnect()
 {
     if (!$this->amqpConnection->isConnected()) {
         $this->amqpConnection->reconnect();
         $this->channel = $this->amqpConnection->channel();
         $this->declaredQueues = [];
     }
 }
開發者ID:ysaroka,項目名稱:uploader,代碼行數:11,代碼來源:AmqpWrapper.php

示例7: setUp

 public function setUp()
 {
     $this->conn = $this->createConnection();
     $this->ch = $this->conn->channel();
     $this->ch->exchange_declare($this->exchange_name, 'direct', false, false, false);
     list($this->queue_name, , ) = $this->ch->queue_declare();
     $this->ch->queue_bind($this->queue_name, $this->exchange_name, $this->queue_name);
 }
開發者ID:vongrad,項目名稱:loanbroker,代碼行數:8,代碼來源:AbstractPublishConsumeTest.php

示例8: open

 /**
  * @param string $exchangeName
  */
 public function open($exchangeName)
 {
     if (null !== $this->channel) {
         return;
     }
     $channel = $this->connection->channel();
     $channel->queue_declare($exchangeName, false, true, false, false);
     $this->channel = $channel;
 }
開發者ID:zoek1,項目名稱:php-testing-tools,代碼行數:12,代碼來源:AmqpMessageConsumer.php

示例9: __construct

 /**
  * Create a new RabbitMQ queue instance.
  *
  * @param \PhpAmqpLib\Connection\AMQPStreamConnection $amqpConnection
  * @param array                                       $config
  */
 public function __construct(AMQPStreamConnection $amqpConnection, $config)
 {
     $this->connection = $amqpConnection;
     $this->default = $config['queue'];
     $this->configQueue = $config['queue_params'];
     $this->configExchange = $config['exchange_params'];
     $this->declareExchange = $config['exchange_declare'];
     $this->declareBindQueue = $config['queue_declare_bind'];
     $this->channel = $this->connection->channel();
 }
開發者ID:narrowspark,項目名稱:framework,代碼行數:16,代碼來源:RabbitMQQueue.php

示例10: connect

 /**
  * @param $exchange_name
  */
 private function connect($exchange_name)
 {
     if (null !== $this->channel) {
         return;
     }
     $this->channel = $this->connection->channel();
     $this->channel->exchange_declare($exchange_name, 'fanout', false, true, false);
     $this->channel->queue_declare($exchange_name, false, true, false, false);
     $this->channel->queue_bind($exchange_name, $exchange_name);
 }
開發者ID:loobee,項目名稱:ddd,代碼行數:13,代碼來源:RabbitMqMessageProducer.php

示例11: __construct

 /**
  * @param AMQPStreamConnection $amqpConnection
  * @param string $queue Queue name
  * @param string $exchange Exchange name
  * @param null $key Routing key
  */
 public function __construct(AMQPStreamConnection $amqpConnection, $queue, $exchange = 'jsonbus', $key = null)
 {
     $this->connection = $amqpConnection;
     $this->channel = $this->connection->channel();
     $this->channel->exchange_declare($exchange, 'direct', false, true);
     $this->channel->queue_declare($queue, false, true);
     if (!$key) {
         $key = $queue;
     }
     $this->channel->queue_bind($queue, $exchange, $key);
     $this->exchange = $exchange;
     $this->queue = $queue;
 }
開發者ID:zarincheg,項目名稱:json-bus,代碼行數:19,代碼來源:RabbitQueue.php

示例12: declareExchange

 /**
  * First tries to create exchange using passive flag.
  * If exchange does not exist, creates new with provided settings.
  * 
  * @param \PhpAmqpLib\Connection\AMQPStreamConnection $connection AMQP connection
  * @param string $name Exchange name
  * @param string $type Exchange type
  * @param array $params optional declare exchange parameters
  * @see self::$defaultDeclareExchangeParams
  */
 public static function declareExchange($connection, $name, $type, $params = [])
 {
     $params = array_replace(self::$defaultDeclareExchangeParams, $params);
     $ch = $connection->channel();
     try {
         $ch->exchange_declare($name, $type, true);
     } catch (AMQPProtocolChannelException $e) {
         $ch = $connection->channel();
         if ($params['arguments'] and is_array($params['arguments'])) {
             $params['arguments'] = new AMQPTable($params['arguments']);
         }
         $ch->exchange_declare($name, $type, false, $params['durable'], $params['auto_delete'], $params['internal'], $params['nowait'], $params['arguments']);
     }
 }
開發者ID:recipe,項目名稱:fatmouse-phpclient,代碼行數:24,代碼來源:Util.php

示例13: __construct

 /**
  * @param AMQPStreamConnection $conn
  */
 public function __construct(AMQPStreamConnection $conn)
 {
     $this->conn = $conn;
     $this->channel = $conn->channel();
     list($this->queueName) = $this->channel->queue_declare('', false, true, true, false);
     $this->channel->exchange_declare(self::TOPIC_NAME, self::MESSAGE_TYPE, false, true, true, false);
 }
開發者ID:evertharmeling,項目名稱:brouwkuyp-control,代碼行數:10,代碼來源:Manager.php

示例14: openChannel

 /**
  * @param bool $forceNewChannell
  *
  * @return void
  */
 protected function openChannel($forceNewChannell = false)
 {
     if (true == $forceNewChannell || false == $this->channel instanceof AMQPChannel) {
         $this->channel = $this->connection->channel();
         $this->logger->info('New channel opened!', [$this->channel->getChannelId()]);
     }
 }
開發者ID:retrinko,項目名稱:cottontail,代碼行數:12,代碼來源:PhpAmqpLibConnector.php

示例15: sendActivityNotice

 /**
  * Send an activity notice using AMQP
  * @param ActivityNotice $notice
  * @return bool
  */
 public function sendActivityNotice($notice)
 {
     if (!isset($notice)) {
         return false;
     }
     /** @var array $setting */
     $setting = $this->params['amqpSetting'];
     try {
         if ($this->amqpClientLibrary == "PhpAmqpLib") {
             $connection = new AMQPStreamConnection($setting['host'], $setting['port'], $setting['user'], $setting['password']);
             $channel = $connection->channel();
             $msg = new AMQPMessage(JsonHelper::encode($notice));
             $channel->basic_publish($msg, $setting['exchangeName'], $setting['routingKey']);
             $channel->close();
             $connection->close();
         } elseif ($this->amqpClientLibrary == "PECL") {
             $connection = new \AMQPConnection(['host' => $setting['host'], 'port' => $setting['port'], 'login' => $setting['user'], 'password' => $setting['password']]);
             $connection->connect();
             if ($connection->isConnected()) {
                 $channel = new \AMQPChannel($connection);
                 $exchange = new \AMQPExchange($channel);
                 $exchange->setName($setting['exchangeName']);
                 $exchange->publish(JsonHelper::encode($notice), $setting['routingKey']);
                 $connection->disconnect();
             }
         } else {
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
開發者ID:fproject,項目名稱:amqp-helper,代碼行數:38,代碼來源:ActivityNoticeManager.php


注:本文中的PhpAmqpLib\Connection\AMQPStreamConnection::channel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。