matthiasnoback/tail-event-stream 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

matthiasnoback/tail-event-stream

最新稳定版本:v0.1.1

Composer 安装命令:

composer require matthiasnoback/tail-event-stream

包简介

A simple, tail-based event stream

README 文档

README

An event stream library based on tail.

Note: I don't think you should use this library in a real project, but it's great for educational purposes. I use it in workshops only."

Getting started

Install using Composer:

composer require matthiasnoback/tail-event-stream 

Usage

Adding messages to the stream:

use TailEventStream\Producer;

$streamFilePath = __DIR__ . '/var/stream.txt';

$producer = new Producer($streamFilePath);
$producer->produce('hello_world', ['Hello' => 'World!']);

The stream.txt file contains one message per line:

{"messageType":"hello_world","data":{"Hello":"World!"}}

Using tail -f a consumer can read each message from the stream, and it will keep consuming messages until you quit the process:

use TailEventStream\Consumer;

$streamFilePath = __DIR__ . '/var/stream.txt';

$consumer = new Consumer($streamFilePath);

$consumer->consume(function (string $messageType, array $data) {
    // $messageType will be 'hello_world'
    // $data will  be ['Hello' => 'World!']
});

consume() accepts a second argument, which is the index (or line) at which to start.

统计信息

  • 总下载量: 346
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-25