當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Connection\AMQPStreamConnection類代碼示例

本文整理匯總了PHP中PhpAmqpLib\Connection\AMQPStreamConnection的典型用法代碼示例。如果您正苦於以下問題:PHP AMQPStreamConnection類的具體用法?PHP AMQPStreamConnection怎麽用?PHP AMQPStreamConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AMQPStreamConnection類的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: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Connection a RabbitMQ
     $connection = new AMQPStreamConnection('rabbitmq', 5672, 'guest', 'guest');
     $channel = $connection->channel();
     $channel->basic_qos(null, 1, null);
     // On ne traite pas plus de 1 message à la fois
     // Déclaration de la queue
     $channel->queue_declare($queue = 'tasks', $passive = false, $durable = true, $exclusive = false, $auto_delete = false);
     $output->writeln("<fg=black;bg=cyan>####################################################</>");
     $output->writeln("<fg=black;bg=cyan>#### Waiting for messages. To exit press CTRL+C ####</>");
     $output->writeln("<fg=black;bg=cyan>####################################################</>");
     $callback = function ($msg) use($output) {
         $output->writeln("");
         $output->writeln("--------------------------");
         $output->writeln("<comment>Data reçu : </comment>");
         $task = json_decode($msg->body, true);
         $output->writeln("<info>" . json_encode($task, JSON_PRETTY_PRINT) . "</info>");
         $output->writeln("");
         $output->writeln("<comment>Build de l'objet " . $task['class'] . " avec l'id " . $task['id'] . "</comment>");
         $object = new $task['class']($task['id']);
         $output->writeln("<comment>Execution de la méthode</comment>");
         $object->{$task}['methode']();
         $output->writeln("");
         $output->writeln("<comment>Fin de l'execution de la méthode</comment>");
         $output->writeln("<comment>Envoi a RabbitMQ que la message à était traité</comment>");
         $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
     };
     $channel->basic_consume($queue = 'tasks', $consumer_tag = '', $no_local = false, $no_ack = false, $exclusive = false, $nowait = false, $callback);
     while (count($channel->callbacks)) {
         $channel->wait();
     }
 }
開發者ID:Hugues-Antoine,項目名稱:RabbitMQTest,代碼行數:33,代碼來源:Received.php

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

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

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

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

示例8: it_properly_pops_job_off_of_rabbitmq

 public function it_properly_pops_job_off_of_rabbitmq(AMQPStreamConnection $connection, AMQPChannel $channel, AMQPMessage $message, Container $container)
 {
     $queue = 'default';
     $connection->channel()->shouldBeCalled()->willReturn($channel);
     $channel->exchange_declare($queue, 'direct', false, true, false)->shouldBeCalled();
     $channel->queue_declare($queue, false, true, false, false, false, null)->shouldBeCalled();
     $channel->queue_bind($queue, $queue, $queue)->shouldBeCalled();
     $channel->basic_get($queue)->shouldBeCalled()->willReturn($message);
     $this->setContainer($container);
     $this->pop()->shouldHaveType(RabbitMQJob::class);
 }
開發者ID:limedeck,項目名稱:laravel-queue-rabbitmq,代碼行數:11,代碼來源:RabbitMQQueueSpec.php

示例9: initialize_translator

 protected function initialize_translator()
 {
     $connection = new AMQPStreamConnection($this->translator_params['host'], $this->translator_params['port'], $this->translator_params['username'], $this->translator_params['password']);
     $channel = $connection->channel();
     $channel->exchange_declare('bank_translators_exchange', 'direct', false, false, false);
     list($queue_name, , ) = $channel->queue_declare("", false, false, true, false);
     $this->translator_params['queue_name'] = $queue_name;
     $channel->queue_bind($queue_name, 'bank_translators_exchange', $this->translator_params['routing_key']);
     echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
     $this->translator = array('connection' => $connection, 'channel' => $channel);
 }
開發者ID:vongrad,項目名稱:loanbroker,代碼行數:11,代碼來源:abstract_translator.php

