Event class provides event-driven publishing to your digital twin. Unlike the Stream producer, you control when signals are sent, making it ideal for triggered events and irregular updates.
Class Definition
Location:avenieca/producers/event.py:8
config(Broker): Broker configuration object
Methods
publish
Signature:avenieca/producers/event.py:21
signal(Signal): Signal dataclass instance to publish
Basic Usage
Simple Event Publishing
Multiple Events
Publish multiple events independently:When to Use Event Producer
Use Event Producer for:
User-triggered actionsStream vs Event Comparison
| Feature | Stream Producer | Event Producer |
|---|---|---|
| Timing | Automatic (sync_rate) | Manual |
| Use case | Periodic updates | Triggered events |
| Handler | Returns Signal | Receives Signal |
| Control | Library manages timing | You control when to publish |
| Example | Sensor every 1s | Button click |
Advanced Examples
Batch Event Publishing
Conditional Publishing
Error Handling
Signal Validation
The Event producer validates signals before publishing (seeavenieca/producers/event.py:29):
- Signal must be a Signal dataclass instance
- State must not be None or empty
- State must be 1-dimensional
- State values must be int or float
Controlling Sync
Thesync property controls whether publishing is enabled:
Related Classes
- Stream Producer - For continuous, time-based streaming
- Consumer - For consuming events
- Configuration - Broker configuration options