bunny-publisher 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -1
- data/README.md +46 -0
- data/lib/bunny_publisher.rb +19 -3
- data/lib/bunny_publisher/base.rb +8 -6
- data/lib/bunny_publisher/mandatory.rb +15 -12
- data/lib/bunny_publisher/test.rb +33 -0
- data/lib/bunny_publisher/version.rb +1 -1
- metadata +25 -31
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.rubocop.yml +0 -16
- data/.travis.yml +0 -16
- data/Gemfile +0 -10
- data/Rakefile +0 -8
- data/bunny-publisher.gemspec +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9578d81f2d9e983145b25db99694b6600ceb72260af7400d53d222a4f0723d09
|
4
|
+
data.tar.gz: 88a145f8ea8e6859d383d9983093d467140f3fe3104a164aa0526125da1defc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b256c60e4c18f7c033867a18077273246188aabc01091a9cd27c3927330daa6f461ed35c1bef7890f1817937884c920fd25807530b0ddbf03a436c9dacaf8727
|
7
|
+
data.tar.gz: f669cd0022bc139539232aebc467bdba3a0c373fc121ce6a91d2304731b23002e1d51401e4c418435cb753e9ffeaa7f926f5ab52634c84edcc20b3c40c7b49f7
|
data/CHANGELOG.md
CHANGED
@@ -1 +1,46 @@
|
|
1
|
-
|
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
|
+
|
7
|
+
## [Unreleased](https://github.com/veeqo/bunny-publisher/compare/v0.1.5...HEAD)
|
8
|
+
|
9
|
+
|
10
|
+
## [0.1.5](https://github.com/veeqo/bunny-publisher/compare/v0.1.4...v0.1.5) - 2020-11-04
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- [#7](https://github.com/veeqo/bunny-publisher/pull/7) Enforce single channel for threaded apps
|
14
|
+
|
15
|
+
|
16
|
+
## [0.1.4](https://github.com/veeqo/bunny-publisher/compare/v0.1.3...v0.1.4) - 2020-11-03
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
- [#5](https://github.com/veeqo/bunny-publisher/pull/5) Test against ruby 2.7.2
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
- [#6](https://github.com/veeqo/bunny-publisher/pull/6) Do not share channels between threads
|
23
|
+
|
24
|
+
|
25
|
+
## [0.1.3](https://github.com/veeqo/bunny-publisher/compare/v0.1.2...v0.1.3) - 2020-09-18
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
- [#2](https://github.com/veeqo/bunny-publisher/pull/2) Use appraisal gem to control gem versions of tests matrix
|
29
|
+
- [#3](https://github.com/veeqo/bunny-publisher/pull/3) Require ruby 2.5
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
- [#4](https://github.com/veeqo/bunny-publisher/pull/4) Fix deprecation warnings of ruby 2.7
|
33
|
+
|
34
|
+
|
35
|
+
## [0.1.2](https://github.com/veeqo/bunny-publisher/compare/v0.1.1...v0.1.2) - 2020-07-30
|
36
|
+
|
37
|
+
### Added
|
38
|
+
- [846369a](https://github.com/veeqo/bunny-publisher/commit/846369a76a9ae1c38e0a08844a5c992412eac520) Test mode
|
39
|
+
|
40
|
+
|
41
|
+
## [0.1.1](https://github.com/veeqo/bunny-publisher/compare/v0.1.0...v0.1.1) - 2020-05-21
|
42
|
+
|
43
|
+
### Changed
|
44
|
+
- [fec490c](https://github.com/veeqo/bunny-publisher/commit/fec490c91a7db9d053dba9afde0736a4ce2dde71) Imrove unrouted messages processing
|
45
|
+
|
46
|
+
## [0.1.0](https://github.com/veeqo/bunny-publisher/releases/tag/v0.1.0) - 2020-05-20
|
data/README.md
CHANGED
@@ -111,6 +111,52 @@ end
|
|
111
111
|
|
112
112
|
Not implemented yet
|
113
113
|
|
114
|
+
## Test mode
|
115
|
+
|
116
|
+
BunnyPublisher also has a test mode which replaces exchange and prevents real connection to RabbitMQ
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
BunnyPublisher.configure do |c|
|
120
|
+
c.test = true # or Rails.env.test?
|
121
|
+
|
122
|
+
# ...
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
Now publisher has `#messages`, `#flush!` methods:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
describe SomeServiceThatPublishesToRabbitMQ, '#call' do
|
130
|
+
subject { described_class.new(some: 'attributes').call }
|
131
|
+
|
132
|
+
before { BunnyPublisher.flush! }
|
133
|
+
|
134
|
+
it 'publishes a message' do
|
135
|
+
expect { subject }.to change(BunnyPublisher.messages).by(1)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
## Testing
|
141
|
+
|
142
|
+
Run rabbitmq server (in separate console):
|
143
|
+
```
|
144
|
+
docker run --rm -p 5672:5672 -p 15672:15672 rabbitmq:3.8-management-alpine
|
145
|
+
```
|
146
|
+
|
147
|
+
Run tests with:
|
148
|
+
|
149
|
+
```sh
|
150
|
+
bundle
|
151
|
+
rake
|
152
|
+
```
|
153
|
+
|
154
|
+
Use [wwtd](https://github.com/grosser/wwtd) to run test matrix:
|
155
|
+
```sh
|
156
|
+
gem install wwtd
|
157
|
+
wwtd
|
158
|
+
```
|
159
|
+
|
114
160
|
## Contributing
|
115
161
|
|
116
162
|
Bug reports and pull requests are welcome on GitHub at https://github.com/veeqo/bunny-publisher.
|
data/lib/bunny_publisher.rb
CHANGED
@@ -6,6 +6,7 @@ require 'bunny_publisher/callbacks'
|
|
6
6
|
require 'bunny_publisher/errors'
|
7
7
|
require 'bunny_publisher/base'
|
8
8
|
require 'bunny_publisher/mandatory'
|
9
|
+
require 'bunny_publisher/test'
|
9
10
|
|
10
11
|
module BunnyPublisher
|
11
12
|
class << self
|
@@ -20,13 +21,28 @@ module BunnyPublisher
|
|
20
21
|
def configure
|
21
22
|
require 'ostruct'
|
22
23
|
|
23
|
-
config = OpenStruct.new(
|
24
|
+
config = OpenStruct.new(mandatory: false, test: false)
|
24
25
|
|
25
26
|
yield(config)
|
26
27
|
|
27
|
-
klass = Class.new(Base)
|
28
|
+
klass = Class.new(Base) do
|
29
|
+
include ::BunnyPublisher::Mandatory if config.delete_field(:mandatory)
|
30
|
+
include ::BunnyPublisher::Test if config.delete_field(:test)
|
31
|
+
end
|
28
32
|
|
29
|
-
@publisher = klass.new(config.to_h)
|
33
|
+
@publisher = klass.new(**config.to_h)
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(method_name, *args)
|
37
|
+
if publisher.respond_to?(method_name)
|
38
|
+
publisher.send(method_name, *args)
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_to_missing?(method_name, *args)
|
45
|
+
publisher.respond_to?(method_name) || super
|
30
46
|
end
|
31
47
|
end
|
32
48
|
end
|
data/lib/bunny_publisher/base.rb
CHANGED
@@ -25,13 +25,15 @@ module BunnyPublisher
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def publish(message, options = {})
|
28
|
-
|
28
|
+
@mutex.synchronize do
|
29
|
+
ensure_connection!
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
run_callback(:before_publish, message, options)
|
32
|
+
result = run_callback(:around_publish, message, options) { exchange.publish(message, options) }
|
33
|
+
run_callback(:after_publish, message, options)
|
33
34
|
|
34
|
-
|
35
|
+
result
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
def close
|
@@ -43,7 +45,7 @@ module BunnyPublisher
|
|
43
45
|
private
|
44
46
|
|
45
47
|
def ensure_connection!
|
46
|
-
|
48
|
+
connect! unless connected?
|
47
49
|
end
|
48
50
|
|
49
51
|
def connect!
|
@@ -16,7 +16,7 @@ module BunnyPublisher
|
|
16
16
|
attr_reader :queue_name, :queue_options
|
17
17
|
|
18
18
|
def initialize(republish_connection: nil, queue: nil, queue_options: {}, timeout_at_exit: 5, **options)
|
19
|
-
super(options)
|
19
|
+
super(**options)
|
20
20
|
|
21
21
|
@queue_name = queue
|
22
22
|
@queue_options = queue_options
|
@@ -65,7 +65,7 @@ module BunnyPublisher
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def ensure_republish_connection!
|
68
|
-
|
68
|
+
connect_for_republish! unless connected_for_republish?
|
69
69
|
end
|
70
70
|
|
71
71
|
def connected_for_republish?
|
@@ -91,7 +91,7 @@ module BunnyPublisher
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def on_message_return(return_info, properties, message)
|
94
|
-
@
|
94
|
+
@unrouted_message_processing = true
|
95
95
|
|
96
96
|
ensure_message_is_unrouted!(return_info, properties, message)
|
97
97
|
|
@@ -103,19 +103,22 @@ module BunnyPublisher
|
|
103
103
|
end
|
104
104
|
run_callback(:after_republish, return_info, properties, message)
|
105
105
|
|
106
|
-
@unrouted_message = false
|
107
106
|
result
|
107
|
+
ensure
|
108
|
+
@unrouted_message_processing = false
|
108
109
|
end
|
109
110
|
|
110
111
|
def setup_queue_for_republish(return_info, properties, message)
|
111
|
-
|
112
|
+
@republish_mutex.synchronize do
|
113
|
+
ensure_republish_connection!
|
112
114
|
|
113
|
-
|
115
|
+
queue = declare_republish_queue(return_info, properties, message)
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
# default exchange already has bindings with queues
|
118
|
+
declare_republish_queue_binding(queue, return_info, properties, message) unless republish_exchange.name == ''
|
117
119
|
|
118
|
-
|
120
|
+
republish_channel.deregister_queue(queue) # we are not going to work with this queue in this channel
|
121
|
+
end
|
119
122
|
end
|
120
123
|
|
121
124
|
def ensure_message_is_unrouted!(return_info, properties, message)
|
@@ -130,13 +133,13 @@ module BunnyPublisher
|
|
130
133
|
def wait_for_unrouted_messages_processing(timeout:)
|
131
134
|
sleep(0.05) # gives exchange some time to receive retuned message
|
132
135
|
|
133
|
-
return unless @
|
136
|
+
return unless @unrouted_message_processing
|
134
137
|
|
135
138
|
puts("Waiting up to #{timeout} seconds for unrouted messages handling")
|
136
139
|
|
137
|
-
Timeout.timeout(timeout) { sleep 0.01 while @
|
140
|
+
Timeout.timeout(timeout) { sleep 0.01 while @unrouted_message_processing }
|
138
141
|
rescue Timeout::Error
|
139
|
-
|
142
|
+
warn('Some unrouted messages are lost on process exit!')
|
140
143
|
end
|
141
144
|
end
|
142
145
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BunnyPublisher
|
4
|
+
# Test module prevents real connections to be made and replaces exchange with array-based TestExchange
|
5
|
+
module Test
|
6
|
+
class TestExchange < Array
|
7
|
+
def publish(message, options = {})
|
8
|
+
self << [message, options]
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
# in case if used with Mandatory module included
|
13
|
+
def on_return(&block); end
|
14
|
+
end
|
15
|
+
|
16
|
+
def exchange
|
17
|
+
@exchange ||= TestExchange.new
|
18
|
+
end
|
19
|
+
|
20
|
+
alias messages exchange
|
21
|
+
|
22
|
+
def flush!
|
23
|
+
exchange.clear
|
24
|
+
end
|
25
|
+
|
26
|
+
alias close flush!
|
27
|
+
alias stop flush!
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def ensure_connection!; end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny-publisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Sharshenov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.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.3.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
47
|
+
version: '2.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
54
|
+
version: '2.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry-byebug
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,34 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '1.13'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
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
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '3.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '3.0'
|
97
97
|
description: AMQP publisher for RabbitMQ based on Bunny
|
98
98
|
email:
|
99
99
|
- rustam@sharshenov.com
|
@@ -101,22 +101,16 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
|
-
- ".rubocop.yml"
|
107
|
-
- ".travis.yml"
|
108
104
|
- CHANGELOG.md
|
109
|
-
- Gemfile
|
110
105
|
- LICENSE.txt
|
111
106
|
- README.md
|
112
|
-
- Rakefile
|
113
|
-
- bunny-publisher.gemspec
|
114
107
|
- lib/bunny/publisher.rb
|
115
108
|
- lib/bunny_publisher.rb
|
116
109
|
- lib/bunny_publisher/base.rb
|
117
110
|
- lib/bunny_publisher/callbacks.rb
|
118
111
|
- lib/bunny_publisher/errors.rb
|
119
112
|
- lib/bunny_publisher/mandatory.rb
|
113
|
+
- lib/bunny_publisher/test.rb
|
120
114
|
- lib/bunny_publisher/version.rb
|
121
115
|
homepage: https://github.com/veeqo/bunny-publisher
|
122
116
|
licenses:
|
@@ -133,14 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
127
|
requirements:
|
134
128
|
- - ">="
|
135
129
|
- !ruby/object:Gem::Version
|
136
|
-
version: '
|
130
|
+
version: '2.5'
|
137
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
132
|
requirements:
|
139
133
|
- - ">="
|
140
134
|
- !ruby/object:Gem::Version
|
141
135
|
version: '0'
|
142
136
|
requirements: []
|
143
|
-
rubygems_version: 3.0.
|
137
|
+
rubygems_version: 3.0.6
|
144
138
|
signing_key:
|
145
139
|
specification_version: 4
|
146
140
|
summary: AMQP publisher for RabbitMQ based on Bunny
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
---
|
2
|
-
dist: xenial
|
3
|
-
language: ruby
|
4
|
-
cache: bundler
|
5
|
-
rvm:
|
6
|
-
- 2.5.8
|
7
|
-
- 2.6.6
|
8
|
-
- 2.7.1
|
9
|
-
env:
|
10
|
-
- BUNNY_VERSION="~> 2.15"
|
11
|
-
- BUNNY_VERSION="2.10.0"
|
12
|
-
|
13
|
-
before_install: gem install bundler
|
14
|
-
before_script:
|
15
|
-
- ".ci/install_rabbitmq"
|
16
|
-
bundler_args: --jobs 3 --retry 3
|
data/Gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
-
|
7
|
-
# Specify your gem's dependencies in bunny-publisher.gemspec
|
8
|
-
gemspec
|
9
|
-
|
10
|
-
gem 'bunny', ENV.fetch('BUNNY_VERSION', '~> 2.15')
|
data/Rakefile
DELETED
data/bunny-publisher.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
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 'bunny_publisher/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'bunny-publisher'
|
9
|
-
spec.version = BunnyPublisher::VERSION
|
10
|
-
spec.authors = ['Rustam Sharshenov']
|
11
|
-
spec.email = ['rustam@sharshenov.com']
|
12
|
-
|
13
|
-
spec.summary = 'AMQP publisher for RabbitMQ based on Bunny'
|
14
|
-
spec.description = 'AMQP publisher for RabbitMQ based on Bunny'
|
15
|
-
spec.homepage = 'https://github.com/veeqo/bunny-publisher'
|
16
|
-
spec.license = 'MIT'
|
17
|
-
|
18
|
-
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
-
spec.metadata['changelog_uri'] = 'https://github.com/veeqo/bunny-publisher/blob/master/CHANGELOG.md'
|
22
|
-
end
|
23
|
-
|
24
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|\.ci)/}) }
|
26
|
-
end
|
27
|
-
spec.require_paths = ['lib']
|
28
|
-
|
29
|
-
spec.add_dependency 'bunny', '~> 2.10'
|
30
|
-
|
31
|
-
spec.add_development_dependency 'bundler'
|
32
|
-
spec.add_development_dependency 'pry-byebug'
|
33
|
-
spec.add_development_dependency 'rabbitmq_http_api_client', '~> 1.13'
|
34
|
-
spec.add_development_dependency 'rake'
|
35
|
-
spec.add_development_dependency 'rspec'
|
36
|
-
end
|