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


PHP AMQPConnection::connect方法代码示例

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


在下文中一共展示了AMQPConnection::connect方法的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: connect

 /**
  * @inheritdoc
  */
 public function connect()
 {
     if ($this->options->getPersistent()) {
         $this->connection->pconnect();
     } else {
         $this->connection->connect();
     }
 }
开发者ID:prolic,项目名称:HumusAmqp,代码行数:11,代码来源:Connection.php

示例4: _getConnection

 /**
  * Connect to server
  * @return AMQPConnection
  */
 protected function _getConnection()
 {
     if (!$this->_connection) {
         $this->_connection = new \AMQPConnection($this->_config);
         if (!$this->_connection->connect()) {
             throw new \Exception("Cannot connect to the broker \n");
         }
     }
     return $this->_connection;
 }
开发者ID:mywin,项目名称:mywin,代码行数:14,代码来源:Rabbitmq.php

示例5: __construct

 /**
  * @param string $protocol
  * @param string $encoding
  * @param bool   $synchronous
  * @param array  $endpoint
  */
 public function __construct($protocol, $encoding, $synchronous = false, array $endpoint = [])
 {
     parent::__construct($protocol, $encoding, $synchronous, $endpoint);
     list($exchangeName, $routingKey) = array_values($this->endpoint);
     $credentials = array_filter($this->endpoint);
     $this->connection = new \AMQPConnection($credentials);
     $this->connection->connect();
     $this->channel = new \AMQPChannel($this->connection);
     $this->exchange = new \AMQPExchange($this->channel);
     $this->exchange->setName($exchangeName);
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:17,代码来源:AmqpConnection.php

示例6: __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

示例7: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->user)) {
         throw new \Exception("Parameter 'user' was not set for AMQP connection.");
     }
     if (empty(self::$ampqConnection)) {
         self::$ampqConnection = new \AMQPConnection();
         self::$ampqConnection->setHost($this->host);
         self::$ampqConnection->setPort($this->port);
         self::$ampqConnection->setLogin($this->user);
         self::$ampqConnection->setPassword($this->password);
         self::$ampqConnection->setVhost($this->vhost);
         self::$ampqConnection->connect();
     }
 }
开发者ID:andriell,项目名称:yii2-amqp,代码行数:18,代码来源:Amqp.php

示例8: setUpAmqp

 /**
  * {@inheritDoc}
  */
 protected function setUpAmqp()
 {
     $this->conn = new \AMQPConnection(['host' => $_SERVER['AMQP_HOST'], 'port' => $_SERVER['AMQP_PORT'], 'login' => $_SERVER['AMQP_USER'], 'password' => $_SERVER['AMQP_PASS'], 'vhost' => $_SERVER['AMQP_VHOST']]);
     $this->conn->connect();
     $channel = new \AMQPChannel($this->conn);
     $exchange = new \AMQPExchange($channel);
     $exchange->setName('event_band.test.exchange');
     $exchange->setFlags(AMQP_AUTODELETE);
     $exchange->setType(AMQP_EX_TYPE_TOPIC);
     $exchange->declareExchange();
     $queue = new \AMQPQueue($channel);
     $queue->setName('event_band.test.event');
     $queue->declareQueue();
     $queue->bind('event_band.test.exchange', 'event.#');
 }
开发者ID:event-band,项目名称:band-transport-amqp-pecl,代码行数:18,代码来源:PeclAmqpDriverTest.php

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

示例10: connection

 /**
  * Returns AMQP connection
  *
  * @return AMQPConnection
  */
 public function connection()
 {
     if (!$this->connection) {
         if (!$this->host || !$this->port) {
             throw new \InvalidArgumentException(sprintf("Remote host or port undefined '%s:%s' ", $this->host, $this->port));
         }
         $this->connection = new \AMQPConnection();
         $this->connection->setHost($this->host);
         $this->connection->setPort($this->port);
         $this->connection->setLogin($this->user);
         $this->connection->setPassword($this->password);
         $this->vhost and $this->connection->setVhost($this->vhost);
         $this->connection->connect();
     }
     return $this->connection;
 }
开发者ID:gallna,项目名称:amqp-event,代码行数:21,代码来源:Broker.php

示例11: resolve

 public function resolve(Command $command, InputInterface $input, OutputInterface $output, array $args)
 {
     $options = array_merge(array('host' => 'localhost', 'port' => 5763, 'login' => null, 'password' => null), $args);
     $conn = new \AMQPConnection($options);
     $conn->connect();
     $channel = new \AMQPChannel($conn);
     return new AmqpHandler(new \AMQPExchange($channel), $this->replacePlaceholders($args['name']));
 }
开发者ID:mjphaynes,项目名称:php-resque,代码行数:8,代码来源:AmqpConnector.php

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

示例13: connect

 /**
  * @inheritdoc
  */
 public function connect()
 {
     try {
         return $this->delegate->connect();
     } catch (\AMQPConnectionException $e) {
         throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:treehouselabs,项目名称:queue,代码行数:11,代码来源:Connection.php

示例14: getAMQPExchange

 protected function getAMQPExchange()
 {
     $connection = new \AMQPConnection(array('vhost' => 'swarrot'));
     $connection->connect();
     $channel = new \AMQPChannel($connection);
     $exchange = new \AMQPExchange($channel);
     $exchange->setName('exchange');
     return $exchange;
 }
开发者ID:Niktux,项目名称:swarrot,代码行数:9,代码来源:PeclPackageMessagePublisherTest.php

示例15: getAMQPConnection

 /**
 AMQP Connection
 */
 protected function getAMQPConnection()
 {
     $connection = new AMQPConnection();
     $connection->setHost('127.0.0.1');
     $connection->setLogin('guest');
     $connection->setPassword('guest');
     $connection->connect();
     return $connection;
 }
开发者ID:blake2002,项目名称:rabbitmq-tutorials,代码行数:12,代码来源:rpc_client.php


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