PHPackages                             menumbing/event-stream - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. menumbing/event-stream

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

menumbing/event-stream
======================

Event stream component for Hyperf

0643↓50%PHP

Since Dec 15Pushed 5mo agoCompare

[ Source](https://github.com/menumbing/event-stream)[ Packagist](https://packagist.org/packages/menumbing/event-stream)[ RSS](/packages/menumbing-event-stream/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Event Stream for Hyperf
=======================

[](#event-stream-for-hyperf)

A powerful event streaming component for Hyperf applications, providing a simple way to produce and consume events using stream engine like Redis and Kafka.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require menumbing/event-stream
```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Hyperf Framework &gt;= 3.1
- Redis Server

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php bin/hyperf.php vendor:publish menumbing/event-stream
```

This will create a `event_stream.php` configuration file in your `config/autoload` directory.

### Configuration Options

[](#configuration-options)

The configuration file contains the following options:

```
return [
    // The name of the consumer group used for stream processing
    'group_name' => env('APP_NAME', 'menumbing'),

    // Available stream drivers configuration
    'drivers' => [
        'default' => [
            'driver'  => RedisStream::class,
            'id'      => DefaultRedisId::class,
            'options' => [
                'pool'             => 'default', // Redis connection pool name
                'read_from'        => ReadMessageFrom::GROUP_CREATED, // Starting point for reading messages
                'wait_time'        => 100, // Wait time in milliseconds between read attempts
                'retention_period' => 7, // Message retention period in days
                'approx'           => false, // Use approximate for deleting messages
            ],
        ],
    ],

    // Consumer configuration settings
    'consumer' => [
        'processes' => [], // Array of process configurations for different streams
        'block_for' => 1, // The number of seconds to sleep between processing batches
        'retry_after' => 60, // The number of seconds to retry zombie message due to offline consumer or failed process
    ],

    // Serialization configuration for messages
    'serialization' => [
        'serializer' => 'default', // The serializer service to use
        'format'     => 'json', // The format to serialize messages to
    ]
];
```

Usage
-----

[](#usage)

### Producing Events

[](#producing-events)

To produce events, you need to:

1. Create an event class
2. Annotate it with `#[ProducedEvent]`
3. Dispatch the event using the event dispatcher

```
