当前位置: 首页>>代码示例>>PHP>>正文


PHP AMQPConnection::isConnected方法代码示例

本文整理汇总了PHP中AMQPConnection::isConnected方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPConnection::isConnected方法的具体用法?PHP AMQPConnection::isConnected怎么用?PHP AMQPConnection::isConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AMQPConnection的用法示例。


在下文中一共展示了AMQPConnection::isConnected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: subscribe

 /**
  * @param callable $callback
  * @throws NotSubscribedListenerException
  * @throws \Exception
  * @return void
  */
 public function subscribe(callable $callback)
 {
     $this->callback = $callback;
     //Check whether connection open or not
     if (!$this->connection->isConnected()) {
         $this->connection->connect();
     }
     /** Declare exchange. In case it is already exists it could change it's options */
     $this->declareExchange();
     //Binding queue to correct exchange
     if (!$this->getQueue()->bind($this->exchangeConfig['name'])) {
         throw new NotSubscribedListenerException("Can not bind " . $this->getQueue()->getName() . " to an exchange " . $this->exchangeConfig);
     }
     $callback = function (\AMQPEnvelope $message) {
         switch ($message->getType()) {
             //Stop consumer by special event
             case 'eventBus.consumer-stop':
                 $this->getQueue()->ack($message->getDeliveryTag());
                 call_user_func($this->callback, 'eventBus.consumer-stop');
                 $this->stopConsumer();
                 break;
             default:
                 //If publisher is same BC as subscriber, don't proceed
                 if ($message->getAppId() !== $this->getQueue()->getName()) {
                     call_user_func($this->callback, $this->unpackMessage($message));
                 }
         }
         //Answering to RabbitMQ, that event processed
         $this->getQueue()->ack($message->getDeliveryTag());
     };
     $callback->bindTo($this);
     //Listen events
     $this->getQueue()->consume($callback);
 }
开发者ID:alpust,项目名称:zf2-rabbitmq-eventbus-module,代码行数:40,代码来源:EventBusAdapterSubscriber.php

示例2: getConnection

 /**
  * Returns an AMQPConnection instance, ensuring that it is connected
  * @return \AMQPConnection
  */
 private function getConnection()
 {
     if (!$this->connection->isConnected()) {
         $this->connection->connect();
     }
     return $this->connection;
 }
开发者ID:kastilyo,项目名称:rabbit-hole,代码行数:11,代码来源:ResourceBuilderTrait.php

示例3: it_should_give_connection_status

 public function it_should_give_connection_status(\AMQPConnection $connection)
 {
     $connection->isConnected()->willReturn(true);
     $this->isConnected()->shouldReturn(true);
     $connection->isConnected()->willReturn(false);
     $this->isConnected()->shouldReturn(false);
 }
开发者ID:Evaneos,项目名称:Hector,代码行数:7,代码来源:ConnectionSpec.php

示例4: __construct

 /**
  * Retrieves connection params from config, then inits connection and channel.
  *
  * @see http://www.php.net/manual/en/class.amqpconnection.php
  * @see http://www.php.net/manual/en/class.amqpchannel.php
  */
 public function __construct()
 {
     if (!extension_loaded('amqp')) {
         Mage::throwException('AMQP extension does not appear to be loaded');
     }
     $config = $this->getConfig();
     $this->_connection = new AMQPConnection($config);
     $this->_connection->connect();
     if (!$this->_connection->isConnected()) {
         Mage::throwException(sprintf("Unable to authenticate to 'amqp://%s:%d' (vhost: %s, user: %s, password: %s)", $config['host'], $config['port'], $config['vhost'], $config['user'], $config['password']));
     }
     $this->_channel = new AMQPChannel($this->_connection);
 }
开发者ID:technomagegithub,项目名称:magento-amqp,代码行数:19,代码来源:Broker.php

示例5: 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

示例6: publish

 /**
  * @param $event
  * @return mixed
  * @throws NotDeliveredEventException
  */
 public function publish($event)
 {
     try {
         //Prepare message for sending to RabbitMQ
         list($message, $attributes) = $this->prepareMessage($event);
         //Check connection, if no reconnect to RabbitMQ
         if (!$this->connection->isConnected()) {
             $this->connection->connect();
         }
         $result = $this->getExchange()->publish($message, null, AMQP_NOPARAM, $attributes);
         $this->exchange = null;
         //$this->channel = null;
         return $result;
     } catch (\Exception $e) {
         throw new NotDeliveredEventException("Event not delivered to queue", 0, $e);
     }
 }
开发者ID:alpust,项目名称:zf2-rabbitmq-eventbus-module,代码行数:22,代码来源:EventBusAdapterPublisher.php

示例7: getChannel

 /**
  * @return \AMQPChannel
  */
 private function getChannel()
 {
     if (!$this->channel) {
         if (!$this->connection->isConnected()) {
             $this->connection->connect();
         }
         $this->channel = new \AMQPChannel($this->connection);
     }
     return $this->channel;
 }
开发者ID:alpust,项目名称:zf2-rabbitmq-eventbus-module,代码行数:13,代码来源:EventBusAdapter.php

