bzrk/http-feeds-server

此项目是[HTTP Feeds](https://github.com/http-feeds/http-feeds)的PHP实现。

0.6 2022-02-13 15:34 UTC

This package is auto-updated.

Last update: 2024-09-21 14:05:09 UTC


README

此项目是[HTTP Feeds](https://github.com/http-feeds/http-feeds)的PHP实现。

HTTP Feeds

使用纯HTTP API进行异步事件流和数据复制的最小规范。

HTTP feeds是一个针对通过HTTP轮询事件的最低规范

  • 一个HTTP feed提供了一个HTTP GET端点
  • 它返回一系列按时间顺序排列的事件
  • CloudEvents事件格式序列化
  • 使用媒体类型application/cloudevents-batch+json进行批量响应
  • 并尊重lastEventId查询参数以滚动查看更多项目
  • 以支持无限轮询实时订阅。

HTTP feeds可用于解耦系统,无需消息代理异步进行,例如Kafka或RabbitMQ。

安装

composer require bzrk/http-feeds-server

Slim一起使用

...
class Repo implements Repository {

    public function getByIdGreaterThan(string $lastEventId, int $limit): FeedItemCollection
    {
        ....
    }
}

$fetcher = HttpFeedsFetcher::builder(new Repo())->limit(10)->build();

$app = AppFactory::create();
$app->get('/', new HttpFeedsController($fetcher));
$app->addErrorMiddleware(true, true, true);
$app->run();

ReactPHP一起使用

...
class Repo implements Repository {

    public function getByIdGreaterThan(string $lastEventId, int $limit): FeedItemCollection
    {
        ....
    }
}

$fetcher = HttpFeedsFetcher::builder(new Repo())->limit(10)->build();


$http = new React\Http\HttpServer(new HttpFeedsController($fetcher));
$socket = new React\Socket\SocketServer('0.0.0.0:8080');
$http->listen($socket);

参数

示例

轮询

http://server.com/inventory

http://server.com/inventory?lastEvenetId=1223

长轮询

http://server.com/inventory?timeout=5

http://server.com/inventory?lastEvenetId=1223&timeout=5