harmoniser 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6daf41d7ec196c5f279bca1e4d9ee1339f17a81508fb4432359b32595c364a07
4
- data.tar.gz: 1cab012d3c64c10590f032b768e5acd267980980e988d02b3f7297a138d8477a
3
+ metadata.gz: e388156d56ef5ed0664269fd342a778cf7cd96547539d8282125252a880b2fe8
4
+ data.tar.gz: 0d1a7a75f214c27a1f703a5b8951d0063982baf65cd8b492110e79c05c73c2f9
5
5
  SHA512:
6
- metadata.gz: 3ec7c8e929076ca5725f91d1755ba5548b99e87e8d7c3b6f9d63d029cf6fd76c8419fef99c25b46a525dc49f0d1af011f71a210bf3602d75787fbba7941c5cb1
7
- data.tar.gz: 554b5e2c30444280133ec848124e3b1bb88fbb994b3a2056efdbcfaa5817783530b6d25642217db43eaeb25a5cc80652395e7b1203ebe2c37767e07b8a024578
6
+ metadata.gz: 7398e433e4f12f75cbb807470c1562b569d683b846c84b3dac85c1e23e0cfc21f0365a42a3608d3d9ae7d5e412fa6d80b31ad20455ff587290c353a4b46acdd9
7
+ data.tar.gz: 1848ced849205cc118ad6b21a64bcce9ca5e781ce5268445ce2f2e8cb84fee7aa52a7afc4561658da5b3069ef4d8b981d63f8d5cfff10b54a84c2ea1d280ff4b
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2023-11-27
4
+
5
+ ### Added
6
+
7
+ - Support to express publishing through any kind of exchanges
8
+ - Capability to subscribe to queues
9
+ - Express RabbitMQ topology separated from the responsibility of publishing or subscribing
10
+ - Provide dedicated Ruby process to consume messages through the subscribers defined
11
+
12
+ ## [0.2.0] - 2023-11-28
13
+
14
+ ### Added
15
+
16
+ - Introduce github action for releasing the gem once is merged into master
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
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,134 @@
1
+ # Harmoniser
2
+
3
+ A minimalistic approach to communicate with RabbitMQ.
4
+
5
+ Harmoniser uses [Bunny](https://github.com/ruby-amqp/bunny) as a low level library to communicate with RabbitMQ in order to integrate publishing and messages consuming.
6
+
7
+ ## Getting Started
8
+
9
+ 1. Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "harmoniser"
13
+ ```
14
+
15
+ 2. Install the gem:
16
+
17
+ ```ruby
18
+ $ bundle install
19
+ ```
20
+
21
+ 3. Include `Harmoniser::Publisher` and/or `Harmoniser::Subscriber` in your classes. For instance, [this scenario](examples/multicast.rb) assumes that you'd like to run publishers and subscriber under the same process.
22
+
23
+ 4. (Optional) Run the dedicated process for Harmoniser in order to process messages from your subscribers:
24
+
25
+ ```sh
26
+ $ bundle exec harmoniser --require ./examples/multicast.rb
27
+ ```
28
+
29
+ 5. Inspect the logs to see if everything worked as expected. Look for logs including `harmoniser@`.
30
+
31
+ ## Concepts
32
+
33
+ Harmoniser is a library for publishing/consuming messages through RabbitMQ. It allows to not only connect applications but also to scale an application by performing work in the background. This gem is comprised of three parts:
34
+
35
+ ### Publisher
36
+
37
+ The Publisher runs in any Ruby process (puma, unicorn, passenger, sidekiq, etc) and allows you to
38
+ push messages through a [RabbitMQ Exchange](https://www.rabbitmq.com/tutorials/amqp-concepts.html#exchanges). Creating a publisher is as simple as:
39
+
40
+ ```ruby
41
+ require "harmoniser"
42
+
43
+ class MyPublisher
44
+ include Harmoniser::Publisher
45
+ harmoniser_publisher exchange_name: "my_topic_exchange"
46
+ end
47
+
48
+ MyPublisher.publish({ salute: "Hello World!" }.to_json, routing_key: "my_resource.foo.bar")
49
+ ```
50
+
51
+ The code above assumes that the exchange is already defined. We'd like to emphasize that defining RabbitMQ topology (exchanges, queues and binding) should be performed outside of the class whose role is purely focused on publishing. See more details about how to define the topology [here](examples/multicast.rb#L9-L18).
52
+
53
+ ### RabbitMQ
54
+
55
+ RabbitMQ is the message broker used to publish/consume messages through Harmoniser. It can be configured through `Harmoniser.configure` as follows:
56
+
57
+ ```ruby
58
+ require "harmoniser"
59
+
60
+ Harmoniser.configure do |config|
61
+ config.connection_opts = {
62
+ host: "rabbitmq"
63
+ }
64
+ end
65
+ ```
66
+
67
+ The options permitted for `connection_opts` are those accepted by
68
+ [Bunny](https://github.com/ruby-amqp/bunny/blob/80a8fc7aa0cd73f8778df87ae05f28c443d10c0d/lib/bunny/session.rb#L142) since at the end this library is built on top of the most widely used Ruby client for RabbitMQ.
69
+
70
+ ### Subscriber Server
71
+
72
+ Harmoniser server is a process specifically dedicated to run Subscribers that are listening into [Rabbit Queues](https://www.rabbitmq.com/tutorials/amqp-concepts.html#queues). This process like any other Ruby process (puma, unicorn, passenger, sidekiq, etc) is up and running unless OS Signals like (SIGINT, SIGTERM) are sent to it. The server during boot time is able to register each class from your code that includes `Harmoniser::Subscriber` module. Creating a subscriber is as simple as:
73
+
74
+ ```ruby
75
+ class MySubscriber
76
+ include Harmoniser::Subscriber
77
+ harmoniser_subscriber queue_name: "my_queue"
78
+
79
+ class << self
80
+ def on_delivery(delivery_info, properties, payload)
81
+ Harmoniser.logger.info({
82
+ body: "message received",
83
+ payload: payload
84
+ }.to_json)
85
+ end
86
+ end
87
+ end
88
+ ```
89
+
90
+ The code above assumes that the queue and its binding to an exchange are already defined. You can see more details about how this is specified [here](examples/multicast.rb#L9-L18).
91
+
92
+ In order for the subscribers to receive messages from a queue, you should spin up a dedicated Ruby process like following:
93
+
94
+ ```sh
95
+ $ bundle exec harmoniser --require ./a_path_to_your_ruby_file.rb
96
+ ```
97
+
98
+ More info about the different options accepted by harmoniser process in [Harmoniser CLI](docs/cli.md).
99
+
100
+ ## Contributing
101
+
102
+ If you are facing issues and you suspect are related to Harmoniser, please consider opening an issue [here](https://github.com/jollopre/harmoniser/issues). Remember to include as much information as possible such as version of Ruby, Rails, Harmoniser, OS, etc.
103
+
104
+ If you consider you have encountered a potential bug, detailed information about how to reproduce it might help to speed up its fix.
105
+
106
+ ### Code
107
+
108
+ In order to contribute to this codebase, you will need to setup your local development using the following steps:
109
+
110
+ ```sh
111
+ # Prepare the environment for working locally.
112
+ $ make build
113
+ # Perform the desired changes into your local copy
114
+ $ make test
115
+ ```
116
+
117
+ You can also shell into the running container by executing `$ make shell` and from within execute anything related to Harmoniser on its isolated environment.
118
+
119
+ ## Future Improvements
120
+
121
+ - [ ] Issue: Reopen memoized Channel in the context of the class that are included. There are scenarios for which the channel gets closed, for instance Precondition Failed when checking an exchange declaration.
122
+ - [ ] Chore: Introduce simplecov gem for code coverage.
123
+ - [ ] Feature: Add sensible defaults for Session options like heartbeat, timeout, recovery_completed or recovery_attempt_started.
124
+ - [ ] Feature: Add default `on_return` handler as well as permitting the definition of on_return method to be called anytime a published message gets returned.
125
+ - [ ] Feature: Add default `on_error` and `on_uncaught_exception` as well as permitting the definition of them to be called anytime an error in the channel occurs or error in the consumer handler happens.
126
+ - [ ] Feature: Introduce capability of configuring number of threads for queue consuming at the CLI.
127
+
128
+ ## License
129
+
130
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
131
+
132
+ ## Author
133
+
134
+ Jose Lloret, [<jollopre@gmail.com>](mailto:jollopre@gmail.com)
data/docs/cli.md ADDED
@@ -0,0 +1,20 @@
1
+ # Harmoniser CLI
2
+
3
+ Harmoniser CLI is a command line tool than run a Ruby process through `bundle exec harmoniser`. This utility accepts the following options:
4
+
5
+ ```sh
6
+ bundle exec harmoniser -h
7
+
8
+ harmoniser [options]
9
+ -e, --environment ENV Application environment
10
+ -r, --require [PATH|DIR] File to require or location of Rails application
11
+ -v, --[no-]verbose Run verbosely
12
+ -V, --version Print version and exit
13
+ -h, --help Show help
14
+ ```
15
+
16
+ The `environment` is automatically inferred from the environment variables `RAILS_ENV` or `RACK_ENV`, otherwise fallbacks to `production`. However you can specify your preferred value, for instance `development` or `test`.
17
+
18
+ The `require` is by default pointing at `.`, which means that this option when configured under a Rails application, might be ignored. Since Ruby is not Rails only, you can certainly specify the location path of your Ruby file that will be used to load the classes including Harmoniser::Subscriber. In contrast, if a path to a directory is passed, Harmoniser assumes that `./config/environment.rb` lives within the folder passed as option.
19
+
20
+ The `verbose` option, when passed, sets the severity of Harmoniser logs to `debug` being able to see fine-grained details of things like RabbitMQ interactions happening or messages published into exchanges. By default, the verbosity is disabled to prevent your production environment to be flooded with unnecessary logs, however if the environment is not set to `production`, the severity of the logs is `debug` mode too.
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/harmoniser/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "harmoniser"
7
+ spec.version = Harmoniser::VERSION
8
+ spec.authors = ["Jose Lloret"]
9
+ spec.email = ["jollopre@gmail.com"]
10
+
11
+ spec.summary = "A minimalistic approach to communicate with RabbitMQ"
12
+ spec.description = "A declarative approach to communicate with RabbitMQ, that uses the reference low level library, to integrate publishing and consuming of messages"
13
+ spec.homepage = "https://github.com/jollopre/harmoniser"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
+
17
+ spec.metadata = {
18
+ "homepage_uri" => spec.homepage,
19
+ "source_code_uri" => "https://github.com/jollopre/harmoniser",
20
+ "changelog_uri" => "https://github.com/jollopre/harmoniser/blob/master/CHANGELOG.md"
21
+ }
22
+
23
+ spec.files = Dir["lib/**/*.rb"] + Dir["bin/*"] + Dir["docs/**/*", "CHANGELOG.md", "CODE_OF_CONDUCT.md", "harmoniser.gemspec", "LICENSE.txt", "README.md"]
24
+ spec.executables = ["harmoniser"]
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency "bunny", "~> 2.22"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "standardrb", "~> 1.0"
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Harmoniser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harmoniser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Lloret
@@ -66,7 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
- description: A declarative tool to communicate with RabbitMQ
69
+ description: A declarative approach to communicate with RabbitMQ, that uses the reference
70
+ low level library, to integrate publishing and consuming of messages
70
71
  email:
71
72
  - jollopre@gmail.com
72
73
  executables:
@@ -74,9 +75,15 @@ executables:
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
78
+ - CHANGELOG.md
79
+ - CODE_OF_CONDUCT.md
80
+ - LICENSE.txt
81
+ - README.md
77
82
  - bin/console
78
83
  - bin/harmoniser
79
84
  - bin/setup
85
+ - docs/cli.md
86
+ - harmoniser.gemspec
80
87
  - lib/harmoniser.rb
81
88
  - lib/harmoniser/channelable.rb
82
89
  - lib/harmoniser/cli.rb
@@ -117,5 +124,5 @@ requirements: []
117
124
  rubygems_version: 3.4.10
118
125
  signing_key:
119
126
  specification_version: 4
120
- summary: A declarative tool to communicate with RabbitMQ
127
+ summary: A minimalistic approach to communicate with RabbitMQ
121
128
  test_files: []