示例8: main

 public function main()
 {
     $connection = new \AMQPConnection($this->config->get('mq'));
     try {
         $connection->connect();
         if (!$connection->isConnected()) {
             $this->logging->exception("Cannot connect to the broker!" . PHP_EOL);
         }
         $this->channel = new \AMQPChannel($connection);
         $this->exchange = new \AMQPExchange($this->channel);
         $this->exchange->setName($this->exchangeName);
         $this->exchange->setType(AMQP_EX_TYPE_DIRECT);
         //direct类型
         $this->exchange->setFlags(AMQP_DURABLE);
         //持久化
         $this->exchange->declareExchange();
         //echo "Exchange Status:".$this->exchange->declare()."\n";
         //创建队列
         $this->queue = new \AMQPQueue($this->channel);
         $this->queue->setName($this->queueName);
         $this->queue->setFlags(AMQP_DURABLE);
         //持久化
         $this->queue->declareQueue();
         $bind = $this->queue->bind($this->exchangeName, $this->routeKey);
         //echo "Message Total:".$this->queue->declare()."\n";
         //绑定交换机与队列,并指定路由键
         //echo 'Queue Bind: '.$bind."\n";
         //阻塞模式接收消息
         //while(true){
         //for($i=0; $i< self::loop ;$i++){
         //$this->queue->consume('processMessage', AMQP_AUTOACK); //自动ACK应答
         $this->queue->consume(function ($envelope, $queue) {
             //print_r($envelope);
             //print_r($queue);
             $speed = microtime(true);
             $msg = $envelope->getBody();
             $result = $this->loader($msg);
             $queue->ack($envelope->getDeliveryTag());
             //手动发送ACK应答
             //$this->logging->info(''.$msg.' '.$result)
             $this->logging->debug('Protocol: ' . $msg . ' ');
             $this->logging->debug('Result: ' . $result . ' ');
             $this->logging->debug('Time: ' . (microtime(true) - $speed) . '');
         });
         $this->channel->qos(0, 1);
         //echo "Message Total:".$this->queue->declare()."\n";
         //}
     } catch (\AMQPConnectionException $e) {
         $this->logging->exception($e->__toString());
     } catch (\Exception $e) {
         $this->logging->exception($e->__toString());
         $connection->disconnect();
     }
 }
开发者ID:xingcuntian,项目名称:SOA,代码行数:54,代码来源:rabbitmq.class.php

示例9: getBrokerStatus

 function getBrokerStatus()
 {
     $amqpConnection = new AMQPConnection();
     $amqpConnection->setLogin("guest");
     $amqpConnection->setPassword("guest");
     $amqpConnection->setVhost("/");
     $amqpConnection->connect();
     if (!$amqpConnection->isConnected()) {
         log("info", "Cannot connect to the broker!");
         return false;
     }
     $amqpConnection->disconnect();
     return true;
 }
开发者ID:NaszvadiG,项目名称:cim-xa,代码行数:14,代码来源:celeryclientlib.php

示例10:

 function __construct()
 {
     $connection = new \AMQPConnection();
     $connection->connect();
     if (!$connection->isConnected()) {
         throw new \AMQPConnectionException('Rabbit is not connected');
     }
     $this->channel = new \AMQPChannel($connection);
     $this->exchange = new \AMQPExchange($this->channel);
     //$this->exchange->delete('Celium');
     $this->exchange->setName('Celium');
     $this->exchange->setType('direct');
     //$this->exchange->setFlags(\AMQP_DURABLE);
     $this->exchange->declare();
 }
开发者ID:zarincheg,项目名称:celium,代码行数:15,代码来源:Rabbit.php

示例11: checkRabbitMQ

 private function checkRabbitMQ()
 {
     $amqpConnection = new AMQPConnection();
     $amqpConnection->setHost($this->mqHost);
     $amqpConnection->setLogin($this->mqUser);
     $amqpConnection->setPassword($this->mqPass);
     $amqpConnection->setVhost($this->mqVhost);
     $amqpConnection->setPort($this->mqPort);
     $amqpConnection->connect();
     return $amqpConnection->isConnected();
 }
开发者ID:rumpranger,项目名称:hosting-scripts,代码行数:11,代码来源:monitor-service-connections.php

示例12: isConnected

 /**
  * Check the channel connection.
  *
  * @return bool Indicates whether the channel is connected.
  */
 public function isConnected()
 {
     return $this->connection->isConnected();
 }
开发者ID:calcinai,项目名称:php-amqplib-bridge,代码行数:9,代码来源:AMQPChannel.php

示例13: function

<?php

require_once __DIR__ . '/../vendor/autoload.php';
$injector = new Auryn\Injector();
$injector->share('AMQPConnection');
$injector->delegate('AMQPConnection', function () {
    $connection = new AMQPConnection(['host' => 'localhost', 'port' => 5672, 'login' => 'guest', 'password' => 'guest']);
    if (!$connection->isConnected()) {
        $connection->connect();
    }
    return $connection;
});
开发者ID:kastilyo,项目名称:rabbit-hole,代码行数:12,代码来源:bootstrap.php

示例14: isConnected

 /**
  * @inheritdoc
  */
 public function isConnected()
 {
     return $this->delegate->isConnected();
 }
开发者ID:treehouselabs,项目名称:queue,代码行数:7,代码来源:Connection.php

示例15: connected

 /**
  * Returns true if the connection is active
  *
  * @return boolean
  */
 public function connected()
 {
     return $this->_connection !== null && $this->_connection->isConnected();
 }
开发者ID:jellehenkens,项目名称:CakeAmqp,代码行数:9,代码来源:CakeAmqpBase.php


注:本文中的AMQPConnection::isConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。