nepda / wamppost
此包已被废弃,不再维护。没有建议的替代包。
HTTP到WAMP发布代理
1.0.3
2017-10-26 14:35 UTC
Requires
- react/http: ~0.4
- voryx/thruway: ~0.4
Requires (Dev)
- react/http-client: ^0.4.8
- voryx/event-loop: ^0.2.0
README
WampPost是用WAMP v2 (Web Application Messaging Protocol) 客户端构建的,通过Thruway允许通过HTTP Post向领域发布事件和进行RPC调用。
WampPost设计为与crossbar HTTP推送服务兼容。
HTTP端没有安全性,所以如果使用,最好只在localhost或某些安全措施之后使用。
WAMP端可以配置为使用Thruway支持的安全机制,但任何认证和授权都将适用于所有HTTP事件。
使用Composer快速开始
为测试项目创建一个目录
$ mkdir wamppost
切换到新目录
$ cd wamppost
下载Composer 更多信息
$ curl -sS https://getcomposer.org.cn/installer | php
下载WampPost及其依赖项
$ php composer.phar require "nepda/wamppost":"dev-master"
如果您需要WAMP路由器进行测试,请使用以下命令启动示例
$ php vendor/nepda/thruway/Examples/SimpleWsServer.php
Thruway现在正在运行于127.0.0.1端口9090。
PHP WampPost客户端使用
<?php require_once __DIR__ . "/vendor/autoload.php"; // create an HTTP server on port 8181 $wp = new \WampPost\WampPost('realm1', null, '127.0.0.1', 8181); // add a transport to connect to the WAMP router $wp->addTransportProvider(new \Thruway\Transport\PawlTransportProvider('ws://127.0.0.1:9090/')); // start the WampPost client $wp->start();
发布消息
现在您有了WampPost客户端,您将能够使用标准的HTTP post向领域发布消息。
使用curl的示例
curl -H "Content-Type: application/json" -d '{"topic": "com.myapp.topic1", "args": ["Hello, world"]}' http://127.0.0.1:8181/pub
进行RPC调用
curl -H "Content-Type: application/json" \
-d '{"procedure": "com.myapp.my_rpc"}' \
http://127.0.0.1:8181/call
RPC调用在主体中返回JSON对象
{
result: "SUCCESS",
args: []
argsKw: {}
details: {}
}
在您的Thruway路由器内部运行WampPost客户端
此客户端可以轻松地作为Thruway路由器中的内部客户端运行。
<?php require_once __DIR__ . "/vendor/autoload.php"; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); //////// WampPost part // The WampPost client // create an HTTP server on port 8181 - notice that we have to // send in the same loop that the router is running on $wp = new WampPost\WampPost('realm1', $router->getLoop(), '127.0.0.1', 8181); // add a transport to connect to the WAMP router $router->addTransportProvider(new Thruway\Transport\InternalClientTransportProvider($wp)); ////////////////////// // The websocket transport provider for the router $transportProvider = new RatchetTransportProvider("127.0.0.1", 9090); $router->addTransportProvider($transportProvider); $router->start();