wamp2.4+composer+rabbitmq環境部署-176

version wamp 2.4php


1.打開opensslgit

分別更改php.ini的文件配置github

E:\wamp\bin\apache\Apache2.4.4\bin\php.iniapache

E:\wamp\bin\apache\Apache2.4.4\bin\php.inijson

php.ini的功能打開composer

extension=php_openssl.dllide


2.Composer下載測試

https://getcomposer.org/Composer-Setup.exeui

下載完成直接點下一步圖型安裝……命令行


3.php-amqplib下載

https://github.com/videlalvaro/php-amqplib/archive/master.zip

加壓後複製PhpAmqpLib文件夾到項目根目錄下



4.根目錄下建立文件:composer.json

{

  "require": {

      "videlalvaro/php-amqplib": "2.2.*"

  }

}


5.cmd命令行安裝php-amqplib:


E:\wamp\bin\php\php5.4.16>E:\wamp\bin\php\php5.4.16/php.exe composer

Could not open input file: composer


E:\wamp\bin\php\php5.4.16>php composer.phar

Could not open input file: composer.phar


E:\wamp\bin\php\php5.4.16>composer update friendsofsymfony/user-bundle

Composer could not find a composer.json file in E:\wamp\bin\php\php5.4.16

To initialize a project, please create a composer.json file as described in the

http://getcomposer.org/ "Getting Started" section


到項目跟目錄安裝php-amqplib


E:\wamp\www\gx> composer update friendsofsymfony/user-bundle

Package "friendsofsymfony/user-bundle" listed for update is not installed. Ignor

ing.

Loading composer repositories with package information

Updating dependencies (including require-dev)

  - Installing videlalvaro/php-amqplib (v2.2.6)

    Downloading: 100%


Writing lock file

Generating autoload files




6.環境完成開始測試


send.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPConnection;

use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPConnection('192.168.99.104', 5672, 'guest', 'guest');

$channel = $connection->channel();

$channel->queue_declare('hello', false, false, false, false);


$data = implode(' ', array_slice($argv, 1));

if(empty($data)) $data = "Hello World!";

$msg = new AMQPMessage($data,

                        array('delivery_mode' => 2) # make message persistent

                      );


$channel->basic_publish($msg, '', 'hello');


echo " [x] Sent ", $data, "\n";

$channel->close();

$connection->close();

?>

receive.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPConnection;

$connection = new AMQPConnection('192.168.99.104', 5672, 'guest', 'guest');

$channel = $connection->channel();


$channel->queue_declare('hello', false, false, false, false);


echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";



$callback = function($msg){

  echo " [x] Received ", $msg->body, "\n";

  sleep(substr_count($msg->body, '.'));

  echo " [x] Done", "\n";

  $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);

};


$channel->basic_qos(null, 1, null);

$channel->basic_consume('hello', '', false, false, false, false, $callback);


while(count($channel->callbacks)) {

    $channel->wait();

}

?>


7.cmd命令行測試:


發送消息:

E:\wamp\www\gx>php send.php 終於測試成功了

 [x] Sent 終於測試成功了


E:\wamp\www\gx>php send.php wamp2.4+rabbitmq 測試經過

 [x] Sent wamp2.4+rabbitmq 測試經過



接受消息:

E:\wamp\www\gx>php receive.php

 [*] Waiting for messages. To exit press CTRL+C

 [x] Received 終於測試成功了

 [x] Done

 [x] Received wamp2.4+rabbitmq 測試經過

 [x] Done

相關文章
相關標籤/搜索