• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP AMQPConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

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


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


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


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


示例6: PostToExchange

 /**
  * Post a task to exchange specified in $details
  * @param AMQPConnection $connection Connection object
  * @param array $details Array of connection details
  * @param string $task JSON-encoded task
  * @param array $params AMQP message parameters
  */
 function PostToExchange($connection, $details, $task, $params)
 {
     $ch = new AMQPChannel($connection);
     $xchg = new AMQPExchange($ch);
     $xchg->setName($details['exchange']);
     $success = $xchg->publish($task, $details['binding'], 0, $params);
     $connection->disconnect();
     return $success;
 }
开发者ID:jjbubudi,项目名称:celery-php,代码行数:16,代码来源:amqppeclconnector.php


示例7: getAMQPQueue

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


示例8: _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


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


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


示例11: sendMessage

 private static function sendMessage($exchange, $data)
 {
     global $CC_CONFIG;
     $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["user"], $CC_CONFIG["rabbitmq"]["password"], $CC_CONFIG["rabbitmq"]["vhost"]);
     $channel = $conn->channel();
     $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
     $channel->exchange_declare($exchange, 'direct', false, true);
     $msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
     $channel->basic_publish($msg, $exchange);
     $channel->close();
     $conn->close();
 }
开发者ID:nidzix,项目名称:Airtime,代码行数:12,代码来源:RabbitMq.php


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


示例13: sendMessage

 private static function sendMessage($exchange, $data)
 {
     $CC_CONFIG = Config::getConfig();
     $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["user"], $CC_CONFIG["rabbitmq"]["password"], $CC_CONFIG["rabbitmq"]["vhost"]);
     if (!isset($conn)) {
         throw new Exception("Cannot connect to RabbitMQ server");
     }
     $channel = $conn->channel();
     $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
     $channel->exchange_declare($exchange, 'direct', false, true);
     $msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
     $channel->basic_publish($msg, $exchange);
     $channel->close();
     $conn->close();
 }
开发者ID:RadioCampusFrance,项目名称:airtime,代码行数:15,代码来源:RabbitMq.php


示例14: createExchange

 /**
  * {@inheritDoc}
  */
 public function createExchange()
 {
     // Create AMQP connection
     $amqpConnection = new \AMQPConnection(['host' => $this->host, 'port' => $this->port, 'vhost' => $this->vhost, 'login' => $this->login, 'password' => $this->password]);
     $amqpConnection->connect();
     // Create channel
     $channel = new \AMQPChannel($amqpConnection);
     // Create exchange
     $exchange = new \AMQPExchange($channel);
     $exchange->setName($this->exchangeName);
     $exchange->setType($this->exchangeType);
     $exchange->setFlags(AMQP_DURABLE);
     $exchange->declareExchange();
     return $exchange;
 }
开发者ID:Gtvar,项目名称:FivePercent-IntegrationBundle,代码行数:18,代码来源:ConfigExchangeFactory.php


示例15: __construct

 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


示例16: load_connection

 /**
  * @return AMQPConnection
  */
 private function load_connection($name)
 {
     if (!class_exists('AMQPConnection')) {
         throw new Exception('MPF_AMQP_Factory Exception: AMQPConnection not found');
     }
     $config = MPF::get_instance()->get_config($name, self::CONF_F_AMQP);
     if (!isset($config['host'])) {
         throw new Exception('MPF_AMQP_Factory Exception: host undefined');
     }
     $con = new AMQPConnection($config);
     $rst = $con->connect();
     if ($rst == false) {
         throw new AMQPException('MPF_AMQP_Factory AMQPException: can not connect to server');
     }
     return $con;
 }
开发者ID:uedcw,项目名称:webstory,代码行数:19,代码来源:Factory.php


示例17: __construct

 public function __construct($AMQPConfiguration, $exchangeName = '')
 {
     if (!class_exists('AMQPConnection')) {
         throw new \LogicException("Can't find AMQP lib");
     }
     $ampq = new \AMQPConnection($AMQPConfiguration);
     if ($ampq->connect()) {
         $channel = new \AMQPChannel($ampq);
         $exchange = new \AMQPExchange($channel);
         $exchange->setName($exchangeName);
         $exchange->declare();
         $this->channel = $channel;
         $this->exchange = $exchange;
     } else {
         throw new \RuntimeException("Can't connect to AMQP server");
     }
 }
开发者ID:rcambien,项目名称:riverline-worker-bundle,代码行数:17,代码来源:AMQP.php


示例18: send

 function send($to, $subject, $text)
 {
     try {
         $conn = new AMQPConnection($this->rabbitMQConf['host'], $this->rabbitMQConf['port'], $this->rabbitMQConf['user'], $this->rabbitMQConf['pass']);
         $channel = $conn->channel();
         $channel->access_request($this->rabbitMQConf['virtualHost'], false, false, true, true);
         $mailData = array("to" => $to, "subject" => $subject, "text" => $text);
         $mailDataToJson = json_encode($mailData);
         $msg = new AMQPMessage($mailDataToJson, array('content_type' => 'text/plain'));
         $channel->basic_publish($msg, $this->queueConf['exchange']);
         $channel->close();
         $conn->close();
         return true;
     } catch (Exception $e) {
         echo "Something went wrong " . $e->getMessage();
     }
 }
开发者ID:flying5,项目名称:rabbitmq-examples,代码行数:17,代码来源:publisher.php


示例19: loadConnections

 /**
  * @param Application $app
  */
 private function loadConnections(Application $app)
 {
     $app['amqp.connection'] = $app->share(function ($app) {
         if (!isset($app['amqp.connections'])) {
             throw new \InvalidArgumentException("You need to configure at least one AMQP connection");
         }
         $connections = [];
         foreach ($app['amqp.connections'] as $name => $options) {
             $connection = new \AMQPConnection($app['amqp.connections'][$name]);
             if (!$this->isLazy($app, $name)) {
                 $connection->connect();
             }
             $connections[$name] = $connection;
         }
         return $connections;
     });
 }
开发者ID:shotonoff,项目名称:silex-amqp-provider,代码行数:20,代码来源:AmqpServiceProvider.php


示例20: getChannel

 /**
  * getChannel
  *
  * @param string $connectionName
  *
  * @return \AMQPChannel
  */
 public function getChannel($connectionName, $vhost)
 {
     $file = rtrim(getenv('HOME'), '/') . '/.rabbitmq_admin_toolkit';
     if (!file_exists($file)) {
         throw new \InvalidArgumentException('Can\'t find ~/.rabbitmq_admin_toolkit file');
     }
     $credentials = json_decode(file_get_contents($file), true);
     if (!isset($credentials[$connectionName])) {
         throw new \InvalidArgumentException("Connection {$connectionName} not found in ~/.rabbitmq_admin_toolkit");
     }
     $defaultCredentials = ['host' => '127.0.0.1', 'port' => 15672, 'user' => 'root', 'password' => 'root'];
     $credentials = array_merge($defaultCredentials, $credentials[$connectionName]);
     $credentials['login'] = $credentials['user'];
     unset($credentials['user'], $credentials['port']);
     $connection = new \AMQPConnection(array_merge($credentials, ['vhost' => $vhost]));
     $connection->connect();
     return new \AMQPChannel($connection);
 }
开发者ID:ikwattro,项目名称:rabbit-mq-admin-toolkit,代码行数:25,代码来源:MessageGetCommand.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP AMQPExchange类代码示例发布时间:2022-05-23
下一篇:
PHP AMP_Registry类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap