jackhammer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/.travis.yml +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/jackhammer +17 -0
- data/jackhammer.gemspec +38 -0
- data/lib/jackhammer.rb +41 -0
- data/lib/jackhammer/cli.rb +32 -0
- data/lib/jackhammer/configuration.rb +35 -0
- data/lib/jackhammer/log.rb +15 -0
- data/lib/jackhammer/message_receiver.rb +22 -0
- data/lib/jackhammer/null_exception_adapter.rb +8 -0
- data/lib/jackhammer/publish.rb +19 -0
- data/lib/jackhammer/queue.rb +20 -0
- data/lib/jackhammer/server.rb +24 -0
- data/lib/jackhammer/topic.rb +32 -0
- data/lib/jackhammer/topic_manager.rb +16 -0
- data/lib/jackhammer/version.rb +5 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 208370cd05fdeaebee2a7c3415c2923d7991ee87e5e8b2b2eabd7f8e6d0ca361
|
4
|
+
data.tar.gz: 23199d8489f34df2d5b8ea71c08f377bf65a00c3174a25b1911d052f247ac6cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 821b70fe20af463bf905df1c91ac01efa89a68429c4d33521b7b449c2018c686087154f50b286ebc96eed95790b6e30b21f07f13f7d0f9dbbf7a56ba2beba570
|
7
|
+
data.tar.gz: a8eadd59bd7d8fea7ba0449a44c8164d83433a415829fc517ac3c3bd007cc631b9a6d1a20a686781163f1b26d2bc078a0a48625e86a2dade8f541f353c06e28d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at scott@renofi.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jackhammer (0.1.0)
|
5
|
+
bunny (~> 2.14)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
amq-protocol (2.3.0)
|
11
|
+
ast (2.4.0)
|
12
|
+
bunny (2.14.2)
|
13
|
+
amq-protocol (~> 2.3, >= 2.3.0)
|
14
|
+
bunny-mock (1.7.0)
|
15
|
+
bunny (>= 1.7)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
jaro_winkler (1.5.3)
|
18
|
+
parallel (1.17.0)
|
19
|
+
parser (2.6.4.1)
|
20
|
+
ast (~> 2.4.0)
|
21
|
+
rainbow (3.0.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.8.0)
|
24
|
+
rspec-core (~> 3.8.0)
|
25
|
+
rspec-expectations (~> 3.8.0)
|
26
|
+
rspec-mocks (~> 3.8.0)
|
27
|
+
rspec-core (3.8.2)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-expectations (3.8.4)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-mocks (3.8.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-support (3.8.2)
|
36
|
+
rubocop (0.74.0)
|
37
|
+
jaro_winkler (~> 1.5.1)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.6)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
43
|
+
rubocop-performance (1.4.1)
|
44
|
+
rubocop (>= 0.71.0)
|
45
|
+
ruby-progressbar (1.10.1)
|
46
|
+
unicode-display_width (1.6.0)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler (~> 2.0)
|
53
|
+
bunny-mock (~> 1.7)
|
54
|
+
jackhammer!
|
55
|
+
rake (~> 10.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
rubocop (~> 0.74)
|
58
|
+
rubocop-performance (~> 1.4.1)
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Scott Serok
|
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,95 @@
|
|
1
|
+
# Jackhammer
|
2
|
+
|
3
|
+
Jackhammer is an opinionated, configurable facade over the RabbitMQ Bunny
|
4
|
+
module.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'jackhammer'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install jackhammer
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Create a YAML file to configure topics and queues your Jackhammer::Server instance
|
25
|
+
will subscribe to when using the executable.
|
26
|
+
|
27
|
+
```YAML
|
28
|
+
# config/jackhammer.yml
|
29
|
+
---
|
30
|
+
default: &default
|
31
|
+
weather:
|
32
|
+
auto_delete: false
|
33
|
+
durable: true
|
34
|
+
queues:
|
35
|
+
americas.south:
|
36
|
+
auto_delete: true
|
37
|
+
durable: false
|
38
|
+
exclusive: false
|
39
|
+
handler: "MyApp::SouthAmericaHandler"
|
40
|
+
routing_key: "americas.south.#"
|
41
|
+
|
42
|
+
development:
|
43
|
+
<<: *default
|
44
|
+
|
45
|
+
development:
|
46
|
+
<<: *default
|
47
|
+
|
48
|
+
production:
|
49
|
+
<<: *default
|
50
|
+
```
|
51
|
+
|
52
|
+
Configure your subscription server by sublcassing `Jackhammer::Server`.
|
53
|
+
|
54
|
+
```Ruby
|
55
|
+
# config/application.rb
|
56
|
+
require 'jackhammer'
|
57
|
+
|
58
|
+
module MyApp
|
59
|
+
class Server < Jackhammer::Server
|
60
|
+
Jackhammer.configure do |jack|
|
61
|
+
jack.connection_options = {}
|
62
|
+
jack.connection_url = nil
|
63
|
+
jack.environment = ENV['RACK_ENV'] || :development
|
64
|
+
jack.exception_adapter = NullExceptionAdapter.new
|
65
|
+
jack.logger = Logger.new(IO::NULL)
|
66
|
+
jack.publish_options = { mandatory: true, persistent: true }
|
67
|
+
jack.yaml_config = "config/jackhammer.yml"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
Start the subscription server to read the YAML and subscribe to topic queues.
|
74
|
+
|
75
|
+
```
|
76
|
+
$ bundle exec jackhammer -r config/application.rb
|
77
|
+
```
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jackhammer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
92
|
+
|
93
|
+
## Code of Conduct
|
94
|
+
|
95
|
+
Everyone interacting in the Jackhammer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/renofi/jackhammer/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'jackhammer'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/jackhammer
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'jackhammer'
|
5
|
+
require 'jackhammer/cli'
|
6
|
+
|
7
|
+
begin
|
8
|
+
cli = Jackhammer::CLI.new
|
9
|
+
cli.parse
|
10
|
+
cli.run
|
11
|
+
rescue StandardError => e
|
12
|
+
raise e if $DEBUG
|
13
|
+
|
14
|
+
warn e.message
|
15
|
+
warn e.backtrace.join("\n")
|
16
|
+
exit 1
|
17
|
+
end
|
data/jackhammer.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'jackhammer/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'jackhammer'
|
9
|
+
spec.version = Jackhammer::VERSION
|
10
|
+
spec.authors = ['Scott Serok']
|
11
|
+
spec.email = ['scott@renofi.com']
|
12
|
+
|
13
|
+
spec.summary = 'Jackhammer is an opinionated facde over RabbitMQ Bunny'
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = 'https://github.com/renofi/jackhammer'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_dependency 'bunny', '~> 2.14'
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'bunny-mock', '~> 1.7'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 0.74'
|
37
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.4.1'
|
38
|
+
end
|
data/lib/jackhammer.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'forwardable'
|
5
|
+
require 'bunny'
|
6
|
+
require 'jackhammer/log'
|
7
|
+
require 'jackhammer/null_exception_adapter'
|
8
|
+
require 'jackhammer/configuration'
|
9
|
+
require 'jackhammer/message_receiver'
|
10
|
+
require 'jackhammer/queue'
|
11
|
+
require 'jackhammer/topic'
|
12
|
+
require 'jackhammer/topic_manager'
|
13
|
+
require 'jackhammer/publish'
|
14
|
+
require 'jackhammer/server'
|
15
|
+
|
16
|
+
module Jackhammer
|
17
|
+
class << self
|
18
|
+
attr_accessor :configuration
|
19
|
+
attr_writer :connection
|
20
|
+
|
21
|
+
def configure
|
22
|
+
@configuration = Configuration.instance
|
23
|
+
yield @configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= Bunny.new(
|
28
|
+
Jackhammer.configuration.connection_url,
|
29
|
+
Jackhammer.configuration.connection_options
|
30
|
+
).start
|
31
|
+
end
|
32
|
+
|
33
|
+
def channel
|
34
|
+
@channel ||= connection.create_channel
|
35
|
+
end
|
36
|
+
|
37
|
+
def topics
|
38
|
+
@topics ||= TopicManager.topics
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
class CLI
|
5
|
+
attr_reader :logger, :opts
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@logger = Logger.new STDERR
|
9
|
+
@opts = { require: './config/application' }
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(argv = ARGV)
|
13
|
+
@parser = OptionParser.new do |o|
|
14
|
+
o.on "-r", "--require PATH", "Location of application" do |arg|
|
15
|
+
opts[:require] = arg
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@parser.banner = "jackhammer [options]"
|
19
|
+
@parser.on_tail "-h", "--help", "Show help" do
|
20
|
+
logger.info @parser
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
@parser.parse!(argv)
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
require opts[:require]
|
28
|
+
Log.info "Booting up Jackhammer v#{VERSION}"
|
29
|
+
Jackhammer.configuration.server.start
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
class Configuration
|
5
|
+
attr_accessor(
|
6
|
+
:connection_options,
|
7
|
+
:connection_url,
|
8
|
+
:environment,
|
9
|
+
:exception_adapter,
|
10
|
+
:logger,
|
11
|
+
:publish_options,
|
12
|
+
:server,
|
13
|
+
:yaml_config
|
14
|
+
)
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@connection_options = {}
|
18
|
+
@connection_url = ENV['RABBITMQ_URL']
|
19
|
+
@environment = ENV['RACK_ENV'] || :development
|
20
|
+
@exception_adapter = NullExceptionAdapter.new
|
21
|
+
@logger = Logger.new IO::NULL
|
22
|
+
@publish_options = { mandatory: true, persistent: true }
|
23
|
+
@yaml_config = './config/jackhammer.yml'
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.instance
|
27
|
+
@instance ||= new
|
28
|
+
end
|
29
|
+
|
30
|
+
def yaml
|
31
|
+
environment = Jackhammer.configuration.environment
|
32
|
+
YAML.load_file(Jackhammer.configuration.yaml_config)[environment]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
class Log
|
5
|
+
class << self
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegators :instance, :debug, :info, :warn, :error, :critical
|
9
|
+
|
10
|
+
def instance
|
11
|
+
@instance ||= Jackhammer.configuration.logger
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
# An object meant to be instantiated once but used on each payload received
|
5
|
+
# via the #call method
|
6
|
+
class MessageReceiver
|
7
|
+
attr_reader :handler_class
|
8
|
+
|
9
|
+
def initialize(handler_class)
|
10
|
+
@handler_class = handler_class
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(message)
|
14
|
+
handler = Object.const_get(handler_class)
|
15
|
+
if handler.respond_to?(:perform_async)
|
16
|
+
handler.perform_async message
|
17
|
+
else
|
18
|
+
handler.call message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
# The API to send messages to a topic with a given attribute
|
5
|
+
class Publish
|
6
|
+
class << self
|
7
|
+
def topics
|
8
|
+
@topics ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def publish(event, message, options)
|
12
|
+
publish_options = Jackhammer.configuration.publish_options # system defaults
|
13
|
+
publish_options[:routing_key] = event # routing_key
|
14
|
+
publish_options = publish_options.merge options # override any system defaults
|
15
|
+
Jackhammer.connection.publish message, publish_options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Jackhammer
|
2
|
+
class Queue
|
3
|
+
def initialize(topic:, queue:, handler:, routing:)
|
4
|
+
@topic = topic
|
5
|
+
@queue = queue
|
6
|
+
@queue.bind @topic, routing_key: routing
|
7
|
+
@handler_object = handler
|
8
|
+
end
|
9
|
+
|
10
|
+
def subscribe
|
11
|
+
@queue.subscribe do |delivery_info, properties, content|
|
12
|
+
Log.debug [delivery_info.inspect, properties.inspect, content].join(' || ')
|
13
|
+
@handler_object.call content
|
14
|
+
rescue StandardError => e
|
15
|
+
Log.error e
|
16
|
+
Jackhammer.configuration.exception_adapter.capture e
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
class Server
|
5
|
+
def self.configure
|
6
|
+
Jackhammer.configure do |j|
|
7
|
+
yield(j)
|
8
|
+
j.server = self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.start
|
13
|
+
running = true
|
14
|
+
Signal.trap('INT') do
|
15
|
+
print "\n\nstopping...\n"
|
16
|
+
running = false
|
17
|
+
end
|
18
|
+
Jackhammer.topics.each { |_name, topic| topic.subscribe_queues }
|
19
|
+
Log.info 'Topic queues subscribed and listening... Send INT signal to stop.'
|
20
|
+
sleep 2 while running
|
21
|
+
Jackhammer.connection.close
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
class Topic
|
5
|
+
def initialize(name:, options:, queue_config:)
|
6
|
+
@topic = Jackhammer.channel.topic name, options
|
7
|
+
@queue_config = queue_config
|
8
|
+
end
|
9
|
+
|
10
|
+
def subscribe_queues
|
11
|
+
queues.each(&:subscribe)
|
12
|
+
end
|
13
|
+
|
14
|
+
# We're expecting the client to specify at least the routing_key in options
|
15
|
+
# for each message published.
|
16
|
+
def publish(message, options)
|
17
|
+
full_options = Jackhammer.configuration.publish_options.dup.merge options
|
18
|
+
@topic.publish message, full_options
|
19
|
+
end
|
20
|
+
|
21
|
+
def queues
|
22
|
+
return @queues if @queues
|
23
|
+
|
24
|
+
@queues = @queue_config.map do |name, options|
|
25
|
+
handler = MessageReceiver.new(options.delete('handler'))
|
26
|
+
routing = options.delete 'routing_key'
|
27
|
+
queue = Jackhammer.channel.queue name, options
|
28
|
+
Queue.new topic: @topic, queue: queue, handler: handler, routing: routing
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jackhammer
|
4
|
+
class TopicManager
|
5
|
+
class << self
|
6
|
+
def topics
|
7
|
+
topics = {}
|
8
|
+
Jackhammer.configuration.yaml.each do |topic, topic_config|
|
9
|
+
queues = topic_config.delete 'queues'
|
10
|
+
topics[topic.to_sym] = Topic.new(name: topic, options: topic_config, queue_config: queues)
|
11
|
+
end
|
12
|
+
topics
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jackhammer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Serok
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bunny
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bunny-mock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.74'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.74'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-performance
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.4.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.4.1
|
111
|
+
description: Jackhammer is an opinionated facde over RabbitMQ Bunny
|
112
|
+
email:
|
113
|
+
- scott@renofi.com
|
114
|
+
executables:
|
115
|
+
- jackhammer
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- exe/jackhammer
|
132
|
+
- jackhammer.gemspec
|
133
|
+
- lib/jackhammer.rb
|
134
|
+
- lib/jackhammer/cli.rb
|
135
|
+
- lib/jackhammer/configuration.rb
|
136
|
+
- lib/jackhammer/log.rb
|
137
|
+
- lib/jackhammer/message_receiver.rb
|
138
|
+
- lib/jackhammer/null_exception_adapter.rb
|
139
|
+
- lib/jackhammer/publish.rb
|
140
|
+
- lib/jackhammer/queue.rb
|
141
|
+
- lib/jackhammer/server.rb
|
142
|
+
- lib/jackhammer/topic.rb
|
143
|
+
- lib/jackhammer/topic_manager.rb
|
144
|
+
- lib/jackhammer/version.rb
|
145
|
+
homepage: https://github.com/renofi/jackhammer
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata:
|
149
|
+
homepage_uri: https://github.com/renofi/jackhammer
|
150
|
+
source_code_uri: https://github.com/renofi/jackhammer
|
151
|
+
changelog_uri: https://github.com/renofi/jackhammer
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubygems_version: 3.0.3
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Jackhammer is an opinionated facde over RabbitMQ Bunny
|
171
|
+
test_files: []
|