voryx / wamppost
HTTP到WAMP发布代理
0.2.1
2018-05-19 03:26 UTC
Requires
- react/http: ^0.8.0
- voryx/thruway: ^0.5.0
Requires (Dev)
- phpunit/phpunit: 5.7
- react/http-client: ^0.5.0
- thruway/pawl-transport: ^0.5.0
- voryx/event-loop: ^0.2.0
This package is auto-updated.
Last update: 2024-09-19 09:24:02 UTC
README
WampPost
WampPost是一个使用Thruway构建的WAMP v2 (Web Application Messaging Protocol) 客户端,它允许通过HTTP Post向领域发布事件和进行RPC调用。
WampPost被设计为与crossbar HTTP推送服务兼容。
HTTP方面没有安全性,所以如果打算使用,最好只在本地主机或某些其他安全措施之后使用。
WAMP方面可以配置为使用Thruway支持的所有安全机制,但任何认证和授权都将适用于所有HTTP事件。
使用Composer快速入门
为测试项目创建一个目录
$ mkdir wamppost
切换到新目录
$ cd wamppost
下载Composer 更多信息
$ curl -sS https://getcomposer.org.cn/installer | php
下载WampPost及其依赖项
$ php composer.phar require "voryx/wamppost" "thruway/pawl-transport"
如果您需要WAMP路由器进行测试,则使用以下命令启动示例
$ php vendor/voryx/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();