Event Adapters

Event adapters connect Rohas to various message brokers and event systems. Adapters handle the pub/sub messaging layer that enables event-driven communication between components.

Overview

Adapters abstract the underlying message broker implementation, allowing you to:

  • Switch between different brokers without code changes
  • Use in-memory adapter for development
  • Use production-grade brokers (Kafka, RabbitMQ, etc.) in production
  • Support multiple adapters for different use cases

Available Adapters

Memory Adapter (Default)

In-memory event bus using Rust's broadcast channels. Perfect for development, testing, and single-instance deployments.

Features:

  • Zero external dependencies
  • Fast in-memory messaging
  • Automatic topic creation
  • Configurable buffer size
  • No persistence (messages lost on restart)

Configuration:

[adapter] type = "memory" buffer_size = 1000 # Maximum messages per topic

Use cases:

  • Local development
  • Testing
  • Single-instance applications
  • Prototyping

Limitations:

  • No persistence
  • Single process only
  • No message durability

NATS Adapter

Connect to NATS messaging system for high-performance, cloud-native event streaming.

Features:

  • High throughput
  • Low latency
  • Clustering support
  • Subject-based routing
  • JetStream for persistence (optional)

Configuration:

[adapter] type = "nats" url = "nats://localhost:4222" # Optional: JetStream configuration jetstream = true

Use cases:

  • Microservices architectures
  • High-throughput systems
  • Cloud-native applications
  • Real-time event streaming

Requirements:

  • NATS server running
  • Network access to NATS server

Kafka Adapter

Connect to Apache Kafka for distributed event streaming at enterprise scale.

Features:

  • Distributed and scalable
  • High durability
  • Partitioning support
  • Consumer groups
  • Exactly-once semantics

Configuration:

[adapter] type = "kafka" brokers = ["localhost:9092"] # Optional: Topic configuration topic_prefix = "rohas"

Use cases:

  • Large-scale event streaming
  • Event sourcing
  • Data pipelines
  • Multi-consumer scenarios

Requirements:

  • Kafka cluster running
  • Network access to brokers

RabbitMQ Adapter

Connect to RabbitMQ message broker for reliable message queuing with advanced routing.

Features:

  • Reliable message delivery
  • Advanced routing (exchanges, queues)
  • Message acknowledgments
  • Dead letter queues
  • Management UI

Configuration:

[adapter] type = "rabbitmq" url = "amqp://guest:guest@localhost:5672" # Optional: Exchange configuration exchange = "rohas_events" exchange_type = "topic"

Use cases:

  • Reliable message delivery
  • Complex routing requirements
  • Traditional message queuing
  • Enterprise integrations

Requirements:

  • RabbitMQ server running
  • Network access to RabbitMQ

AWS SQS Adapter

Connect to Amazon Simple Queue Service for cloud-native message queuing on AWS.

Features:

  • Fully managed service
  • Auto-scaling
  • Dead letter queues
  • Long polling
  • FIFO queues support

Configuration:

[adapter] type = "sqs" region = "us-east-1" # Optional: Queue configuration queue_prefix = "rohas-" fifo = false

Use cases:

  • AWS-native applications
  • Serverless architectures
  • Cloud deployments
  • Managed message queuing

Requirements:

  • AWS account
  • IAM credentials configured
  • Network access to AWS

Configuration

Configure adapters in config/rohas.toml:

[adapter] type = "memory" # or "nats", "kafka", "rabbitmq", "sqs" buffer_size = 1000 # For memory adapter

Adapter-Specific Configuration

Each adapter may have additional configuration options:

NATS:

[adapter] type = "nats" url = "nats://localhost:4222" jetstream = true

Kafka:

[adapter] type = "kafka" brokers = ["localhost:9092"] topic_prefix = "rohas"

RabbitMQ:

[adapter] type = "rabbitmq" url = "amqp://user:pass@localhost:5672" exchange = "rohas_events"

SQS:

pub trait MessageAdapter { async fn publish(&self, topic: &str, payload: Value) -> Result<()>; async fn subscribe(&self, topic: &str, handler: Handler) -> Result<()>; }

Best Practices

  1. Development: Use memory adapter for speed
  2. Testing: Use memory adapter for isolation
  3. Production: Choose based on scale and requirements
  4. Monitoring: Monitor adapter health and message throughput
  5. Error Handling: Configure dead letter queues where supported
  6. Scaling: Consider adapter-specific scaling strategies

Troubleshooting

Memory Adapter

  • Issue: Messages lost on restart
  • Solution: Use persistent adapter for production

NATS/Kafka/RabbitMQ

  • Issue: Connection failures
  • Solution: Check network connectivity and credentials

SQS

  • Issue: Authentication errors
  • Solution: Verify AWS credentials and IAM permissions

Next Steps

  • Learn about Event System
  • Explore Configuration
  • Read Architecture