ears 0.1.0
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/.github/workflows/build.yml +31 -0
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +91 -0
- data/.tool-versions +2 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/ears.gemspec +40 -0
- data/lib/ears.rb +41 -0
- data/lib/ears/consumer.rb +76 -0
- data/lib/ears/middlewares/json.rb +12 -0
- data/lib/ears/setup.rb +54 -0
- data/lib/ears/version.rb +3 -0
- data/package.json +15 -0
- data/yarn.lock +20 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ffe0666050e53793b9bf121c7d7ca22140a0929cc20a4f208f3341b87016316
|
4
|
+
data.tar.gz: 282378c31cfa56d57d1849897b9f3bda537f32f6554f17666ca6d79e20f7272f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c55e36ef299934d94b8bd93e26d53fea82d51b50c79608ec071dbe381043741a74a2eba7f5bdf93b962587d1d375c40ab3c081494d18cd0e291d1ce5a683e422
|
7
|
+
data.tar.gz: '08f998e9ec60b7e2f58c8674ac176bfc5d1c8a70a5717c463a095b8b038461e1f26fedb9f0f4a391d19f57d3d30da980029c715e05d4ff728defa32f766da7bd'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Build
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
bundler-cache: true
|
23
|
+
- uses: actions/setup-node@v2
|
24
|
+
with:
|
25
|
+
node-version: '14'
|
26
|
+
- name: Run prettier
|
27
|
+
run: npm i -g yarn && yarn && yarn lint
|
28
|
+
- name: Run Rubocop
|
29
|
+
run: bundle exec rubocop
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
inherit_mode:
|
2
|
+
merge:
|
3
|
+
- Exclude
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- db/**/*
|
8
|
+
- config/**/*
|
9
|
+
- script/**/*
|
10
|
+
- Rakefile
|
11
|
+
- Guardfile
|
12
|
+
- bin/*
|
13
|
+
- tmp/**/*
|
14
|
+
TargetRubyVersion: 2.5
|
15
|
+
NewCops: enable
|
16
|
+
|
17
|
+
Style:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Layout:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/HashEachMethods:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/HashTransformKeys:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/HashTransformValues:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Metrics/AbcSize:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Naming/VariableNumber:
|
36
|
+
EnforcedStyle: snake_case
|
37
|
+
|
38
|
+
Metrics/BlockLength:
|
39
|
+
CountComments: false
|
40
|
+
Max: 25
|
41
|
+
Exclude:
|
42
|
+
- 'spec/**/*.rb'
|
43
|
+
- 'test/**/*.rb'
|
44
|
+
- 'Rakefile'
|
45
|
+
- '*.gemspec'
|
46
|
+
- 'apps/api/application.rb'
|
47
|
+
- '**/*.rake'
|
48
|
+
|
49
|
+
Metrics/ClassLength:
|
50
|
+
CountComments: false
|
51
|
+
Exclude:
|
52
|
+
- 'spec/**/*.rb'
|
53
|
+
- 'test/**/*.rb'
|
54
|
+
|
55
|
+
Metrics/MethodLength:
|
56
|
+
Enabled: true
|
57
|
+
Exclude:
|
58
|
+
- 'spec/**/*.rb'
|
59
|
+
- 'test/**/*.rb'
|
60
|
+
|
61
|
+
Metrics/ModuleLength:
|
62
|
+
CountComments: false
|
63
|
+
Exclude:
|
64
|
+
- 'spec/**/*.rb'
|
65
|
+
- 'test/**/*.rb'
|
66
|
+
|
67
|
+
require: rubocop-rspec
|
68
|
+
|
69
|
+
RSpec/DescribedClass:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
RSpec/MultipleExpectations:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
RSpec/ExampleLength:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
RSpec/MessageSpies:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
RSpec/MessageChain:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
RSpec/AnyInstance:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
RSpec/MultipleMemoizedHelpers:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
RSpec/StubbedMock:
|
91
|
+
Enabled: false
|
data/.tool-versions
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
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 mario.mainz@invision.de. 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 [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ears (0.1.0)
|
5
|
+
bunny
|
6
|
+
multi_json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
amq-protocol (2.3.2)
|
12
|
+
ast (2.4.2)
|
13
|
+
bunny (2.17.0)
|
14
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
multi_json (1.15.0)
|
17
|
+
parallel (1.20.1)
|
18
|
+
parser (3.0.0.0)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
rainbow (3.0.0)
|
21
|
+
rake (13.0.3)
|
22
|
+
regexp_parser (2.1.1)
|
23
|
+
rexml (3.2.4)
|
24
|
+
rspec (3.10.0)
|
25
|
+
rspec-core (~> 3.10.0)
|
26
|
+
rspec-expectations (~> 3.10.0)
|
27
|
+
rspec-mocks (~> 3.10.0)
|
28
|
+
rspec-core (3.10.1)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-expectations (3.10.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.10.0)
|
33
|
+
rspec-mocks (3.10.2)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-support (3.10.2)
|
37
|
+
rubocop (1.12.0)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 3.0.0.0)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.8, < 3.0)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
46
|
+
rubocop-ast (1.4.1)
|
47
|
+
parser (>= 2.7.1.5)
|
48
|
+
rubocop-rake (0.5.1)
|
49
|
+
rubocop
|
50
|
+
rubocop-rspec (2.2.0)
|
51
|
+
rubocop (~> 1.0)
|
52
|
+
rubocop-ast (>= 1.1.0)
|
53
|
+
ruby-progressbar (1.11.0)
|
54
|
+
unicode-display_width (2.0.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
x86_64-darwin-20
|
58
|
+
x86_64-linux
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
ears!
|
62
|
+
rake
|
63
|
+
rspec
|
64
|
+
rubocop
|
65
|
+
rubocop-rake
|
66
|
+
rubocop-rspec
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Mario Mainz
|
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,35 @@
|
|
1
|
+
# Ears
|
2
|
+
|
3
|
+
TODO: Write description here
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ears'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ears
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ears. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ears/blob/master/CODE_OF_CONDUCT.md).
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
32
|
+
|
33
|
+
## Code of Conduct
|
34
|
+
|
35
|
+
Everyone interacting in the Ears project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ears/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/ears.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'lib/ears/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'ears'
|
5
|
+
spec.version = Ears::VERSION
|
6
|
+
spec.authors = ['Mario Mainz']
|
7
|
+
spec.email = ['mario.mainz@invision.de']
|
8
|
+
|
9
|
+
spec.summary = 'A gem for building RabbitMQ consumers.'
|
10
|
+
spec.description = 'A gem for building RabbitMQ consumers.'
|
11
|
+
spec.homepage = 'https://github.com/ivx/ears'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
14
|
+
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ivx/ears'
|
19
|
+
spec.metadata['changelog_uri'] =
|
20
|
+
'https://github.com/ivx/ears/blob/master/CHANGELOG.md'
|
21
|
+
|
22
|
+
spec.files =
|
23
|
+
Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'bunny'
|
33
|
+
spec.add_dependency 'multi_json'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'rake'
|
36
|
+
spec.add_development_dependency 'rspec'
|
37
|
+
spec.add_development_dependency 'rubocop'
|
38
|
+
spec.add_development_dependency 'rubocop-rake'
|
39
|
+
spec.add_development_dependency 'rubocop-rspec'
|
40
|
+
end
|
data/lib/ears.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require 'ears/consumer'
|
3
|
+
require 'ears/setup'
|
4
|
+
require 'ears/version'
|
5
|
+
|
6
|
+
module Ears
|
7
|
+
class Error < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def connection
|
12
|
+
@connection ||= Bunny.new.tap { |conn| conn.start }
|
13
|
+
end
|
14
|
+
|
15
|
+
def channel
|
16
|
+
Thread.current[:ears_channel] ||=
|
17
|
+
connection
|
18
|
+
.create_channel(nil, 1, true)
|
19
|
+
.tap do |channel|
|
20
|
+
channel.prefetch(1)
|
21
|
+
channel.on_uncaught_exception { |error| Thread.main.raise(error) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup(&block)
|
26
|
+
Ears::Setup.new.instance_eval(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def run!
|
30
|
+
running = true
|
31
|
+
Signal.trap('INT') { running = false }
|
32
|
+
Signal.trap('TERM') { running = false }
|
33
|
+
sleep 1 while running
|
34
|
+
end
|
35
|
+
|
36
|
+
def reset!
|
37
|
+
@connection = nil
|
38
|
+
Thread.current[:ears_channel] = nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
|
3
|
+
module Ears
|
4
|
+
class Consumer < Bunny::Consumer
|
5
|
+
class InvalidReturnError < StandardError
|
6
|
+
def initialize(value)
|
7
|
+
super(
|
8
|
+
"#work must return :ack, :reject or :requeue, received #{value.inspect} instead",
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.middlewares
|
14
|
+
@middlewares ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.use(middleware)
|
18
|
+
middlewares << middleware
|
19
|
+
end
|
20
|
+
|
21
|
+
def work(delivery_info, metadata, payload)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def process_delivery(delivery_info, metadata, payload)
|
26
|
+
self.class.middlewares.reverse.reduce(
|
27
|
+
work_proc,
|
28
|
+
) do |next_middleware, middleware|
|
29
|
+
nest_middleware(middleware, next_middleware)
|
30
|
+
end.call(delivery_info, metadata, payload)
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def ack
|
36
|
+
:ack
|
37
|
+
end
|
38
|
+
|
39
|
+
def reject
|
40
|
+
:reject
|
41
|
+
end
|
42
|
+
|
43
|
+
def requeue
|
44
|
+
:requeue
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def work_proc
|
50
|
+
->(delivery_info, metadata, payload) do
|
51
|
+
work(delivery_info, metadata, payload).tap do |result|
|
52
|
+
process_result(result, delivery_info.delivery_tag)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def nest_middleware(middleware, next_middleware)
|
58
|
+
->(delivery_info, metadata, payload) do
|
59
|
+
middleware.call(delivery_info, metadata, payload, next_middleware)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def process_result(result, delivery_tag)
|
64
|
+
case result
|
65
|
+
when :ack
|
66
|
+
channel.ack(delivery_tag, false)
|
67
|
+
when :reject
|
68
|
+
channel.reject(delivery_tag)
|
69
|
+
when :requeue
|
70
|
+
channel.reject(delivery_tag, true)
|
71
|
+
else
|
72
|
+
raise InvalidReturnError, result
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/ears/setup.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require 'ears/consumer'
|
3
|
+
|
4
|
+
module Ears
|
5
|
+
class Setup
|
6
|
+
def exchange(name, type, opts = {})
|
7
|
+
Bunny::Exchange.new(Ears.channel, type, name, opts)
|
8
|
+
end
|
9
|
+
|
10
|
+
def queue(name, opts = {})
|
11
|
+
Bunny::Queue.new(Ears.channel, name, opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def consumer(queue, consumer_class, threads = 1, args = {})
|
15
|
+
threads.times do |n|
|
16
|
+
consumer_queue = create_consumer_queue(queue, args)
|
17
|
+
create_consumer(consumer_queue, consumer_class, args, n + 1)
|
18
|
+
.tap do |consumer|
|
19
|
+
consumer.on_delivery do |delivery_info, metadata, payload|
|
20
|
+
consumer.process_delivery(delivery_info, metadata, payload)
|
21
|
+
end
|
22
|
+
consumer_queue.subscribe_with(consumer)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_consumer(queue, consumer_class, args, number)
|
30
|
+
consumer_class.new(
|
31
|
+
queue.channel,
|
32
|
+
queue,
|
33
|
+
"#{consumer_class.name}-#{number}",
|
34
|
+
false,
|
35
|
+
false,
|
36
|
+
args,
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_consumer_channel(args)
|
41
|
+
Ears
|
42
|
+
.connection
|
43
|
+
.create_channel(nil, 1, true)
|
44
|
+
.tap do |channel|
|
45
|
+
channel.prefetch(args.fetch(:prefetch, 1))
|
46
|
+
channel.on_uncaught_exception { |error| Thread.main.raise(error) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_consumer_queue(queue, args)
|
51
|
+
Bunny::Queue.new(create_consumer_channel(args), queue.name, queue.options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/ears/version.rb
ADDED
data/package.json
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"name": "on-prem-importer",
|
3
|
+
"private": true,
|
4
|
+
"scripts": {
|
5
|
+
"prettify": "prettier \"**/*.{ru,rb,yml,yaml,md,gemspec,json}\" --ignore-path=\".gitignore\"",
|
6
|
+
"lint": "yarn prettify --check",
|
7
|
+
"format": "yarn prettify --write"
|
8
|
+
},
|
9
|
+
"devDependencies": {
|
10
|
+
"@invisionag/prettier-config-ivx": "^2.1.1",
|
11
|
+
"@prettier/plugin-ruby": "^1.5.2",
|
12
|
+
"prettier": "^2.2.0"
|
13
|
+
},
|
14
|
+
"prettier": "@invisionag/prettier-config-ivx"
|
15
|
+
}
|
data/yarn.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
2
|
+
# yarn lockfile v1
|
3
|
+
|
4
|
+
|
5
|
+
"@invisionag/prettier-config-ivx@^2.1.1":
|
6
|
+
version "2.1.1"
|
7
|
+
resolved "https://registry.yarnpkg.com/@invisionag/prettier-config-ivx/-/prettier-config-ivx-2.1.1.tgz#8899ec027cfde823ff497f2d67326bc14fbdf4bd"
|
8
|
+
integrity sha512-vujtO8XVSwoWU6k1lRZzvOeMCNvX2injJsEfG5rAfQGBjcN0J4a0zwXYBb6GI4gNZsYj6C6iD1Nk2HsMXKFByg==
|
9
|
+
|
10
|
+
"@prettier/plugin-ruby@^1.5.2":
|
11
|
+
version "1.5.3"
|
12
|
+
resolved "https://registry.yarnpkg.com/@prettier/plugin-ruby/-/plugin-ruby-1.5.3.tgz#04c1058fce59651c38c02ace39faa7a0daa4264b"
|
13
|
+
integrity sha512-YXXf0PGsUOMk40UlfnjDeF3NuRmKE4ddN4L2drFaskhqcB/P9jNGabz5FsGJdJt+ibPxfRsqx05gfxGLZo1wHg==
|
14
|
+
dependencies:
|
15
|
+
prettier ">=1.10"
|
16
|
+
|
17
|
+
prettier@>=1.10, prettier@^2.2.0:
|
18
|
+
version "2.2.1"
|
19
|
+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
20
|
+
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ears
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mario Mainz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-23 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A gem for building RabbitMQ consumers.
|
112
|
+
email:
|
113
|
+
- mario.mainz@invision.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".github/workflows/build.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".tool-versions"
|
123
|
+
- CHANGELOG.md
|
124
|
+
- CODE_OF_CONDUCT.md
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.md
|
129
|
+
- Rakefile
|
130
|
+
- ears.gemspec
|
131
|
+
- lib/ears.rb
|
132
|
+
- lib/ears/consumer.rb
|
133
|
+
- lib/ears/middlewares/json.rb
|
134
|
+
- lib/ears/setup.rb
|
135
|
+
- lib/ears/version.rb
|
136
|
+
- package.json
|
137
|
+
- yarn.lock
|
138
|
+
homepage: https://github.com/ivx/ears
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata:
|
142
|
+
allowed_push_host: https://rubygems.org
|
143
|
+
homepage_uri: https://github.com/ivx/ears
|
144
|
+
source_code_uri: https://github.com/ivx/ears
|
145
|
+
changelog_uri: https://github.com/ivx/ears/blob/master/CHANGELOG.md
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 2.5.0
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubygems_version: 3.2.3
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: A gem for building RabbitMQ consumers.
|
165
|
+
test_files: []
|