示例10: getChannel

 /**
  * Connects to AMQP and gets channel
  *
  * @return AMQPChannel
  */
 private function getChannel()
 {
     if (!$this->channel) {
         $conn = new AMQPStreamConnection($this->connectionOptions['host'], $this->connectionOptions['port'], $this->connectionOptions['user'], $this->connectionOptions['pass'], $this->connectionOptions['vhost']);
         $ch = $conn->channel();
         $ch->exchange_declare($this->exchange, $this->exchangeType, false, true, false);
         $ch->queue_declare($this->queue, false, true, false, false);
         $ch->queue_bind($this->queue, $this->exchange, $this->routingKey);
         $this->channel = $ch;
     }
     return $this->channel;
 }
開發者ID:pekkis,項目名稱:queue,代碼行數:17,代碼來源:PhpAMQPAdapter.php

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

示例12: declareExchange

 /**
  * First tries to create exchange using passive flag.
  * If exchange does not exist, creates new with provided settings.
  *
  * @param AMQPStreamConnection $connection AMQP connection.
  * @param string               $name       Exchange name.
  * @param string               $type       Exchange type.
  * @param array                $params     Optional declare exchange parameters.
  *
  * @return void
  *
  * @see self::$defaultDeclareExchangeParams
  */
 public static function declareExchange(AMQPStreamConnection $connection, $name, $type, array $params = [])
 {
     $ch = $connection->channel();
     $params = array_merge(self::$defaultDeclareExchangeParams, $params);
     if ($params['arguments'] and is_array($params['arguments'])) {
         $params['arguments'] = new AMQPTable($params['arguments']);
     }
     try {
         $ch->exchange_declare($name, $type, false, $params['durable'], $params['auto_delete'], $params['internal'], $params['nowait'], $params['arguments']);
     } finally {
         $ch->close();
     }
 }
開發者ID:scalr,項目名稱:fatmouse-phpclient,代碼行數:26,代碼來源:Util.php

示例13: getChannel

 protected function getChannel()
 {
     if (empty($this->channel)) {
         try {
             $connection = new AMQPStreamConnection($this->config['host'], $this->config['port'], $this->config['user'], $this->config['password']);
         } catch (\ErrorException $ee) {
             sleep(2);
             return $this->getChannel();
         }
         $this->channel = $connection->channel();
     }
     return $this->channel;
 }
開發者ID:Mailclark,項目名稱:bot2hook,代碼行數:13,代碼來源:Rabbitmq.php

示例14: setUp

 protected function setUp()
 {
     // drop AMQP server state
     $amqpConnection = new AMQPStreamConnection(TASK_QUEUE_AMQP_HOST, TASK_QUEUE_AMQP_PORT, TASK_QUEUE_AMQP_USER, TASK_QUEUE_AMQP_PASSWORD);
     $channel = $amqpConnection->channel();
     $channel->queue_delete(TASK_QUEUE_AMQP_QUEUE_NAME);
     $channel->close();
     $amqpConnection->close();
     $channel = null;
     $amqpConnection = null;
     $this->mockApplication($this->getAppConfig());
     parent::setUp();
 }
開發者ID:turboezh,項目名稱:yii2-task-queue,代碼行數:13,代碼來源:TestCase.php

示例15: __construct

 /**
  * @param string $exchange
  * @param string $type
  * @param array $config
  * @throws ConnectionException
  */
 public function __construct($exchange, $type = 'direct', $config = [])
 {
     $this->config = $this->buildConfig($config);
     $this->exchange = $exchange;
     $this->type = $type;
     try {
         $connection = new AMQPStreamConnection($this->config['host'], $this->config['port'], $this->config['username'], $this->config['password'], $this->config['vhost'], $this->config['connection']['insist'], $this->config['connection']['login_method'], $this->config['connection']['login_response'], $this->config['connection']['locale'], $this->config['connection']['timeout'], $this->config['connection']['read_write_timeout'], $this->config['connection']['context'], $this->config['connection']['keepalive'], $this->config['connection']['heartbeat']);
         $this->channel = $connection->channel();
         $this->channel->exchange_declare($exchange, $type, $this->config['exchange']['passive'], $this->config['exchange']['durable'], $this->config['exchange']['auto_delete'], $this->config['exchange']['internal'], $this->config['exchange']['no_wait'], $this->config['exchange']['arguments'], $this->config['exchange']['ticket']);
     } catch (\Exception $e) {
         throw new ConnectionException('Carrot failed to build connection: ' . $e->getMessage());
     }
 }
開發者ID:sunspikes,項目名稱:carrot,代碼行數:19,代碼來源:Carrot.php


注:本文中的PhpAmqpLib\Connection\AMQPStreamConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。