BunnyFarm¶
Like a well-organized farm where messages hop efficiently from producers to consumers, BunnyFarm provides a lightweight Ruby gem for managing background jobs using RabbitMQ. Each message becomes a living entity with its own behavior, routing intelligently through the message broker to the right workers.
What is BunnyFarm?¶
The bunny farm is an abstraction in which the messages are encapsulated as classes. Instances of these BunnyFarm::Messages are hopping around the RabbitMQ as JSON strings with routing keys in the form of MessageClassName.action
where action is a method on the MessageClassName instance.
Key Features¶
- 🐰 Message-Centric Design - Classes encapsulate behavior and data
- 🔀 Smart Routing - Automatic routing with ClassName.action keys
- 📨 JSON Serialization - Simple, readable message format
- ⚙️ Flexible Configuration - Environment, YAML, or programmatic setup
- 🔄 Workflow Support - Multi-step processes with message chaining
- ⏰ Task Scheduling - Delayed execution with retry logic
- 🛡️ Error Handling - Built-in success/failure tracking
- 🎯 Simplicity First - K.I.S.S. design philosophy
Architecture Overview¶
BunnyFarm provides a clean, layered architecture that separates concerns and enables scalable message processing:
The architecture consists of four main layers:
- Ruby Application Layer - Your web apps, API servers, schedulers, and worker processes
- BunnyFarm Library Layer - Core components including Message classes, Publisher, Consumer, Config, and Router
- RabbitMQ Message Broker - Handles message routing, queuing, and delivery with exchanges and queues
- Persistence & External Services - Databases, email services, file storage, APIs, and caching layers
Quick Start¶
Get up and running with BunnyFarm in minutes:
Installation¶
Add this line to your application's Gemfile:
And then execute:
Basic Usage¶
require 'bunny_farm'
require 'my_message_class'
# Configure BunnyFarm
BunnyFarm.config
# Start processing messages (blocks)
BunnyFarm.manage
Publishing Messages¶
require 'bunny_farm'
BunnyFarm.config do
app_id 'my_job_name'
end
# Create and publish a message
message = MyMessageClass.new
message[:field1] = 'Hello'
message[:field2] = 'World'
message.publish('action') # routing key: MyMessageClass.action
puts 'Success!' if message.successful?
Why BunnyFarm?¶
- Simplistic? Because extensive is sometimes overkill
- JSON? Because binary compression is sometimes overkill
- Bunny? Who doesn't like bunnies? They're like cats with long ears
- AMQP? I like AMQP. I like RabbitMQ as an AMQP broker
BTW, at the farm bunnies grow best if planted ears up. 🐰
What's Next?¶
- Installation Guide - Detailed installation and setup
- Quick Start - Get running in 5 minutes
- Basic Concepts - Understand the fundamentals
- Examples - Comprehensive, runnable examples
- API Reference - Complete API documentation