当前位置: 首页>>代码示例>>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;未经允许,请勿转载。