The PubSub module provides real-time publish/subscribe messaging for event-driven architectures. Functions can subscribe to topics and react instantly to published events.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iii-hq/iii/llms.txt
Use this file to discover all available pages before exploring further.
Configuration
Configure the PubSub module inconfig.yaml:
config.yaml
Available Adapters
- LocalAdapter (Default)
- RedisAdapter (Production)
In-memory pub/sub for development and single-instance deployments:
LocalAdapter stores subscriptions in memory. Events are only delivered to subscribers in the same process instance.
Publishing Events
Use thepubsub.publish function to publish events to a topic:
The topic name to publish the event to. Cannot be empty.
The event data payload. Can be any JSON-serializable value.
Subscribing to Topics
Define subscribe triggers to listen for events on specific topics:index.ts
Trigger Configuration
Must be
subscribe to register a PubSub subscriptionThe topic name to subscribe to
Use Cases
Real-time Notifications
Event Broadcasting
Cross-Service Communication
LocalAdapter vs RedisAdapter
LocalAdapter
- Use for: Development, single-instance deployments
- Storage: In-memory HashMap
- Scope: Single process instance only
- Performance: Extremely fast (no network overhead)
- Persistence: None (events lost on restart)
RedisAdapter
- Use for: Production, multi-instance deployments
- Storage: Redis pub/sub channels
- Scope: All connected instances
- Performance: Fast with minimal network latency
- Persistence: None (Redis pub/sub is ephemeral)
Error Handling
The publish function returns errors for invalid input:Best Practices
- Use descriptive topic names - Use namespaced topics like
user.created,order.shipped - Keep payloads small - PubSub is optimized for real-time events, not large data transfers
- Handle failures gracefully - Subscribers should not throw errors that affect other subscribers
- Use Redis in production - RedisAdapter enables horizontal scaling across multiple instances
- Don’t rely on delivery guarantees - Use the Queue module if you need guaranteed delivery
Comparison with Queue Module
| Feature | PubSub | Queue |
|---|---|---|
| Delivery | Fire-and-forget | At-least-once |
| Pattern | Broadcast to all subscribers | Single consumer processes each message |
| Use case | Real-time notifications, events | Background jobs, task processing |
| Persistence | No | Yes |
| Message ordering | No guarantees | Ordered within topic |
API Reference
pubsub.publish
null on success, ErrorBody on failure
Errors:
topic_not_set- Topic is empty or not provided