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


PHP AMQPStreamConnection::close方法代码示例

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


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

 /**
  *
  */
 public function __destruct()
 {
     if ($this->connection) {
         $this->channel->close();
         $this->connection->close();
     }
 }
开发者ID:RepoMon,项目名称:scheduler,代码行数:10,代码来源:QueueClient.php

示例3: tearDown

 public function tearDown()
 {
     if ($this->ch) {
         $this->ch->exchange_delete($this->exchange_name);
         $this->ch->close();
     }
     if ($this->conn) {
         $this->conn->close();
     }
 }
开发者ID:vongrad,项目名称:loanbroker,代码行数:10,代码来源:AbstractPublishConsumeTest.php

示例4: registerAction

 /**
  * @Route("/register", name="security_register")
  * @Method("POST")
  */
 public function registerAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $request = Request::createFromGlobals();
     $email = $request->request->get('email');
     $password = $request->request->get('password');
     $ico = trim($request->request->get('ico'));
     $user = new User();
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword($password, $user->getSalt()));
     $user->setEmail($email);
     $user->setIco($ico);
     $backgroundImages = ['animal', 'corn', 'farming', 'chicken'];
     shuffle($backgroundImages);
     $user->setBackgroundImage($backgroundImages[0]);
     $profileImages = ['animal', 'corn', 'farming', 'chicken'];
     shuffle($profileImages);
     $user->setProfileImage($profileImages[0]);
     $em->persist($user);
     $em->flush();
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->get('security.token_storage')->setToken($token);
     //rabbit MQ
     $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
     $channel = $connection->channel();
     $channel->queue_declare('ico_queue', false, false, false, false);
     $json = json_encode(["userId" => $user->getId(), "ico" => $ico]);
     $msg = new AMQPMessage($json);
     $channel->basic_publish($msg, '', 'ico_queue');
     dump(" [x] Sent '{$ico}'\n");
     $channel->close();
     $connection->close();
     return $this->redirect($this->generateUrl('main_overview'));
 }
开发者ID:alifuk,项目名称:mrafi,代码行数:38,代码来源:SecurityController.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: disconnect

 /**
  * Disconnects from the message broker
  */
 public function disconnect()
 {
     if ($this->connection !== null) {
         $this->channel->close();
         $this->connection->close();
     }
     return $this;
 }
开发者ID:keruald,项目名称:broker,代码行数:11,代码来源:AMQPBroker.php

示例7: close

 /**
  * Closing connection to the server with possible to delete queue
  * @param bool|false $delete Set true for delete queue before closing connection
  */
 public function close($delete = false)
 {
     if ($delete) {
         $this->delete();
     }
     $this->channel->close();
     $this->connection->close();
 }
开发者ID:zarincheg,项目名称:json-bus,代码行数:12,代码来源:RabbitQueue.php

示例8: forward_to_router

function forward_to_router($msg, $routing_key)
{
    $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
    $channel = $connection->channel();
    $channel->queue_declare($routing_key, false, false, false, false);
    $channel->basic_publish($msg, '', $routing_key);
    $channel->close();
    $connection->close();
}
开发者ID:vongrad,项目名称:loanbroker,代码行数:9,代码来源:receive.php

示例9: closeConnections

 /**
  * Close the channel and connections to AMQP
  *
  * @return void
  */
 public function closeConnections()
 {
     if ($this->channel) {
         $this->channel->close();
     }
     if ($this->connection) {
         $this->connection->close();
     }
 }
开发者ID:imbo,项目名称:imbo-amqp-publisher,代码行数:14,代码来源:AmqpPublisher.php

示例10: closeConnection

 /**
  * @return void
  */
 public function closeConnection()
 {
     $this->closeChannel();
     if ($this->connection instanceof AbstractConnection) {
         $this->connection->close();
         $this->logger->info('Connection clossed!', ['server' => $this->server, 'port' => $this->port, 'vhost' => $this->vhost]);
     }
     $this->connection = null;
 }
开发者ID:retrinko,项目名称:cottontail,代码行数:12,代码来源:PhpAmqpLibConnector.php

示例11: forward_to_translator

function forward_to_translator($msg, $routing_key)
{
    $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
    $channel = $connection->channel();
    $channel->exchange_declare('bank_translators_exchange', 'direct', false, false, false);
    $channel->basic_publish($msg, 'bank_translators_exchange', $routing_key);
    $channel->close();
    $connection->close();
}
开发者ID:vongrad,项目名称:loanbroker,代码行数:9,代码来源:receive.php

示例12: __destruct

 public function __destruct()
 {
     $this->channel->close();
     unset($this->channel);
     $this->connection->close();
     unset($this->connection);
     unset($this->replyQueueName);
     unset($this->consumerTag);
     unset($this->outputMessages);
 }
开发者ID:parallel-php,项目名称:parallel-task,代码行数:10,代码来源:RabbitMQQueue.php

示例13: sendBuyServiceToRabbit

 public function sendBuyServiceToRabbit($taskId, $resourceId)
 {
     $connection = new AMQPStreamConnection(RABBIT_URL, RABBIT_PORT, RABBIT_USER, RABBIT_PASSWORD);
     $channel = $connection->channel();
     $channel->queue_declare($taskId, false, false, false, false);
     $msg = new AMQPMessage($resourceId);
     $channel->basic_publish($msg, '', $taskId);
     $channel->close();
     $connection->close();
 }
开发者ID:diegomurbanos,项目名称:ServicesWebSocket,代码行数:10,代码来源:RabbitMQ.php

示例14: disconnect

 /**
  * Closes the transient connection with the AMQP broker.
  *
  * This method will close an open connection with the AMQP broker.
  *
  * @return boolean true if connection was successfully closed, false otherwise.
  */
 public function disconnect()
 {
     if (!$this->isConnected()) {
         return false;
     }
     try {
         $this->connection->close();
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
开发者ID:calcinai,项目名称:php-amqplib-bridge,代码行数:19,代码来源:AMQPConnection.php

示例15: subscribe

 public function subscribe()
 {
     $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
     $channel = $connection->channel();
     $channel->queue_declare('aggregator', false, false, false, false);
     $channel->basic_consume('aggregator', '', false, true, false, false, array($this, 'on_response'));
     echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
     while (count($channel->callbacks)) {
         $channel->wait();
     }
     $channel->close();
     $connection->close();
 }
开发者ID:vongrad,项目名称:loanbroker,代码行数:13,代码来源:receive.php


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