Event Streaming
Event streaming sends domain events through Redis Streams as they happen. Workers in consumer groups share the reading and processing.
How It Works
Publish
Domain services publish their events. Each domain has its own Redis Stream.
Stream
Redis Streams keeps the events for the consumer groups. It trims old entries when a stream reaches its maximum length.
Consume
Workers read events in batches, process them and confirm each one. A message that is not confirmed is delivered again.
use App\Domain\Shared\EventSourcing\EventStreamPublisher; // Inject via constructor public function __construct( private readonly EventStreamPublisher $publisher ) {} // Publish a domain event $messageId = $this->publisher->publish('account', [ 'event_class' => AccountCreatedEvent::class, 'aggregate_uuid' => $account->uuid, 'name' => $account->name, 'balance' => '0.00', ]); // Batch publish $ids = $this->publisher->publishBatch([ ['domain' => 'account', 'data' => [...]], ['domain' => 'payment', 'data' => [...]], ]);
use App\Domain\Shared\EventSourcing\EventStreamConsumer; $consumer = app(EventStreamConsumer::class); // Create consumer group (once, on startup) $consumer->createConsumerGroup('account', '0'); // Read messages in a loop while (true) { $messages = $consumer->consume('account', 'worker-1'); foreach ($messages as [$id, $fields]) { $payload = json_decode($fields['payload'], true); // Process event... $consumer->acknowledge('account', $id); } }
Available Streams
Each domain publishes to its own Redis Stream. The stream keys start with the value of EVENT_STREAMING_PREFIX, which is finaegis:events here.
| Domain | Stream Key | Events |
|---|---|---|
| account | account-events |
Accounts created, updated and frozen, balance changes |
| exchange | exchange-events |
Orders placed, matched and cancelled, trades |
| wallet | wallet-events |
Wallets created, transfers, multi-signature approvals |
| compliance | compliance-events |
Identity check submissions, anti-money laundering alerts, sanctions screening |
| lending | lending-events |
Loan applications, approvals, disbursements |
| treasury | treasury-events |
Portfolio rebalancing, net asset value calculations |
| payment | payment-events |
Deposits, withdrawals, transfer completions |
| fraud | fraud-events |
Fraud alerts, case escalations, pattern detections |
| mobile | mobile-events |
Device registrations, session events |
| mobile-payment | mobile-payment-events |
Payment intents, receipt generation |
| trust-cert | trust-cert-events |
Certificate issuance, revocation |
| cross-chain | cross-chain-events |
Bridge transfers, completions |
| defi | defi-events |
Positions opened and closed, swaps |
| stablecoin | stablecoin-events |
Minting, redemption, collateral changes |
| privacy | privacy-events |
Identity proofs, delegated proof progress |
Message Format
{
"domain": "account",
"event_class": "App\\Domain\\Account\\Events\\AccountCreatedEvent",
"aggregate_uuid": "550e8400-...",
"payload": "{...serialized event...}",
"published_at": "2026-03-16T10:30:00Z"
}
Configuration
EVENT_STREAMING_ENABLED
false
Turns streaming on or off
EVENT_STREAMING_REDIS_CONNECTION
default
Redis connection name
EVENT_STREAMING_PREFIX
finaegis:events
Stream key prefix
EVENT_STREAMING_MAX_LENGTH
100000
Maximum entries per stream
EVENT_STREAMING_CONSUMER_GROUP
finaegis-consumers
Consumer group name
EVENT_STREAMING_BLOCK_TIMEOUT
5000
Read wait time in milliseconds
EVENT_STREAMING_BATCH_SIZE
100
Messages per read
EVENT_STREAMING_IDLE_TIMEOUT
30000
Idle time in milliseconds before another worker can claim a message
EVENT_STREAMING_TTL_HOURS
168
Retention period (7 days)
Monitoring
php artisan event-stream:monitor # All streams php artisan event-stream:monitor --domain account # Specific domain php artisan event-stream:monitor --json # JSON output for tooling
Consumer Group Operations
A consumer group lets several workers share one stream. If a worker stops, another worker claims its unconfirmed messages.
| Method | Purpose |
|---|---|
createConsumerGroup($domain, $startId) | Creates the group. Start at '0' to read from the beginning, or at '$' to read only new messages. |
consume($domain, $consumerName) | Waits for and reads a batch of messages for this consumer |
acknowledge($domain, $messageId) | Marks a message as processed, so it is not delivered again |
getPending($domain) | Lists messages that are not confirmed yet |
claimIdleMessages($domain, $consumer) | Takes over messages from consumers that stopped |
getConsumerGroupInfo($domain) | Shows the group's consumers and the number of waiting messages |