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.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +1 -0
  3. data/.github/workflows/docs.yml +38 -0
  4. data/.gitignore +11 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.md +61 -0
  7. data/COMMITS.md +196 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +330 -0
  11. data/Rakefile +9 -0
  12. data/bunny_farm.gemspec +30 -0
  13. data/config/bunny.yml.erb +29 -0
  14. data/config/bunny_test.yml.erb +29 -0
  15. data/config/hipchat.yml.erb +12 -0
  16. data/docs/api/configuration.md +9 -0
  17. data/docs/api/consumer.md +8 -0
  18. data/docs/api/message-class.md +419 -0
  19. data/docs/api/publisher.md +9 -0
  20. data/docs/architecture/integration.md +8 -0
  21. data/docs/architecture/message-flow.md +11 -0
  22. data/docs/architecture/overview.md +448 -0
  23. data/docs/architecture/scaling.md +8 -0
  24. data/docs/assets/actions_dsl_flow.svg +109 -0
  25. data/docs/assets/architecture_overview.svg +152 -0
  26. data/docs/assets/best_practices_patterns.svg +203 -0
  27. data/docs/assets/bunny_farm_logo.png +0 -0
  28. data/docs/assets/configuration_api_methods.svg +104 -0
  29. data/docs/assets/configuration_flow.svg +130 -0
  30. data/docs/assets/configuration_hierarchy.svg +70 -0
  31. data/docs/assets/data_processing_pipeline.svg +131 -0
  32. data/docs/assets/debugging_monitoring.svg +165 -0
  33. data/docs/assets/ecommerce_example_flow.svg +145 -0
  34. data/docs/assets/email_campaign_example.svg +127 -0
  35. data/docs/assets/environment_variables_map.svg +78 -0
  36. data/docs/assets/error_handling_flow.svg +114 -0
  37. data/docs/assets/favicon.ico +1 -0
  38. data/docs/assets/fields_dsl_structure.svg +89 -0
  39. data/docs/assets/instance_methods_lifecycle.svg +137 -0
  40. data/docs/assets/integration_patterns.svg +207 -0
  41. data/docs/assets/json_serialization_flow.svg +153 -0
  42. data/docs/assets/logo.svg +4 -0
  43. data/docs/assets/message_api_overview.svg +126 -0
  44. data/docs/assets/message_encapsulation.svg +113 -0
  45. data/docs/assets/message_lifecycle.svg +110 -0
  46. data/docs/assets/message_structure.svg +138 -0
  47. data/docs/assets/publisher_consumer_api.svg +120 -0
  48. data/docs/assets/scaling_deployment_patterns.svg +195 -0
  49. data/docs/assets/smart_routing_diagram.svg +131 -0
  50. data/docs/assets/system_architecture_overview.svg +155 -0
  51. data/docs/assets/task_scheduling_flow.svg +139 -0
  52. data/docs/assets/testing_strategies.svg +146 -0
  53. data/docs/assets/workflow_patterns.svg +183 -0
  54. data/docs/assets/yaml_config_structure.svg +72 -0
  55. data/docs/configuration/environment-variables.md +14 -0
  56. data/docs/configuration/overview.md +373 -0
  57. data/docs/configuration/programmatic-setup.md +10 -0
  58. data/docs/configuration/yaml-configuration.md +12 -0
  59. data/docs/core-features/configuration.md +528 -0
  60. data/docs/core-features/error-handling.md +82 -0
  61. data/docs/core-features/json-serialization.md +545 -0
  62. data/docs/core-features/message-design.md +406 -0
  63. data/docs/core-features/smart-routing.md +467 -0
  64. data/docs/core-features/task-scheduling.md +67 -0
  65. data/docs/core-features/workflow-support.md +112 -0
  66. data/docs/development/contributing.md +345 -0
  67. data/docs/development/roadmap.md +9 -0
  68. data/docs/development/testing.md +14 -0
  69. data/docs/examples/order-processing.md +10 -0
  70. data/docs/examples/overview.md +269 -0
  71. data/docs/examples/real-world.md +8 -0
  72. data/docs/examples/simple-producer-consumer.md +15 -0
  73. data/docs/examples/task-scheduler.md +9 -0
  74. data/docs/getting-started/basic-concepts.md +274 -0
  75. data/docs/getting-started/installation.md +122 -0
  76. data/docs/getting-started/quick-start.md +158 -0
  77. data/docs/index.md +106 -0
  78. data/docs/message-structure/actions-dsl.md +163 -0
  79. data/docs/message-structure/fields-dsl.md +146 -0
  80. data/docs/message-structure/instance-methods.md +115 -0
  81. data/docs/message-structure/overview.md +211 -0
  82. data/examples/README.md +212 -0
  83. data/examples/consumer.rb +41 -0
  84. data/examples/images/message_flow.svg +87 -0
  85. data/examples/images/order_workflow.svg +122 -0
  86. data/examples/images/producer_consumer.svg +96 -0
  87. data/examples/images/task_scheduler.svg +140 -0
  88. data/examples/order_processor.rb +238 -0
  89. data/examples/producer.rb +60 -0
  90. data/examples/simple_message.rb +43 -0
  91. data/examples/task_scheduler.rb +263 -0
  92. data/images/architecture_overview.svg +152 -0
  93. data/images/bunny_farm_logo.png +0 -0
  94. data/images/configuration_flow.svg +130 -0
  95. data/images/message_structure.svg +138 -0
  96. data/lib/bunny_farm/.irbrc +7 -0
  97. data/lib/bunny_farm/generic_consumer.rb +12 -0
  98. data/lib/bunny_farm/hash_ext.rb +37 -0
  99. data/lib/bunny_farm/init_bunny.rb +137 -0
  100. data/lib/bunny_farm/init_hipchat.rb +49 -0
  101. data/lib/bunny_farm/message.rb +218 -0
  102. data/lib/bunny_farm/message_elements.rb +25 -0
  103. data/lib/bunny_farm/version.rb +3 -0
  104. data/lib/bunny_farm.rb +9 -0
  105. data/mkdocs.yml +148 -0
  106. metadata +244 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dce4a5a279e75daa093483da57a1606a4c1afc242bc95914d8536988a2d9d4b8
