Broker class defines the configuration for connecting to Kafka and managing topics for AveniECA streaming.
Class Definition
Location:avenieca/config/broker.py:7
Configuration Fields
url (required)
Type:str
The Kafka broker URL with host and port.
Examples:
sub_topic (required)
Type:str
The topic name for subscribing (where producers send data to the digital twin).
Usage:
- Used by Stream and Event producers
- Not used by Consumer
- Can be empty string for consumer-only configs
pub_topic (required)
Type:str
The topic name for publishing (where consumers read data from the digital twin).
Usage:
- Used by Consumer
- Not used by Stream and Event producers
- Can be empty string for producer-only configs
group (required)
Type:str
The consumer group ID for Kafka consumer group management.
Purpose:
- Identifies which consumer group this client belongs to
- Multiple consumers with the same group share message processing
- Each message is delivered to only one consumer per group
- Different groups receive all messages independently
auto_offset_reset (optional)
Type:strDefault:
"latest"
Controls where consumption starts when no previous offset exists.
Values:
"latest": Start from newest messages (default)"earliest": Start from oldest available messages
Basic Usage
Producer Configuration
Consumer Configuration
Full Configuration
Environment Variables
Common practice is to use environment variables for configuration:Usage Examples
Stream Producer
Event Producer
Consumer
Advanced Configurations
Multiple Brokers
Development vs Production
Topic Naming Conventions
Consumer Group Behavior
Single Consumer
Multiple Consumers, Same Group
Multiple Consumers, Different Groups
Offset Reset Behavior
Latest (Default)
Earliest
Configuration Best Practices
- Use environment variables for sensitive or environment-specific values
- Use descriptive topic names that indicate data type and purpose
- Use consistent group naming across related consumers
- Set
auto_offset_reset="earliest"for development to see all messages - Set
auto_offset_reset="latest"for production to avoid reprocessing - Use empty strings for unused topic fields (sub_topic for consumers, pub_topic for producers)
Connection Examples
Local Development
Docker Compose
Cloud Kafka (Confluent, AWS MSK, etc.)
Related Classes
- Stream Producer - Using Broker with Stream
- Event Producer - Using Broker with Event
- Consumer - Using Broker with Consumer
- Overview - Streaming architecture and concepts