Skip to content

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

  1. Overview
  2. Prerequisites
  3. Running the Demo
  4. Step-by-Step Walkthrough
  5. Expected Output
  6. What You Will Learn
  7. 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

fcc demo run messaging-patterns

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.

from fcc.messaging.bus import EventBus
bus = EventBus()

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 EventFilter for 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