orus-io/php-xbus
Composer 安装命令:
composer require orus-io/php-xbus
包简介
PHP Client for xbus.io.
README 文档
README
A PHP client for Xbus.
This client relies on the xbus-http gateway, and is limited to implementing emitters, consumers and workers.
Installation
composer require orus-io/php-xbus dev-default
Usage
Emit a message
To emit a simple envelope with one events containing one or more items:
<?php
$actor = new \XbusClient\Actor('http://test.test', 'emittername', 'theApiKey');
$actor->emitItems("a.event.type", "item1", "item2");
?>
Receive a message
Receiving messages rely on the webhook feature of xbus-http. The client application must provide a http endpoint, on which xbus-http will POST some data.
A typical implementation for the endpoint is:
<?php
$actor = new \XbusClient\Actor('http://test.test', 'consumername', 'theApiKey');
$actor->handleRequest(
$_SERVER['HTTP_CONTENT_TYPE'], // <- The incoming request content type
fopen('php://input', 'r'), // <- The incoming request body (as a resource)
'header', // <- a callable that set a header on the response
'http_response_code', // <- a callable that sets the http response code
fopen('php://output', 'w'), // The response body resource
// The user-defined handler. This example one will print the incoming items
function(\Xbus\ActorProcessRequest $request): ?\Xbus\ActorProcessingState {
foreach($request->getInputs() as $input) {
print "input: " . $input.getName();
foreach($input->getEnvelope()->getEvents() as $event) {
print "event: " . $event.getType();
foreach($event->getItems() as $item) {
print "item: " . $item;
}
};
};
}
);
?>
统计信息
- 总下载量: 6.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-10