4
+ data.tar.gz: 81b2823ea910eb4aac39027b77c55ecf69ff2c37d0f905a57f3d8260df3bad67
5
+ SHA512:
6
+ metadata.gz: b7aae736d022ed6713a041c02c8d0ca713bbedb16f746d8eeb80eb87f3ae9673e64120ae0692d1e468ae5547eaea3ad4138f1f2af0a58d6d1f16e520fbec03c2
7
+ data.tar.gz: 6ee8229cee9771ba0ceeb7786e6c505fce96f15c71c6533892b25ba3cffe4632f5f59b711a66038fabc38359b20477dd12630b3454181a3f8575ccc0a0ac3ede
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ export RR=`pwd`
@@ -0,0 +1,38 @@
1
+ name: Deploy Documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - "docs/**"
9
+ - "mkdocs.yml"
10
+ - ".github/workflows/docs.yml"
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: write
15
+ pages: write
16
+ id-token: write
17
+
18
+ jobs:
19
+ deploy:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - name: Checkout repository
23
+ uses: actions/checkout@v4
24
+ with:
25
+ fetch-depth: 0
26
+
27
+ - name: Set up Python
28
+ uses: actions/setup-python@v4
29
+ with:
30
+ python-version: "3.11"
31
+
32
+ - name: Install Python dependencies
33
+ run: |
34
+ python -m pip install --upgrade pip
35
+ pip install mkdocs-material mkdocs-minify-plugin
36
+
37
+ - name: Deploy to GitHub Pages
38
+ run: mkdocs gh-deploy --force
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ site
11
+ .aigcm_msg
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [Released]
11
+
12
+ ### [v0.1.2] - 2025-09-02
13
+
14
+ #### Added
15
+ - Comprehensive documentation website with MkDocs
16
+ - 26 interactive SVG diagrams illustrating core concepts
17
+ - GitHub Actions CI/CD pipeline for documentation deployment
18
+ - Complete API reference documentation
19
+ - Getting started guide with examples
20
+ - Core features documentation (error handling, task scheduling, workflow support)
21
+ - Configuration management documentation
22
+ - Development and testing guides
23
+ - Architecture overview diagrams
24
+
25
+ #### Fixed
26
+ - XML parsing issues in SVG diagrams (unescaped ampersands and angle brackets)
27
+ - Documentation build warnings for missing files
28
+ - Improved visual consistency across all diagrams
29
+
30
+ #### Changed
31
+ - Enhanced documentation structure and navigation
32
+ - Updated configuration examples for better clarity
33
+ - Improved code examples throughout documentation
34
+
35
+ ### [v0.1.1] - 2016-06-30
36
+
37
+ #### Added
38
+ - Initial BunnyFarm message processing framework
39
+ - Message DSL for defining fields and actions
40
+ - RabbitMQ integration with smart routing
41
+ - JSON serialization support
42
+ - Basic error handling and retry mechanisms
43
+ - Configuration management system
44
+ - Core message lifecycle management
45
+ - Publishing and consuming capabilities
46
+
47
+ #### Fixed
48
+ - Basic message routing functionality
49
+ - Connection handling improvements
50
+ - Error propagation in message processing
51
+
52
+ #### Security
53
+ - Secure configuration handling for RabbitMQ credentials
54
+
55
+ ### [v0.1.0] - 2015-02-21
56
+
57
+ #### Added
58
+ - Initial project structure
59
+ - Basic message framework foundation
60
+ - Core library architecture
61
+ - Initial RabbitMQ integration prototype
data/COMMITS.md ADDED
@@ -0,0 +1,196 @@
1
+ ---
2
+ url: https://www.conventionalcommits.org/en/v1.0.0/
3
+ title: Conventional Commits
4
+ description: A specification for adding human and machine readable meaning to commit messages
5
+ access_date: 2025-07-31T20:51:29.000Z
6
+ current_date: 2025-07-31T20:51:29.601Z
7
+ ---
8
+
9
+ # Conventional Commits
10
+
11
+ A specification for adding human and machine readable meaning to commit messages
12
+
13
+ Quick Summary Full Specification Contribute
14
+
15
+ # Conventional Commits 1.0.0
16
+
17
+ ## Summary
18
+
19
+ The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
20
+
21
+ The commit message should be structured as follows:
22
+
23
+ ---
24
+
25
+ ```
26
+ <type>[optional scope]: <description>
27
+
28
+ [optional body]
29
+
30
+ [optional footer(s)]
31
+
32
+ ```
33
+
34
+ ---
35
+
36
+ The commit contains the following structural elements, to communicate intent to the consumers of your library:
37
+
38
+ 1. **fix:** a commit of the _type_ `fix` patches a bug in your codebase (this correlates with `PATCH` in Semantic Versioning).
39
+ 2. **feat:** a commit of the _type_ `feat` introduces a new feature to the codebase (this correlates with `MINOR` in Semantic Versioning).
40
+ 3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:`, or appends a `!` after the type/scope, introduces a breaking API change (correlating with `MAJOR` in Semantic Versioning). A BREAKING CHANGE can be part of commits of any _type_.
41
+ 4. _types_ other than `fix:` and `feat:` are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends `build:`, `chore:`,`ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others.
42
+ 5. _footers_ other than `BREAKING CHANGE: <description>` may be provided and follow a convention similar to git trailer format.
43
+
44
+ Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.
45
+
46
+ ## Examples
47
+
48
+ ### Commit message with description and breaking change footer
49
+
50
+ ```
51
+ feat: allow provided config object to extend other configs
52
+
53
+ BREAKING CHANGE: `extends` key in config file is now used for extending other config files
54
+
55
+ ```
56
+
57
+ ### Commit message with `!` to draw attention to breaking change
58
+
59
+ ```
60
+ feat!: send an email to the customer when a product is shipped
61
+
62
+ ```
63
+
64
+ ### Commit message with scope and `!` to draw attention to breaking change
65
+
66
+ ```
67
+ feat(api)!: send an email to the customer when a product is shipped
68
+
69
+ ```
70
+
71
+ ### Commit message with both `!` and BREAKING CHANGE footer
72
+
73
+ ```
74
+ chore!: drop support for Node 6
75
+
76
+ BREAKING CHANGE: use JavaScript features not available in Node 6.
77
+
78
+ ```
79
+
80
+ ### Commit message with no body
81
+
82
+ ```
83
+ docs: correct spelling of CHANGELOG
84
+
85
+ ```
86
+
87
+ ### Commit message with scope
88
+
89
+ ```
90
+ feat(lang): add Polish language
91
+
92
+ ```
93
+
94
+ ### Commit message with multi-paragraph body and multiple footers
95
+
96
+ ```
97
+ fix: prevent racing of requests
98
+
99
+ Introduce a request id and a reference to latest request. Dismiss
100
+ incoming responses other than from latest request.
101
+
102
+ Remove timeouts which were used to mitigate the racing issue but are
103
+ obsolete now.
104
+
105
+ Reviewed-by: Z
106
+ Refs: #123
107
+
108
+ ```
109
+
110
+ ## Specification
111
+
112
+ The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
113
+
114
+ 1. Commits MUST be prefixed with a type, which consists of a noun, `feat`, `fix`, etc., followed by the OPTIONAL scope, OPTIONAL `!`, and REQUIRED terminal colon and space.
115
+ 2. The type `feat` MUST be used when a commit adds a new feature to your application or library.
116
+ 3. The type `fix` MUST be used when a commit represents a bug fix for your application.
117
+ 4. A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., `fix(parser):`
118
+ 5. A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., _fix: array parsing issue when multiple spaces were contained in string_.
119
+ 6. A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
120
+ 7. A commit body is free-form and MAY consist of any number of newline separated paragraphs.
121
+ 8. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a `:<space>` or `<space>#` separator, followed by a string value (this is inspired by the git trailer convention).
122
+ 9. A footer’s token MUST use `-` in place of whitespace characters, e.g., `Acked-by` (this helps differentiate the footer section from a multi-paragraph body). An exception is made for `BREAKING CHANGE`, which MAY also be used as a token.
123
+ 10. A footer’s value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
124
+ 11. Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
125
+ 12. If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g.,_BREAKING CHANGE: environment variables now take precedence over config files_.
126
+ 13. If included in the type/scope prefix, breaking changes MUST be indicated by a`!` immediately before the `:`. If `!` is used, `BREAKING CHANGE:` MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
127
+ 14. Types other than `feat` and `fix` MAY be used in your commit messages, e.g., _docs: update ref docs._
128
+ 15. The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
129
+ 16. BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
130
+
131
+ ## Why Use Conventional Commits
132
+
133
+ * Automatically generating CHANGELOGs.
134
+ * Automatically determining a semantic version bump (based on the types of commits landed).
135
+ * Communicating the nature of changes to teammates, the public, and other stakeholders.
136
+ * Triggering build and publish processes.
137
+ * Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
138
+
139
+ ## FAQ
140
+
141
+ ### How should I deal with commit messages in the initial development phase?
142
+
143
+ We recommend that you proceed as if you’ve already released the product. Typically _somebody_, even if it’s your fellow software developers, is using your software. They’ll want to know what’s fixed, what breaks etc.
144
+
145
+ ### Are the types in the commit title uppercase or lowercase?
146
+
147
+ Any casing may be used, but it’s best to be consistent.
148
+
149
+ ### What do I do if the commit conforms to more than one of the commit types?
150
+
151
+ Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
152
+
153
+ ### Doesn’t this discourage rapid development and fast iteration?
154
+
155
+ It discourages moving fast in a disorganized way. It helps you be able to move fast long term across multiple projects with varied contributors.
156
+
157
+ ### Might Conventional Commits lead developers to limit the type of commits they make because they’ll be thinking in the types provided?
158
+
159
+ Conventional Commits encourages us to make more of certain types of commits such as fixes. Other than that, the flexibility of Conventional Commits allows your team to come up with their own types and change those types over time.
160
+
161
+ ### How does this relate to SemVer?
162
+
163
+ `fix` type commits should be translated to `PATCH` releases. `feat` type commits should be translated to `MINOR` releases. Commits with `BREAKING CHANGE` in the commits, regardless of type, should be translated to `MAJOR` releases.
164
+
165
+ ### How should I version my extensions to the Conventional Commits Specification, e.g. `@jameswomack/conventional-commit-spec`?
166
+
167
+ We recommend using SemVer to release your own extensions to this specification (and encourage you to make these extensions!)
168
+
169
+ ### What do I do if I accidentally use the wrong commit type?
170
+
171
+ #### When you used a type that’s of the spec but not the correct type, e.g. `fix` instead of `feat`
172
+
173
+ Prior to merging or releasing the mistake, we recommend using `git rebase -i` to edit the commit history. After release, the cleanup will be different according to what tools and processes you use.
174
+
175
+ #### When you used a type _not_ of the spec, e.g. `feet` instead of `feat`
176
+
177
+ In a worst case scenario, it’s not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
178
+
179
+ ### Do all my contributors need to use the Conventional Commits specification?
180
+
181
+ No! If you use a squash based workflow on Git lead maintainers can clean up the commit messages as they’re merged—adding no workload to casual committers. A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge.
182
+
183
+ ### How does Conventional Commits handle revert commits?
184
+
185
+ Reverting code can be complicated: are you reverting multiple commits? if you revert a feature, should the next release instead be a patch?
186
+
187
+ Conventional Commits does not make an explicit effort to define revert behavior. Instead we leave it to tooling authors to use the flexibility of _types_ and _footers_ to develop their logic for handling reverts.
188
+
189
+ One recommendation is to use the `revert` type, and a footer that references the commit SHAs that are being reverted:
190
+
191
+ ```
192
+ revert: let us never again speak of the noodle incident
193
+
194
+ Refs: 676104e, a215868
195
+
196
+ ```
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bunny_farm.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Dewayne VanHoozer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,330 @@
1
+ # BunnyFarm
2
+
3
+ <div align="center">
4
+ <table>
5
+ <tr>
6
+ <td width="40%" align="center" valign="top">
7
+ <a href="https://github.com/MadBomber/bunny_farm" target="_blank">
8
+ <img src="images/bunny_farm_logo.png" alt="BunnyFarm - Lightweight AMQP Job Manager" width="800">
9
+ </a>
10
+ <br /><br />
11
+ <a href="https://badge.fury.io/rb/bunny_farm"><img src="https://badge.fury.io/rb/bunny_farm.svg" alt="Gem Version" /></a>
12
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT" /></a>
13
+ <br/><br/>
14
+ <a href="https://madbomber.github.io/bunny_farm/">Comprehensive Documentation Website</a>
15
+ </td>
16
+ <td width="60%" align="left" valign="top">
17
+ 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.
18
+ <br/><br/>
19
+ 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.
20
+ <br/><br/>
21
+ <h3>Key Features</h3>
22
+ <ul>
23
+ <li><strong>🐰 <a href="#message-structure">Message-Centric Design</a></strong> - Classes encapsulate behavior and data</li>
24
+ <li><strong>🔀 <a href="#usage">Smart Routing</a></strong> - Automatic routing with ClassName.action keys</li>
25
+ <li><strong>📨 <a href="#usage">JSON Serialization</a></strong> - Simple, readable message format</li>
26
+ <li><strong>⚙️ <a href="#configuration">Flexible Configuration</a></strong> - Environment, YAML, or programmatic setup</li>
27
+ <li><strong>🔄 <a href="#examples">Workflow Support</a></strong> - Multi-step processes with message chaining</li>
28
+ <li><strong>⏰ <a href="#examples">Task Scheduling</a></strong> - Delayed execution with retry logic</li>
29
+ <li><strong>🛡️ <a href="#examples">Error Handling</a></strong> - Built-in success/failure tracking</li>
30
+ <li><strong>🎯 <a href="#why">Simplicity First</a></strong> - K.I.S.S. design philosophy</li>
31
+ </ul>
32
+ </td>
33
+ </tr>
34
+ </table>
35
+ </div>
36
+
37
+ ## Table of Contents
38
+
39
+ * [Why?](#why)
40
+ * [How?](#how)
41
+ * [Requirements](#requirements)
42
+ * [Installation](#installation)
43
+ * [Message Structure](#message-structure)
44
+ * [Usage](#usage)
45
+ * [Configuration](#configuration)
46
+ * [Environment Variables](#environment-variables)
47
+ * [Programmatic Configuration](#programmatic-configuration)
48
+ * [Configuration File](#configuration-file)
49
+ * [Testing](#testing)
50
+ * [Architecture Overview](#architecture-overview)
51
+ * [License](#license)
52
+ * [Examples](#examples)
53
+ * [Contributing](#contributing)
54
+
55
+ ## Why?
56
+
57
+ - Simplistic? Because extensive is sometimes overkill.
58
+ - JSON? Because binary compression is sometimes overkill.
59
+ - Bunny? Who doesn't like bunnies? They're like cats with long ears.
60
+ - AMQP? I like AMQP. I like RabbitMQ as an AMQP broker.
61
+
62
+ BTW, at the farm bunnies grow best if planted ears up.
63
+
64
+ ## How?
65
+
66
+ Use system environment variables. Such as:
67
+
68
+ ```bash
69
+ export AMQP_HOST=amqp.example.com
70
+ export AMQP_VHOST=sandbox
71
+ export AMQP_EXCHANGE=sandbox
72
+ export AMQP_QUEUE=tv_show_suggestions
73
+ export AMQP_ROUTING_KEY="TvShowSuggestion.submit"
74
+ export AMQP_PASS=guest
75
+ export AMQP_USER=guest
76
+ ```
77
+
78
+ If you don't know how AMQP works you had better go study. The
79
+ values above were selected to match the demo code below.
80
+
81
+ ## Requirements
82
+
83
+ - Ruby 2.5 or higher
84
+ - RabbitMQ server
85
+ - Bundler
86
+
87
+ ## Installation
88
+
89
+ Add this line to your application's Gemfile:
90
+
91
+ ```ruby
92
+ gem 'bunny_farm'
93
+ ```
94
+
95
+ And then execute:
96
+
97
+ bundle install
98
+
99
+ Or install it yourself as:
100
+
101
+ gem install bunny_farm
102
+
103
+ ## Message Structure
104
+
105
+ Understanding how BunnyFarm messages are structured is key to using the library effectively:
106
+
107
+ ![Message Structure](images/message_structure.svg)
108
+
109
+ ## Usage
110
+
111
+ The shortest job manager / message processor looks like this:
112
+
113
+ ```ruby
114
+ require 'bunny_farm'
115
+ require 'my_message_class'
116
+
117
+ BunnyFarm.config
118
+ BunnyFarm.manage # This will block and process messages
119
+ ```
120
+
121
+ Here is how to publish messages:
122
+
123
+ ```ruby
124
+ require 'bunny_farm'
125
+ require 'my_message_class'
126
+
127
+ BunnyFarm.config do
128
+ app_id 'my_job_name'
129
+ end
130
+
131
+ mm = MyMessageClass.new
132
+
133
+ mm[:field1] = 'Hello'
134
+ mm[:field2] = 'World'
135
+ # ...
136
+ mm[:fieldn] = 'whatever'
137
+
138
+ mm.publish('action') # routing key becomes: MyMessageClass.action
139
+
140
+ puts 'It worked' if mm.successful?
141
+
142
+ if mm.failed?
143
+ puts 'This sucks. Here are some errors:'
144
+ puts mm.errors.join("\n")
145
+ end
146
+ # rinse and repeat as necessary
147
+ ```
148
+
149
+
150
+ All processing is done in YourMessageClass. The
151
+ AMQP routing keys look like: "YourMessageClass.action" and
152
+ guess what the "action" is... a method in YourMessageClass.
153
+
154
+ So assume that I have a public facing website which allows users
155
+ to fill our forms for various purposes. Say that one of those
156
+ forms is to collect suggestions for episodes of a TV show. I would have a
157
+ form with fields that collect informaion about the user as well as a field
158
+ where their suggestion is recorded. As a hash it might looks something
159
+ like this:
160
+
161
+ ```ruby
162
+ form_contents = {
163
+ author: {
164
+ name: 'Jimmy Smith',
165
+ mailing_address: '123 Main St. USA',
166
+ email_address: 'little_jimmy@smith.us',
167
+ phone_number: '+19995551212'
168
+ },
169
+ tv_show_name: 'Lost In Space',
170
+ suggestion: 'Why does doctor Smith have to be such a meanie?',
171
+ lots_of_other_house_keeping_junk: {}
172
+ }
173
+ ```
174
+
175
+ The website turns that hash into a json package and publishes it
176
+ via an AMQP broker. I like RabbitMQ. The published message has
177
+ a routing key of 'TvShowSuggestion.submit'
178
+
179
+ In the file tv_show_suggestion.rb you could have something like this:
180
+
181
+ ```ruby
182
+ class TvShowSuggestion < BunnyFarm::Message
183
+
184
+ fields :tv_show_name, :suggestion,
185
+ { author: [ :name, :mailing_address, :email_address, :phone_number ]}
186
+
187
+ actions :submit
188
+
189
+ def submit
190
+ # TODO: anything you want.
191
+ save_suggestion
192
+ notify_writers if success?
193
+ success? ? send_thank_you : send_sorry_please_try_again
194
+ success!
195
+ some_super_class_service
196
+ successful? # true will ACK the message; false will not
197
+ end
198
+
199
+ private
200
+
201
+ def save_suggestion
202
+ puts @items[:suggestion]
203
+ success
204
+ end
205
+
206
+ def notify_writers
207
+ puts "Hey slackers! what about #{@items[:suggestion]}"
208
+ failure('Writers were sleeping')
209
+ end
210
+
211
+ def send_thank_you
212
+ puts "Thank you goes to #{@items[:author][:name]}"
213
+ success
214
+ end
215
+
216
+ def send_sorry_please_try_again
217
+ STDERR.puts "Sorry #{@items[:author][:name]}, please try again later."
218
+ end
219
+ end # class TvShowSuggestion < BunnyFarm::Message
220
+ ```
221
+
222
+ ## Configuration
223
+
224
+ BunnyFarm provides flexible configuration options to suit different environments and deployment scenarios:
225
+
226
+ ![Configuration Flow](images/configuration_flow.svg)
227
+
228
+ BunnyFarm can be configured using environment variables or programmatically:
229
+
230
+ ### Environment Variables
231
+
232
+ ```bash
233
+ export AMQP_HOST=localhost
234
+ export AMQP_VHOST=/
235
+ export AMQP_PORT=5672
236
+ export AMQP_USER=guest
237
+ export AMQP_PASS=guest
238
+ export AMQP_EXCHANGE=my_exchange
239
+ export AMQP_QUEUE=my_queue
240
+ export AMQP_ROUTING_KEY='#.new'
241
+ export AMQP_APP_NAME=my_app
242
+ ```
243
+
244
+ ### Programmatic Configuration
245
+
246
+ ```ruby
247
+ BunnyFarm.config do
248
+ env 'production'
249
+ app_id 'my_worker'
250
+ bunny_file 'config/bunny.yml.erb'
251
+ end
252
+ ```
253
+
254
+ ### Configuration File
255
+
256
+ You can also use a YAML configuration file with ERB support (`config/bunny.yml.erb`):
257
+
258
+ ```yaml
259
+ defaults: &defaults
260
+ host: <%= ENV['AMQP_HOST'] || 'localhost' %>
261
+ vhost: <%= ENV['AMQP_VHOST'] || '/' %>
262
+ port: <%= (ENV['AMQP_PORT'] || 5672).to_i %>
263
+ user: <%= ENV['AMQP_USER'] || 'guest' %>
264
+ pass: <%= ENV['AMQP_PASS'] || 'guest' %>
265
+ exchange_name: <%= ENV['AMQP_EXCHANGE'] || 'my_exchange' %>
266
+ queue_name: <%= ENV['AMQP_QUEUE'] || 'my_queue' %>
267
+ routing_key: <%= ENV['AMQP_ROUTING_KEY'] || '#' %>
268
+ app_name: <%= ENV['AMQP_APP_NAME'] || 'bunny_farm_job' %>
269
+
270
+ development:
271
+ <<: *defaults
272
+
273
+ test:
274
+ <<: *defaults
275
+
276
+ production:
277
+ <<: *defaults
278
+ host: amqp.production.com
279
+ ```
280
+
281
+ ## Testing
282
+
283
+ ```bash
284
+ bundle exec rake test
285
+ ```
286
+
287
+ ## Architecture Overview
288
+
289
+ BunnyFarm provides a clean, layered architecture that separates concerns and enables scalable message processing:
290
+
291
+
292
+ <img src="images/architecture_overview.svg" alt="Architecture Overview" width="1200">
293
+
294
+ The architecture consists of four main layers:
295
+
296
+ 1. **Ruby Application Layer** - Your web apps, API servers, schedulers, and worker processes
297
+ 2. **BunnyFarm Library Layer** - Core components including Message classes, Publisher, Consumer, Config, and Router
298
+ 3. **RabbitMQ Message Broker** - Handles message routing, queuing, and delivery with exchanges and queues
299
+ 4. **Persistence & External Services** - Databases, email services, file storage, APIs, and caching layers
300
+
301
+ This separation allows for:
302
+ - **Horizontal scaling** - Add more workers as needed
303
+ - **Fault tolerance** - Messages persist in queues if workers are down
304
+ - **Flexible routing** - Different message types can go to different workers
305
+ - **Monitoring** - RabbitMQ provides comprehensive management tools
306
+
307
+ ## License
308
+
309
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
310
+
311
+ ## Examples
312
+
313
+ Check out the [examples directory](examples/) for comprehensive, runnable examples including:
314
+
315
+ - **Simple Producer/Consumer**: Basic message publishing and processing
316
+ - **Order Processing Workflow**: Complex multi-step workflows with error handling
317
+ - **Task Scheduler**: Scheduled tasks with retry logic and failure recovery
318
+
319
+ Each example includes detailed documentation and can be run independently to help you understand BunnyFarm's capabilities.
320
+
321
+ ## Contributing
322
+
323
+ Remember the key design goal is K.I.S.S. Edge cases and exotic stuff
324
+ are not what life is like on the bunny farm.
325
+
326
+ 1. Fork it ( https://github.com/MadBomber/bunny_farm/fork )
327
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
328
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
329
+ 4. Push to the branch (`git push origin my-new-feature`)
330
+ 5. Create a new Pull Request