Messaging Patterns Demo¶
This demo provides a guided walkthrough of the FCC event bus messaging infrastructure -- from basic pub/sub through filtered subscriptions, fan-out delivery, priority handling, and full event replay.
Table of Contents¶
- Overview
- Prerequisites
- Running the Demo
- Step-by-Step Walkthrough
- Expected Output
- What You Will Learn
- Next Steps
Overview¶
The FCC event bus is a thread-safe in-process pub/sub system that routes events between framework components. This demo covers six core messaging patterns that every FCC integrator should understand:
- Topic-based subscription -- subscribe to specific event types
- Payload filtering -- filter events by field values
- Fan-out delivery -- one event, many subscribers
- Priority handling -- process high-priority events first
- Event serialization -- persist and replay event streams
- Dead-letter handling -- manage undeliverable events
Prerequisites¶
- Python 3.10+ with FCC installed (
pip install -e ".[dev]") - No API key required -- all messaging is in-process
Running the Demo¶
CLI¶
Programmatic¶
from fcc.demos.registry import DemoRegistry
from fcc.demos.runner import DemoRunner
registry = DemoRegistry.from_builtin()
demo = registry.get("messaging_patterns")
runner = DemoRunner()
result = runner.run(demo)
print(f"Success: {result.success}, Steps: {result.steps_completed}/{result.total_steps}")
Step-by-Step Walkthrough¶
Step 1: Create EventBus¶
Initialize a thread-safe EventBus instance ready for subscriptions.
Step 2: Subscribe with Filters¶
Register subscribers with EventFilter to select events by type,
source, and payload fields.
from fcc.messaging.bus import EventFilter
from fcc.messaging.events import EventType
bus.subscribe(
EventType.SIMULATION_STARTED,
lambda e: print(f"Simulation: {e.payload}"),
event_filter=EventFilter(source_match="simulation_engine"),
)
Step 3: Publish Events¶
Publish events and observe routing to matching subscribers.
Step 4: Demonstrate Fan-Out¶
Show that a single event reaches all matching subscribers independently.
Step 5: Show Priority Handling¶
Demonstrate that high-priority events are processed before lower-priority events when multiple events are queued.
Step 6: Replay Event Stream¶
Serialize all published events and replay them through EventReplay.
Expected Output¶
Step 1/6: Create EventBus ......................... OK
Step 2/6: Subscribe with Filters .................. OK
Step 3/6: Publish Events .......................... OK
Step 4/6: Demonstrate Fan-Out ..................... OK
Step 5/6: Show Priority Handling .................. OK
Step 6/6: Replay Event Stream ..................... OK
Demo complete: 6/6 steps passed (12.3 ms)
What You Will Learn¶
- How to create and configure the FCC
EventBus - How to use
EventFilterfor targeted subscriptions - Fan-out delivery semantics and subscriber isolation
- Priority-based event processing patterns
- Event serialization and replay for audit trails
- Integration patterns for connecting event-driven components
Next Steps¶
- Messaging Real-Time Demo -- WebSocket streaming
- Messaging Phase 14 Addendum -- Compliance events
- Messaging Phase 15 Addendum -- Priority queues and DLQ
- Compliance Pipeline Demo -- Event-driven auditing
- Guidebook Chapter 7