bunny_farm 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.envrc +1 -0
- data/.github/workflows/docs.yml +38 -0
- data/.gitignore +11 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +61 -0
- data/COMMITS.md +196 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +330 -0
- data/Rakefile +9 -0
- data/bunny_farm.gemspec +30 -0
- data/config/bunny.yml.erb +29 -0
- data/config/bunny_test.yml.erb +29 -0
- data/config/hipchat.yml.erb +12 -0
- data/docs/api/configuration.md +9 -0
- data/docs/api/consumer.md +8 -0
- data/docs/api/message-class.md +419 -0
- data/docs/api/publisher.md +9 -0
- data/docs/architecture/integration.md +8 -0
- data/docs/architecture/message-flow.md +11 -0
- data/docs/architecture/overview.md +448 -0
- data/docs/architecture/scaling.md +8 -0
- data/docs/assets/actions_dsl_flow.svg +109 -0
- data/docs/assets/architecture_overview.svg +152 -0
- data/docs/assets/best_practices_patterns.svg +203 -0
- data/docs/assets/bunny_farm_logo.png +0 -0
- data/docs/assets/configuration_api_methods.svg +104 -0
- data/docs/assets/configuration_flow.svg +130 -0
- data/docs/assets/configuration_hierarchy.svg +70 -0
- data/docs/assets/data_processing_pipeline.svg +131 -0
- data/docs/assets/debugging_monitoring.svg +165 -0
- data/docs/assets/ecommerce_example_flow.svg +145 -0
- data/docs/assets/email_campaign_example.svg +127 -0
- data/docs/assets/environment_variables_map.svg +78 -0
- data/docs/assets/error_handling_flow.svg +114 -0
- data/docs/assets/favicon.ico +1 -0
- data/docs/assets/fields_dsl_structure.svg +89 -0
- data/docs/assets/instance_methods_lifecycle.svg +137 -0
- data/docs/assets/integration_patterns.svg +207 -0
- data/docs/assets/json_serialization_flow.svg +153 -0
- data/docs/assets/logo.svg +4 -0
- data/docs/assets/message_api_overview.svg +126 -0
- data/docs/assets/message_encapsulation.svg +113 -0
- data/docs/assets/message_lifecycle.svg +110 -0
- data/docs/assets/message_structure.svg +138 -0
- data/docs/assets/publisher_consumer_api.svg +120 -0
- data/docs/assets/scaling_deployment_patterns.svg +195 -0
- data/docs/assets/smart_routing_diagram.svg +131 -0
- data/docs/assets/system_architecture_overview.svg +155 -0
- data/docs/assets/task_scheduling_flow.svg +139 -0
- data/docs/assets/testing_strategies.svg +146 -0
- data/docs/assets/workflow_patterns.svg +183 -0
- data/docs/assets/yaml_config_structure.svg +72 -0
- data/docs/configuration/environment-variables.md +14 -0
- data/docs/configuration/overview.md +373 -0
- data/docs/configuration/programmatic-setup.md +10 -0
- data/docs/configuration/yaml-configuration.md +12 -0
- data/docs/core-features/configuration.md +528 -0
- data/docs/core-features/error-handling.md +82 -0
- data/docs/core-features/json-serialization.md +545 -0
- data/docs/core-features/message-design.md +406 -0
- data/docs/core-features/smart-routing.md +467 -0
- data/docs/core-features/task-scheduling.md +67 -0
- data/docs/core-features/workflow-support.md +112 -0
- data/docs/development/contributing.md +345 -0
- data/docs/development/roadmap.md +9 -0
- data/docs/development/testing.md +14 -0
- data/docs/examples/order-processing.md +10 -0
- data/docs/examples/overview.md +269 -0
- data/docs/examples/real-world.md +8 -0
- data/docs/examples/simple-producer-consumer.md +15 -0
- data/docs/examples/task-scheduler.md +9 -0
- data/docs/getting-started/basic-concepts.md +274 -0
- data/docs/getting-started/installation.md +122 -0
- data/docs/getting-started/quick-start.md +158 -0
- data/docs/index.md +106 -0
- data/docs/message-structure/actions-dsl.md +163 -0
- data/docs/message-structure/fields-dsl.md +146 -0
- data/docs/message-structure/instance-methods.md +115 -0
- data/docs/message-structure/overview.md +211 -0
- data/examples/README.md +212 -0
- data/examples/consumer.rb +41 -0
- data/examples/images/message_flow.svg +87 -0
- data/examples/images/order_workflow.svg +122 -0
- data/examples/images/producer_consumer.svg +96 -0
- data/examples/images/task_scheduler.svg +140 -0
- data/examples/order_processor.rb +238 -0
- data/examples/producer.rb +60 -0
- data/examples/simple_message.rb +43 -0
- data/examples/task_scheduler.rb +263 -0
- data/images/architecture_overview.svg +152 -0
- data/images/bunny_farm_logo.png +0 -0
- data/images/configuration_flow.svg +130 -0
- data/images/message_structure.svg +138 -0
- data/lib/bunny_farm/.irbrc +7 -0
- data/lib/bunny_farm/generic_consumer.rb +12 -0
- data/lib/bunny_farm/hash_ext.rb +37 -0
- data/lib/bunny_farm/init_bunny.rb +137 -0
- data/lib/bunny_farm/init_hipchat.rb +49 -0
- data/lib/bunny_farm/message.rb +218 -0
- data/lib/bunny_farm/message_elements.rb +25 -0
- data/lib/bunny_farm/version.rb +3 -0
- data/lib/bunny_farm.rb +9 -0
- data/mkdocs.yml +148 -0
- metadata +244 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# Contributing to BunnyFarm
|
|
2
|
+
|
|
3
|
+
We welcome contributions to BunnyFarm! This guide will help you get started with contributing code, documentation, and other improvements.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Ruby 2.5 or higher
|
|
10
|
+
- RabbitMQ server for testing
|
|
11
|
+
- Git for version control
|
|
12
|
+
- Bundler for dependency management
|
|
13
|
+
|
|
14
|
+
### Setting Up Development Environment
|
|
15
|
+
|
|
16
|
+
1. **Fork the repository** on GitHub
|
|
17
|
+
2. **Clone your fork** locally:
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/YOUR_USERNAME/bunny_farm.git
|
|
20
|
+
cd bunny_farm
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. **Install dependencies**:
|
|
24
|
+
```bash
|
|
25
|
+
bundle install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
4. **Set up RabbitMQ** for testing:
|
|
29
|
+
```bash
|
|
30
|
+
# macOS with Homebrew
|
|
31
|
+
brew install rabbitmq
|
|
32
|
+
brew services start rabbitmq
|
|
33
|
+
|
|
34
|
+
# Ubuntu/Debian
|
|
35
|
+
sudo apt-get install rabbitmq-server
|
|
36
|
+
sudo systemctl start rabbitmq-server
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
5. **Run the tests** to ensure everything works:
|
|
40
|
+
```bash
|
|
41
|
+
bundle exec rake test
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Development Philosophy
|
|
45
|
+
|
|
46
|
+
BunnyFarm follows the **K.I.S.S. (Keep It Simple, Stupid)** design principle:
|
|
47
|
+
|
|
48
|
+
- **Simplicity over complexity** - Choose simple solutions over elaborate ones
|
|
49
|
+
- **Clarity over cleverness** - Write code that's easy to understand
|
|
50
|
+
- **Convention over configuration** - Provide sensible defaults
|
|
51
|
+
- **Edge cases are not priorities** - Focus on common use cases
|
|
52
|
+
|
|
53
|
+
## Code Style Guidelines
|
|
54
|
+
|
|
55
|
+
### Ruby Style
|
|
56
|
+
|
|
57
|
+
Follow standard Ruby conventions:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
# Good: Clear, descriptive names
|
|
61
|
+
class OrderProcessingMessage < BunnyFarm::Message
|
|
62
|
+
fields :order_id, :customer_email, :items
|
|
63
|
+
actions :validate, :process, :ship
|
|
64
|
+
|
|
65
|
+
def validate
|
|
66
|
+
validate_order_data
|
|
67
|
+
validate_customer_info
|
|
68
|
+
success! if errors.empty?
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Avoid: Unclear or overly clever code
|
|
73
|
+
class OPM < BF::Msg
|
|
74
|
+
flds :oid, :ce, :its
|
|
75
|
+
acts :v, :p, :s
|
|
76
|
+
|
|
77
|
+
def v; vod; vci; suc! if ers.empty?; end
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Documentation Style
|
|
82
|
+
|
|
83
|
+
- **Clear examples** - Provide runnable code examples
|
|
84
|
+
- **Practical focus** - Show real-world usage patterns
|
|
85
|
+
- **Progressive complexity** - Start simple, build up
|
|
86
|
+
- **Consistent format** - Follow established patterns
|
|
87
|
+
|
|
88
|
+
## Types of Contributions
|
|
89
|
+
|
|
90
|
+
### 🐛 Bug Fixes
|
|
91
|
+
|
|
92
|
+
Found a bug? We'd love your help fixing it!
|
|
93
|
+
|
|
94
|
+
1. **Search existing issues** to avoid duplicates
|
|
95
|
+
2. **Create an issue** describing the bug with:
|
|
96
|
+
- Ruby version
|
|
97
|
+
- BunnyFarm version
|
|
98
|
+
- RabbitMQ version
|
|
99
|
+
- Minimal reproduction case
|
|
100
|
+
- Expected vs actual behavior
|
|
101
|
+
3. **Submit a pull request** with the fix
|
|
102
|
+
|
|
103
|
+
### ✨ Feature Additions
|
|
104
|
+
|
|
105
|
+
Have an idea for a new feature?
|
|
106
|
+
|
|
107
|
+
1. **Discuss first** - Open an issue to discuss the feature
|
|
108
|
+
2. **Keep it simple** - Align with BunnyFarm's philosophy
|
|
109
|
+
3. **Consider the common case** - Focus on widely useful features
|
|
110
|
+
4. **Include tests** - New features need test coverage
|
|
111
|
+
5. **Update documentation** - Include usage examples
|
|
112
|
+
|
|
113
|
+
### 📚 Documentation Improvements
|
|
114
|
+
|
|
115
|
+
Documentation improvements are always welcome:
|
|
116
|
+
|
|
117
|
+
- Fix typos and grammar
|
|
118
|
+
- Add missing examples
|
|
119
|
+
- Clarify confusing sections
|
|
120
|
+
- Create new guides and tutorials
|
|
121
|
+
- Update API documentation
|
|
122
|
+
|
|
123
|
+
### 🧪 Testing Enhancements
|
|
124
|
+
|
|
125
|
+
Help improve test coverage:
|
|
126
|
+
|
|
127
|
+
- Add missing test cases
|
|
128
|
+
- Improve test reliability
|
|
129
|
+
- Add integration tests
|
|
130
|
+
- Performance testing
|
|
131
|
+
- Cross-platform testing
|
|
132
|
+
|
|
133
|
+
## Pull Request Process
|
|
134
|
+
|
|
135
|
+
### Before Submitting
|
|
136
|
+
|
|
137
|
+
1. **Run the tests**:
|
|
138
|
+
```bash
|
|
139
|
+
bundle exec rake test
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
2. **Check code style**:
|
|
143
|
+
```bash
|
|
144
|
+
bundle exec rubocop
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. **Update documentation** if needed
|
|
148
|
+
|
|
149
|
+
4. **Add tests** for new functionality
|
|
150
|
+
|
|
151
|
+
### Submitting Your PR
|
|
152
|
+
|
|
153
|
+
1. **Create a feature branch**:
|
|
154
|
+
```bash
|
|
155
|
+
git checkout -b feature/your-feature-name
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
2. **Make your changes** with clear, atomic commits:
|
|
159
|
+
```bash
|
|
160
|
+
git commit -m "Add message retry functionality"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
3. **Push to your fork**:
|
|
164
|
+
```bash
|
|
165
|
+
git push origin feature/your-feature-name
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
4. **Create a pull request** with:
|
|
169
|
+
- Clear title describing the change
|
|
170
|
+
- Detailed description of what was changed and why
|
|
171
|
+
- Link to related issues
|
|
172
|
+
- Screenshots/examples if applicable
|
|
173
|
+
|
|
174
|
+
### PR Review Process
|
|
175
|
+
|
|
176
|
+
1. **Automated checks** run (tests, style, etc.)
|
|
177
|
+
2. **Maintainer review** - We'll provide feedback
|
|
178
|
+
3. **Address feedback** - Make requested changes
|
|
179
|
+
4. **Final review** - Maintainer approval
|
|
180
|
+
5. **Merge** - Your contribution is included!
|
|
181
|
+
|
|
182
|
+
## Testing Guidelines
|
|
183
|
+
|
|
184
|
+
### Writing Tests
|
|
185
|
+
|
|
186
|
+
BunnyFarm uses Minitest for testing. Follow these patterns:
|
|
187
|
+
|
|
188
|
+
```ruby
|
|
189
|
+
# test/test_your_feature.rb
|
|
190
|
+
require 'minitest_helper'
|
|
191
|
+
|
|
192
|
+
class TestYourFeature < Minitest::Test
|
|
193
|
+
def setup
|
|
194
|
+
@message = TestMessage.new
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_basic_functionality
|
|
198
|
+
@message[:field] = 'value'
|
|
199
|
+
@message.your_action
|
|
200
|
+
|
|
201
|
+
assert @message.successful?
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def test_error_handling
|
|
205
|
+
@message[:field] = nil # Invalid value
|
|
206
|
+
@message.your_action
|
|
207
|
+
|
|
208
|
+
assert @message.failed?
|
|
209
|
+
assert_includes @message.errors, 'Field is required'
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Test Organization
|
|
215
|
+
|
|
216
|
+
- **Unit tests** - Test individual methods and classes
|
|
217
|
+
- **Integration tests** - Test end-to-end message flows
|
|
218
|
+
- **Performance tests** - Verify performance characteristics
|
|
219
|
+
- **Edge case tests** - Test boundary conditions
|
|
220
|
+
|
|
221
|
+
### Running Tests
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Run all tests
|
|
225
|
+
bundle exec rake test
|
|
226
|
+
|
|
227
|
+
# Run specific test file
|
|
228
|
+
bundle exec ruby test/test_message.rb
|
|
229
|
+
|
|
230
|
+
# Run specific test method
|
|
231
|
+
bundle exec ruby test/test_message.rb -n test_basic_functionality
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Issue Reporting
|
|
235
|
+
|
|
236
|
+
### Bug Reports
|
|
237
|
+
|
|
238
|
+
When reporting bugs, include:
|
|
239
|
+
|
|
240
|
+
```markdown
|
|
241
|
+
**Bug Description**
|
|
242
|
+
Clear description of the bug
|
|
243
|
+
|
|
244
|
+
**Environment**
|
|
245
|
+
- Ruby version: X.X.X
|
|
246
|
+
- BunnyFarm version: X.X.X
|
|
247
|
+
- RabbitMQ version: X.X.X
|
|
248
|
+
- OS: macOS/Linux/Windows
|
|
249
|
+
|
|
250
|
+
**Reproduction Steps**
|
|
251
|
+
1. Step one
|
|
252
|
+
2. Step two
|
|
253
|
+
3. Bug occurs
|
|
254
|
+
|
|
255
|
+
**Expected Behavior**
|
|
256
|
+
What should happen
|
|
257
|
+
|
|
258
|
+
**Actual Behavior**
|
|
259
|
+
What actually happens
|
|
260
|
+
|
|
261
|
+
**Minimal Code Example**
|
|
262
|
+
```ruby
|
|
263
|
+
# Code that reproduces the bug
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Feature Requests
|
|
267
|
+
|
|
268
|
+
For feature requests, provide:
|
|
269
|
+
|
|
270
|
+
- **Use case** - What problem does this solve?
|
|
271
|
+
- **Proposed solution** - How should it work?
|
|
272
|
+
- **Alternatives considered** - What other approaches did you consider?
|
|
273
|
+
- **Examples** - Show how it would be used
|
|
274
|
+
|
|
275
|
+
## Code Review Guidelines
|
|
276
|
+
|
|
277
|
+
### For Contributors
|
|
278
|
+
|
|
279
|
+
- **Keep PRs focused** - One feature/fix per PR
|
|
280
|
+
- **Write clear commit messages** - Explain what and why
|
|
281
|
+
- **Be responsive** - Address feedback promptly
|
|
282
|
+
- **Test thoroughly** - Ensure changes work correctly
|
|
283
|
+
|
|
284
|
+
### For Reviewers
|
|
285
|
+
|
|
286
|
+
- **Be constructive** - Provide helpful feedback
|
|
287
|
+
- **Focus on the code** - Not the person
|
|
288
|
+
- **Explain reasoning** - Help contributors learn
|
|
289
|
+
- **Recognize good work** - Acknowledge quality contributions
|
|
290
|
+
|
|
291
|
+
## Release Process
|
|
292
|
+
|
|
293
|
+
BunnyFarm follows semantic versioning:
|
|
294
|
+
|
|
295
|
+
- **Major version** (X.0.0) - Breaking changes
|
|
296
|
+
- **Minor version** (0.X.0) - New features, backwards compatible
|
|
297
|
+
- **Patch version** (0.0.X) - Bug fixes, backwards compatible
|
|
298
|
+
|
|
299
|
+
### Release Criteria
|
|
300
|
+
|
|
301
|
+
- All tests passing
|
|
302
|
+
- Documentation updated
|
|
303
|
+
- CHANGELOG.md updated
|
|
304
|
+
- Version number updated
|
|
305
|
+
|
|
306
|
+
## Community Guidelines
|
|
307
|
+
|
|
308
|
+
### Be Respectful
|
|
309
|
+
|
|
310
|
+
- **Inclusive environment** - Welcome contributors of all backgrounds
|
|
311
|
+
- **Professional communication** - Keep discussions constructive
|
|
312
|
+
- **Patient teaching** - Help newcomers learn
|
|
313
|
+
|
|
314
|
+
### Be Helpful
|
|
315
|
+
|
|
316
|
+
- **Answer questions** - Help other users and contributors
|
|
317
|
+
- **Share knowledge** - Contribute to discussions
|
|
318
|
+
- **Mentor newcomers** - Guide new contributors
|
|
319
|
+
|
|
320
|
+
## Getting Help
|
|
321
|
+
|
|
322
|
+
Need help contributing? Reach out:
|
|
323
|
+
|
|
324
|
+
- **GitHub Issues** - For bugs and feature requests
|
|
325
|
+
- **GitHub Discussions** - For questions and general discussion
|
|
326
|
+
- **Pull Request Comments** - For specific code feedback
|
|
327
|
+
|
|
328
|
+
## Recognition
|
|
329
|
+
|
|
330
|
+
Contributors are recognized in:
|
|
331
|
+
|
|
332
|
+
- **CHANGELOG.md** - For significant contributions
|
|
333
|
+
- **README.md** - In the contributors section
|
|
334
|
+
- **Release notes** - For notable features and fixes
|
|
335
|
+
|
|
336
|
+
## Next Steps
|
|
337
|
+
|
|
338
|
+
Ready to contribute?
|
|
339
|
+
|
|
340
|
+
1. **Browse open issues** - Find something to work on
|
|
341
|
+
2. **Join discussions** - Participate in the community
|
|
342
|
+
3. **Start small** - Begin with documentation or small bug fixes
|
|
343
|
+
4. **Ask questions** - Don't hesitate to ask for help
|
|
344
|
+
|
|
345
|
+
Thank you for contributing to BunnyFarm! 🐰
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
Testing strategies for BunnyFarm applications.
|
|
4
|
+
|
|
5
|
+
## Unit Testing
|
|
6
|
+
```ruby
|
|
7
|
+
class TestOrderMessage < Minitest::Test
|
|
8
|
+
def test_validation
|
|
9
|
+
message = OrderMessage.new
|
|
10
|
+
message.validate
|
|
11
|
+
assert message.successful?
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
```
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Examples Overview
|
|
2
|
+
|
|
3
|
+
This section provides comprehensive, runnable examples that demonstrate BunnyFarm's capabilities. Each example includes complete code, setup instructions, and explanation of concepts.
|
|
4
|
+
|
|
5
|
+
## Available Examples
|
|
6
|
+
|
|
7
|
+
### 🚀 [Simple Producer/Consumer](simple-producer-consumer.md)
|
|
8
|
+
Perfect for getting started. Shows the basic patterns of message creation, publishing, and consumption.
|
|
9
|
+
|
|
10
|
+
**What you'll learn:**
|
|
11
|
+
- Basic message class creation
|
|
12
|
+
- Publishing messages
|
|
13
|
+
- Setting up consumers
|
|
14
|
+
- Message routing
|
|
15
|
+
|
|
16
|
+
**Use cases:**
|
|
17
|
+
- Background job processing
|
|
18
|
+
- Simple task queues
|
|
19
|
+
- Event notifications
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### 📦 [Order Processing Workflow](order-processing.md)
|
|
24
|
+
A comprehensive e-commerce order processing system with multiple steps, error handling, and workflow management.
|
|
25
|
+
|
|
26
|
+
**What you'll learn:**
|
|
27
|
+
- Complex message workflows
|
|
28
|
+
- Multi-step processing
|
|
29
|
+
- Error handling and recovery
|
|
30
|
+
- State transitions
|
|
31
|
+
- Success/failure tracking
|
|
32
|
+
|
|
33
|
+
**Use cases:**
|
|
34
|
+
- E-commerce order processing
|
|
35
|
+
- Multi-step business workflows
|
|
36
|
+
- Complex validation chains
|
|
37
|
+
- Payment processing
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
### ⏰ [Task Scheduler](task-scheduler.md)
|
|
42
|
+
Advanced example showing scheduled task execution, retry logic, and failure recovery patterns.
|
|
43
|
+
|
|
44
|
+
**What you'll learn:**
|
|
45
|
+
- Delayed message processing
|
|
46
|
+
- Retry mechanisms with exponential backoff
|
|
47
|
+
- Dead letter queue handling
|
|
48
|
+
- Monitoring and alerting
|
|
49
|
+
- Batch processing
|
|
50
|
+
|
|
51
|
+
**Use cases:**
|
|
52
|
+
- Scheduled report generation
|
|
53
|
+
- Recurring maintenance tasks
|
|
54
|
+
- Email campaigns
|
|
55
|
+
- Data synchronization
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### 🌍 [Real World Examples](real-world.md)
|
|
60
|
+
Production-ready examples from real applications showing advanced patterns and best practices.
|
|
61
|
+
|
|
62
|
+
**What you'll learn:**
|
|
63
|
+
- Production configuration
|
|
64
|
+
- Monitoring and logging
|
|
65
|
+
- Performance optimization
|
|
66
|
+
- Error tracking
|
|
67
|
+
- Deployment patterns
|
|
68
|
+
|
|
69
|
+
**Use cases:**
|
|
70
|
+
- Microservice communication
|
|
71
|
+
- Event-driven architecture
|
|
72
|
+
- Data pipeline processing
|
|
73
|
+
- System integration
|
|
74
|
+
|
|
75
|
+
## Getting Started with Examples
|
|
76
|
+
|
|
77
|
+
### Prerequisites
|
|
78
|
+
|
|
79
|
+
Before running any examples, ensure you have:
|
|
80
|
+
|
|
81
|
+
1. **BunnyFarm installed**: `gem install bunny_farm`
|
|
82
|
+
2. **RabbitMQ running**: Local or remote instance
|
|
83
|
+
3. **Ruby 2.5+**: Compatible Ruby version
|
|
84
|
+
|
|
85
|
+
### Environment Setup
|
|
86
|
+
|
|
87
|
+
Set up your environment variables:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
export AMQP_HOST=localhost
|
|
91
|
+
export AMQP_VHOST=/
|
|
92
|
+
export AMQP_PORT=5672
|
|
93
|
+
export AMQP_USER=guest
|
|
94
|
+
export AMQP_PASS=guest
|
|
95
|
+
export AMQP_EXCHANGE=bunny_farm_examples
|
|
96
|
+
export AMQP_QUEUE=example_queue
|
|
97
|
+
export AMQP_ROUTING_KEY='#'
|
|
98
|
+
export AMQP_APP_NAME=example_app
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Running Examples
|
|
102
|
+
|
|
103
|
+
Each example includes:
|
|
104
|
+
|
|
105
|
+
1. **Complete source code** - Copy-paste ready
|
|
106
|
+
2. **Setup instructions** - Step-by-step guide
|
|
107
|
+
3. **Expected output** - What you should see
|
|
108
|
+
4. **Troubleshooting** - Common issues and solutions
|
|
109
|
+
5. **Variations** - Alternative implementations
|
|
110
|
+
|
|
111
|
+
## Example Structure
|
|
112
|
+
|
|
113
|
+
All examples follow a consistent structure:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
example_name/
|
|
117
|
+
├── README.md # Setup and usage instructions
|
|
118
|
+
├── message_class.rb # Message definition
|
|
119
|
+
├── producer.rb # Message publisher
|
|
120
|
+
├── consumer.rb # Message processor
|
|
121
|
+
└── config.rb # Configuration (if needed)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Architecture Patterns
|
|
125
|
+
|
|
126
|
+
The examples demonstrate key architectural patterns:
|
|
127
|
+
|
|
128
|
+
### Producer-Consumer Pattern
|
|
129
|
+
```ruby
|
|
130
|
+
# Producer
|
|
131
|
+
message = OrderMessage.new
|
|
132
|
+
message[:order_id] = 12345
|
|
133
|
+
message.publish('process')
|
|
134
|
+
|
|
135
|
+
# Consumer
|
|
136
|
+
BunnyFarm.manage # Process incoming messages
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Workflow Pattern
|
|
140
|
+
```ruby
|
|
141
|
+
def process_order
|
|
142
|
+
validate_order
|
|
143
|
+
return unless successful?
|
|
144
|
+
|
|
145
|
+
charge_payment
|
|
146
|
+
return unless successful?
|
|
147
|
+
|
|
148
|
+
ship_order
|
|
149
|
+
return unless successful?
|
|
150
|
+
|
|
151
|
+
send_confirmation
|
|
152
|
+
end
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Retry Pattern
|
|
156
|
+
```ruby
|
|
157
|
+
def risky_operation
|
|
158
|
+
retries = 0
|
|
159
|
+
begin
|
|
160
|
+
perform_operation
|
|
161
|
+
success!
|
|
162
|
+
rescue => e
|
|
163
|
+
retries += 1
|
|
164
|
+
if retries < 3
|
|
165
|
+
sleep(2 ** retries) # Exponential backoff
|
|
166
|
+
retry
|
|
167
|
+
else
|
|
168
|
+
failure("Failed after 3 attempts: #{e.message}")
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Testing Examples
|
|
175
|
+
|
|
176
|
+
Each example includes test scenarios:
|
|
177
|
+
|
|
178
|
+
### Unit Testing
|
|
179
|
+
```ruby
|
|
180
|
+
# Test message behavior
|
|
181
|
+
message = OrderMessage.new
|
|
182
|
+
message[:order_id] = 123
|
|
183
|
+
message.validate_order
|
|
184
|
+
|
|
185
|
+
assert message.successful?
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Integration Testing
|
|
189
|
+
```ruby
|
|
190
|
+
# Test end-to-end flow
|
|
191
|
+
producer.publish_order(order_data)
|
|
192
|
+
consumer.process_next_message
|
|
193
|
+
assert_order_processed(order_data[:id])
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Common Patterns
|
|
197
|
+
|
|
198
|
+
### Configuration Management
|
|
199
|
+
```ruby
|
|
200
|
+
BunnyFarm.config do
|
|
201
|
+
case ENV['RAILS_ENV']
|
|
202
|
+
when 'production'
|
|
203
|
+
env 'production'
|
|
204
|
+
bunny_file 'config/rabbitmq.yml'
|
|
205
|
+
when 'development'
|
|
206
|
+
# Use defaults
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Error Handling
|
|
212
|
+
```ruby
|
|
213
|
+
def safe_operation
|
|
214
|
+
begin
|
|
215
|
+
risky_work
|
|
216
|
+
success!
|
|
217
|
+
rescue SpecificError => e
|
|
218
|
+
failure("Known issue: #{e.message}")
|
|
219
|
+
rescue StandardError => e
|
|
220
|
+
failure("Unexpected error: #{e.message}")
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
successful?
|
|
224
|
+
end
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Logging and Monitoring
|
|
228
|
+
```ruby
|
|
229
|
+
def tracked_operation
|
|
230
|
+
Rails.logger.info "Starting operation for #{@items[:id]}"
|
|
231
|
+
|
|
232
|
+
result = perform_operation
|
|
233
|
+
|
|
234
|
+
if successful?
|
|
235
|
+
Rails.logger.info "Operation completed successfully"
|
|
236
|
+
else
|
|
237
|
+
Rails.logger.error "Operation failed: #{errors.join(', ')}"
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
result
|
|
241
|
+
end
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Performance Considerations
|
|
245
|
+
|
|
246
|
+
The examples include performance best practices:
|
|
247
|
+
|
|
248
|
+
- **Connection pooling** for high-throughput scenarios
|
|
249
|
+
- **Batch processing** for efficiency
|
|
250
|
+
- **Memory management** for long-running consumers
|
|
251
|
+
- **Queue configuration** for optimal performance
|
|
252
|
+
|
|
253
|
+
## Deployment Examples
|
|
254
|
+
|
|
255
|
+
Learn how to deploy BunnyFarm applications:
|
|
256
|
+
|
|
257
|
+
- **Docker containers** with proper configuration
|
|
258
|
+
- **Kubernetes** deployment manifests
|
|
259
|
+
- **Systemd services** for traditional servers
|
|
260
|
+
- **Cloud deployment** patterns
|
|
261
|
+
|
|
262
|
+
## Next Steps
|
|
263
|
+
|
|
264
|
+
Choose an example that matches your use case:
|
|
265
|
+
|
|
266
|
+
- **New to BunnyFarm?** Start with [Simple Producer/Consumer](simple-producer-consumer.md)
|
|
267
|
+
- **Building workflows?** Check out [Order Processing](order-processing.md)
|
|
268
|
+
- **Need scheduling?** See [Task Scheduler](task-scheduler.md)
|
|
269
|
+
- **Going to production?** Review [Real World Examples](real-world.md)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Simple Producer/Consumer
|
|
2
|
+
|
|
3
|
+
Basic example showing message publishing and consumption.
|
|
4
|
+
|
|
5
|
+
## Producer
|
|
6
|
+
```ruby
|
|
7
|
+
message = GreetingMessage.new
|
|
8
|
+
message[:name] = 'World'
|
|
9
|
+
message.publish('greet')
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Consumer
|
|
13
|
+
```ruby
|
|
14
|
+
BunnyFarm.manage
|
|
15
|
+
```
|