rabbit_messaging 1.2.0 → 1.4.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -5
- data/Gemfile.lock +60 -194
- data/README.md +24 -0
- data/config/sneakers.yml +9 -0
- data/environments/development.rb +1 -5
- data/lib/rabbit/daemon.rb +2 -9
- data/lib/rabbit/publishing.rb +30 -14
- data/lib/rabbit/receiving/job.rb +7 -6
- data/lib/rabbit/receiving/worker.rb +21 -3
- data/lib/rabbit/version.rb +1 -1
- data/lib/rabbit.rb +24 -4
- data/rabbit_messaging.gemspec +1 -3
- metadata +7 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd33b8817709c4f36e9ae42150aefbf6b9430ea6a764e9b57328b322ac8a092d
|
4
|
+
data.tar.gz: 03d3b93e6a05a28376f171921b52858ecbbd2bcf12a25f0e7bf51c53579048ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 190b007690a90b6373a07a7f2f425265dbb2209b9f00fc268e99e3d77493c764671a4979ac3da34981c55fa5370c06d30bfb6f69b4af0dded14d5504cacc599d
|
7
|
+
data.tar.gz: cd210853510b86ff23022035f8c5e0fa169cc46504288ff15c2d6ffec62069da575e2f4bb6cad6bec0e4ee3fb87d9f2cad9cb00fc936ccd1f887f4ac9271f510
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.4.0] - 2025-03-10
|
5
|
+
### Added
|
6
|
+
- Introduced new configuration attributes for connection reset handling:
|
7
|
+
- `connection_reset_max_retries`
|
8
|
+
- `connection_reset_timeout`
|
9
|
+
- `connection_reset_exceptions`
|
10
|
+
### Changed
|
11
|
+
- Improved handling of `Bunny::ConnectionClosedError`:
|
12
|
+
- Added automatic reconnection with retries.
|
13
|
+
- Implemented configurable timeouts between retries.
|
14
|
+
|
4
15
|
## [1.2.0] - 2025-02-10
|
5
16
|
### Added
|
6
17
|
- Add `ExponentialBackoffHandler` for handling errors in rabbit messages
|
data/Gemfile
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem "benchmark"
|
7
|
-
gem "bundler"
|
8
|
-
gem "ostruct"
|
9
6
|
gem "pry"
|
10
|
-
gem "
|
11
|
-
gem "rake"
|
7
|
+
gem "reline"
|
12
8
|
gem "rspec"
|
13
9
|
gem "rspec-its"
|
14
10
|
gem "rubocop-config-umbrellio"
|
15
11
|
gem "simplecov"
|
16
12
|
gem "simplecov-lcov"
|
13
|
+
|
14
|
+
gem "activejob"
|
15
|
+
gem "activerecord"
|
17
16
|
gem "sneakers_handlers", github: "umbrellio/sneakers_handlers"
|
data/Gemfile.lock
CHANGED
@@ -8,268 +8,139 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
rabbit_messaging (1.
|
11
|
+
rabbit_messaging (1.4.0)
|
12
12
|
bunny (~> 2.0)
|
13
|
-
kicks
|
14
|
-
lamian
|
15
|
-
rails (>= 6.1)
|
13
|
+
kicks
|
16
14
|
tainbox
|
17
15
|
|
18
16
|
GEM
|
19
17
|
remote: https://rubygems.org/
|
20
18
|
specs:
|
21
|
-
|
22
|
-
|
23
|
-
activesupport (= 7.1.4.1)
|
24
|
-
nio4r (~> 2.0)
|
25
|
-
websocket-driver (>= 0.6.1)
|
26
|
-
zeitwerk (~> 2.6)
|
27
|
-
actionmailbox (7.1.4.1)
|
28
|
-
actionpack (= 7.1.4.1)
|
29
|
-
activejob (= 7.1.4.1)
|
30
|
-
activerecord (= 7.1.4.1)
|
31
|
-
activestorage (= 7.1.4.1)
|
32
|
-
activesupport (= 7.1.4.1)
|
33
|
-
mail (>= 2.7.1)
|
34
|
-
net-imap
|
35
|
-
net-pop
|
36
|
-
net-smtp
|
37
|
-
actionmailer (7.1.4.1)
|
38
|
-
actionpack (= 7.1.4.1)
|
39
|
-
actionview (= 7.1.4.1)
|
40
|
-
activejob (= 7.1.4.1)
|
41
|
-
activesupport (= 7.1.4.1)
|
42
|
-
mail (~> 2.5, >= 2.5.4)
|
43
|
-
net-imap
|
44
|
-
net-pop
|
45
|
-
net-smtp
|
46
|
-
rails-dom-testing (~> 2.2)
|
47
|
-
actionpack (7.1.4.1)
|
48
|
-
actionview (= 7.1.4.1)
|
49
|
-
activesupport (= 7.1.4.1)
|
50
|
-
nokogiri (>= 1.8.5)
|
51
|
-
racc
|
52
|
-
rack (>= 2.2.4)
|
53
|
-
rack-session (>= 1.0.1)
|
54
|
-
rack-test (>= 0.6.3)
|
55
|
-
rails-dom-testing (~> 2.2)
|
56
|
-
rails-html-sanitizer (~> 1.6)
|
57
|
-
actiontext (7.1.4.1)
|
58
|
-
actionpack (= 7.1.4.1)
|
59
|
-
activerecord (= 7.1.4.1)
|
60
|
-
activestorage (= 7.1.4.1)
|
61
|
-
activesupport (= 7.1.4.1)
|
62
|
-
globalid (>= 0.6.0)
|
63
|
-
nokogiri (>= 1.8.5)
|
64
|
-
actionview (7.1.4.1)
|
65
|
-
activesupport (= 7.1.4.1)
|
66
|
-
builder (~> 3.1)
|
67
|
-
erubi (~> 1.11)
|
68
|
-
rails-dom-testing (~> 2.2)
|
69
|
-
rails-html-sanitizer (~> 1.6)
|
70
|
-
activejob (7.1.4.1)
|
71
|
-
activesupport (= 7.1.4.1)
|
19
|
+
activejob (7.2.2.1)
|
20
|
+
activesupport (= 7.2.2.1)
|
72
21
|
globalid (>= 0.3.6)
|
73
|
-
activemodel (7.
|
74
|
-
activesupport (= 7.
|
75
|
-
activerecord (7.
|
76
|
-
activemodel (= 7.
|
77
|
-
activesupport (= 7.
|
22
|
+
activemodel (7.2.2.1)
|
23
|
+
activesupport (= 7.2.2.1)
|
24
|
+
activerecord (7.2.2.1)
|
25
|
+
activemodel (= 7.2.2.1)
|
26
|
+
activesupport (= 7.2.2.1)
|
78
27
|
timeout (>= 0.4.0)
|
79
|
-
|
80
|
-
actionpack (= 7.1.4.1)
|
81
|
-
activejob (= 7.1.4.1)
|
82
|
-
activerecord (= 7.1.4.1)
|
83
|
-
activesupport (= 7.1.4.1)
|
84
|
-
marcel (~> 1.0)
|
85
|
-
activesupport (7.1.4.1)
|
28
|
+
activesupport (7.2.2.1)
|
86
29
|
base64
|
30
|
+
benchmark (>= 0.3)
|
87
31
|
bigdecimal
|
88
|
-
concurrent-ruby (~> 1.0, >= 1.
|
32
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
89
33
|
connection_pool (>= 2.2.5)
|
90
34
|
drb
|
91
35
|
i18n (>= 1.6, < 2)
|
36
|
+
logger (>= 1.4.2)
|
92
37
|
minitest (>= 5.1)
|
93
|
-
|
94
|
-
tzinfo (~> 2.0)
|
38
|
+
securerandom (>= 0.3)
|
39
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
95
40
|
amq-protocol (2.3.2)
|
96
41
|
ast (2.4.2)
|
97
42
|
base64 (0.2.0)
|
98
43
|
benchmark (0.4.0)
|
99
|
-
bigdecimal (3.1.
|
100
|
-
builder (3.3.0)
|
44
|
+
bigdecimal (3.1.9)
|
101
45
|
bunny (2.23.0)
|
102
46
|
amq-protocol (~> 2.3, >= 2.3.1)
|
103
47
|
sorted_set (~> 1, >= 1.0.2)
|
104
48
|
coderay (1.1.3)
|
105
|
-
concurrent-ruby (1.3.
|
106
|
-
connection_pool (2.
|
107
|
-
crass (1.0.6)
|
108
|
-
date (3.3.4)
|
49
|
+
concurrent-ruby (1.3.5)
|
50
|
+
connection_pool (2.5.0)
|
109
51
|
diff-lcs (1.5.1)
|
110
52
|
docile (1.4.1)
|
111
53
|
drb (2.2.1)
|
112
|
-
erubi (1.13.0)
|
113
54
|
globalid (1.2.1)
|
114
55
|
activesupport (>= 6.1)
|
115
|
-
i18n (1.14.
|
56
|
+
i18n (1.14.7)
|
116
57
|
concurrent-ruby (~> 1.0)
|
117
|
-
io-console (0.
|
118
|
-
|
119
|
-
|
120
|
-
reline (>= 0.4.2)
|
121
|
-
json (2.7.2)
|
122
|
-
kicks (3.1.0)
|
58
|
+
io-console (0.8.0)
|
59
|
+
json (2.10.0)
|
60
|
+
kicks (3.2.0)
|
123
61
|
bunny (~> 2.19)
|
124
62
|
concurrent-ruby (~> 1.0)
|
125
63
|
rake (>= 12.3, < 14.0)
|
126
64
|
serverengine (~> 2.1)
|
127
65
|
thor
|
128
|
-
|
129
|
-
|
130
|
-
language_server-protocol (3.17.0.3)
|
131
|
-
logger (1.6.1)
|
132
|
-
loofah (2.23.1)
|
133
|
-
crass (~> 1.0.2)
|
134
|
-
nokogiri (>= 1.12.0)
|
135
|
-
mail (2.8.1)
|
136
|
-
mini_mime (>= 0.1.1)
|
137
|
-
net-imap
|
138
|
-
net-pop
|
139
|
-
net-smtp
|
140
|
-
marcel (1.0.4)
|
66
|
+
language_server-protocol (3.17.0.4)
|
67
|
+
logger (1.6.5)
|
141
68
|
method_source (1.1.0)
|
142
|
-
|
143
|
-
mini_portile2 (2.8.8)
|
144
|
-
minitest (5.25.1)
|
145
|
-
mutex_m (0.2.0)
|
146
|
-
net-imap (0.4.17)
|
147
|
-
date
|
148
|
-
net-protocol
|
149
|
-
net-pop (0.1.2)
|
150
|
-
net-protocol
|
151
|
-
net-protocol (0.2.2)
|
152
|
-
timeout
|
153
|
-
net-smtp (0.5.0)
|
154
|
-
net-protocol
|
155
|
-
nio4r (2.7.3)
|
156
|
-
nokogiri (1.16.8)
|
157
|
-
mini_portile2 (~> 2.8.2)
|
158
|
-
racc (~> 1.4)
|
159
|
-
ostruct (0.6.1)
|
69
|
+
minitest (5.25.4)
|
160
70
|
parallel (1.26.3)
|
161
|
-
parser (3.3.
|
71
|
+
parser (3.3.7.1)
|
162
72
|
ast (~> 2.4.1)
|
163
73
|
racc
|
164
|
-
pry (0.
|
74
|
+
pry (0.15.2)
|
165
75
|
coderay (~> 1.1)
|
166
76
|
method_source (~> 1.0)
|
167
|
-
psych (5.1.2)
|
168
|
-
stringio
|
169
77
|
racc (1.8.1)
|
170
|
-
rack (3.1.
|
171
|
-
rack-session (2.0.0)
|
172
|
-
rack (>= 3.0.0)
|
173
|
-
rack-test (2.1.0)
|
174
|
-
rack (>= 1.3)
|
175
|
-
rackup (2.1.0)
|
176
|
-
rack (>= 3)
|
177
|
-
webrick (~> 1.8)
|
178
|
-
rails (7.1.4.1)
|
179
|
-
actioncable (= 7.1.4.1)
|
180
|
-
actionmailbox (= 7.1.4.1)
|
181
|
-
actionmailer (= 7.1.4.1)
|
182
|
-
actionpack (= 7.1.4.1)
|
183
|
-
actiontext (= 7.1.4.1)
|
184
|
-
actionview (= 7.1.4.1)
|
185
|
-
activejob (= 7.1.4.1)
|
186
|
-
activemodel (= 7.1.4.1)
|
187
|
-
activerecord (= 7.1.4.1)
|
188
|
-
activestorage (= 7.1.4.1)
|
189
|
-
activesupport (= 7.1.4.1)
|
190
|
-
bundler (>= 1.15.0)
|
191
|
-
railties (= 7.1.4.1)
|
192
|
-
rails-dom-testing (2.2.0)
|
193
|
-
activesupport (>= 5.0.0)
|
194
|
-
minitest
|
195
|
-
nokogiri (>= 1.6)
|
196
|
-
rails-html-sanitizer (1.6.1)
|
197
|
-
loofah (~> 2.21)
|
198
|
-
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
199
|
-
railties (7.1.4.1)
|
200
|
-
actionpack (= 7.1.4.1)
|
201
|
-
activesupport (= 7.1.4.1)
|
202
|
-
irb
|
203
|
-
rackup (>= 1.0.0)
|
204
|
-
rake (>= 12.2)
|
205
|
-
thor (~> 1.0, >= 1.2.2)
|
206
|
-
zeitwerk (~> 2.6)
|
78
|
+
rack (3.1.9)
|
207
79
|
rainbow (3.1.1)
|
208
80
|
rake (13.2.1)
|
209
81
|
rbtree (0.4.6)
|
210
|
-
|
211
|
-
|
212
|
-
regexp_parser (2.9.2)
|
213
|
-
reline (0.5.10)
|
82
|
+
regexp_parser (2.10.0)
|
83
|
+
reline (0.6.0)
|
214
84
|
io-console (~> 0.5)
|
215
85
|
rspec (3.13.0)
|
216
86
|
rspec-core (~> 3.13.0)
|
217
87
|
rspec-expectations (~> 3.13.0)
|
218
88
|
rspec-mocks (~> 3.13.0)
|
219
|
-
rspec-core (3.13.
|
89
|
+
rspec-core (3.13.3)
|
220
90
|
rspec-support (~> 3.13.0)
|
221
91
|
rspec-expectations (3.13.3)
|
222
92
|
diff-lcs (>= 1.2.0, < 2.0)
|
223
93
|
rspec-support (~> 3.13.0)
|
224
|
-
rspec-its (
|
225
|
-
rspec-core (>= 3.
|
226
|
-
rspec-expectations (>= 3.
|
94
|
+
rspec-its (2.0.0)
|
95
|
+
rspec-core (>= 3.13.0)
|
96
|
+
rspec-expectations (>= 3.13.0)
|
227
97
|
rspec-mocks (3.13.2)
|
228
98
|
diff-lcs (>= 1.2.0, < 2.0)
|
229
99
|
rspec-support (~> 3.13.0)
|
230
|
-
rspec-support (3.13.
|
231
|
-
rubocop (1.
|
100
|
+
rspec-support (3.13.2)
|
101
|
+
rubocop (1.69.2)
|
232
102
|
json (~> 2.3)
|
233
103
|
language_server-protocol (>= 3.17.0)
|
234
104
|
parallel (~> 1.10)
|
235
105
|
parser (>= 3.3.0.2)
|
236
106
|
rainbow (>= 2.2.2, < 4.0)
|
237
|
-
regexp_parser (>= 2.
|
238
|
-
rubocop-ast (>= 1.
|
107
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
108
|
+
rubocop-ast (>= 1.36.2, < 2.0)
|
239
109
|
ruby-progressbar (~> 1.7)
|
240
|
-
unicode-display_width (>= 2.4.0, <
|
241
|
-
rubocop-ast (1.
|
110
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
111
|
+
rubocop-ast (1.38.0)
|
242
112
|
parser (>= 3.3.1.0)
|
243
|
-
rubocop-config-umbrellio (1.
|
244
|
-
rubocop (~> 1.
|
113
|
+
rubocop-config-umbrellio (1.69.0.101)
|
114
|
+
rubocop (~> 1.69.0)
|
245
115
|
rubocop-factory_bot (~> 2.26.0)
|
246
|
-
rubocop-performance (~> 1.
|
247
|
-
rubocop-rails (~> 2.
|
116
|
+
rubocop-performance (~> 1.23.0)
|
117
|
+
rubocop-rails (~> 2.28.0)
|
248
118
|
rubocop-rake (~> 0.6.0)
|
249
|
-
rubocop-rspec (~> 3.
|
250
|
-
rubocop-sequel (~> 0.3.
|
119
|
+
rubocop-rspec (~> 3.3.0)
|
120
|
+
rubocop-sequel (~> 0.3.0)
|
251
121
|
rubocop-factory_bot (2.26.1)
|
252
122
|
rubocop (~> 1.61)
|
253
|
-
rubocop-performance (1.
|
123
|
+
rubocop-performance (1.23.1)
|
254
124
|
rubocop (>= 1.48.1, < 2.0)
|
255
125
|
rubocop-ast (>= 1.31.1, < 2.0)
|
256
|
-
rubocop-rails (2.
|
126
|
+
rubocop-rails (2.28.0)
|
257
127
|
activesupport (>= 4.2.0)
|
258
128
|
rack (>= 1.1)
|
259
129
|
rubocop (>= 1.52.0, < 2.0)
|
260
130
|
rubocop-ast (>= 1.31.1, < 2.0)
|
261
131
|
rubocop-rake (0.6.0)
|
262
132
|
rubocop (~> 1.0)
|
263
|
-
rubocop-rspec (3.0
|
133
|
+
rubocop-rspec (3.3.0)
|
264
134
|
rubocop (~> 1.61)
|
265
|
-
rubocop-sequel (0.3.
|
135
|
+
rubocop-sequel (0.3.8)
|
266
136
|
rubocop (~> 1.0)
|
267
137
|
ruby-progressbar (1.13.0)
|
138
|
+
securerandom (0.4.1)
|
268
139
|
serverengine (2.4.0)
|
269
140
|
base64 (~> 0.1)
|
270
141
|
logger (~> 1.4)
|
271
142
|
sigdump (~> 0.2.2)
|
272
|
-
set (1.1.
|
143
|
+
set (1.1.1)
|
273
144
|
sigdump (0.2.5)
|
274
145
|
simplecov (0.22.0)
|
275
146
|
docile (~> 1.1)
|
@@ -281,31 +152,26 @@ GEM
|
|
281
152
|
sorted_set (1.0.3)
|
282
153
|
rbtree
|
283
154
|
set (~> 1.0)
|
284
|
-
stringio (3.1.1)
|
285
155
|
tainbox (2.1.2)
|
286
156
|
activesupport
|
287
157
|
thor (1.3.2)
|
288
|
-
timeout (0.4.
|
158
|
+
timeout (0.4.3)
|
289
159
|
tzinfo (2.0.6)
|
290
160
|
concurrent-ruby (~> 1.0)
|
291
|
-
unicode-display_width (
|
292
|
-
|
293
|
-
|
294
|
-
websocket-extensions (>= 0.1.0)
|
295
|
-
websocket-extensions (0.1.5)
|
296
|
-
zeitwerk (2.6.18)
|
161
|
+
unicode-display_width (3.1.4)
|
162
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
163
|
+
unicode-emoji (4.0.4)
|
297
164
|
|
298
165
|
PLATFORMS
|
166
|
+
arm64-darwin
|
299
167
|
ruby
|
300
168
|
|
301
169
|
DEPENDENCIES
|
302
|
-
|
303
|
-
|
304
|
-
ostruct
|
170
|
+
activejob
|
171
|
+
activerecord
|
305
172
|
pry
|
306
173
|
rabbit_messaging!
|
307
|
-
|
308
|
-
rake
|
174
|
+
reline
|
309
175
|
rspec
|
310
176
|
rspec-its
|
311
177
|
rubocop-config-umbrellio
|
data/README.md
CHANGED
@@ -127,6 +127,30 @@ require "rabbit_messaging"
|
|
127
127
|
- `backoff_handler_max_retries` (`Integer`)
|
128
128
|
|
129
129
|
Number of retries that `ExponentialBackoffHandler` will use before sending job to the error queue. 5 by default.
|
130
|
+
|
131
|
+
- `connection_reset_exceptions` (`Array`)
|
132
|
+
|
133
|
+
Exceptions for reset connection. Default: [`Bunny::ConnectionClosedError`].
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
config.connection_reset_exceptions << MyInterestingException
|
137
|
+
```
|
138
|
+
|
139
|
+
- `connection_reset_max_retries` (`Integer`)
|
140
|
+
|
141
|
+
Maximum number of reconnection attempts after a connection loss. Default: 10.
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
config.connection_reset_max_retries = 20
|
145
|
+
```
|
146
|
+
|
147
|
+
- `connection_reset_timeout` (`Float`)
|
148
|
+
|
149
|
+
The timeout duration before attempting to reset the connection. Default: 0.2 sec.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
config.connection_reset_timeout = 0.2
|
153
|
+
```
|
130
154
|
---
|
131
155
|
|
132
156
|
### Client
|
data/config/sneakers.yml
ADDED
data/environments/development.rb
CHANGED
@@ -6,12 +6,8 @@ Bundler.require(:default, :development)
|
|
6
6
|
require "active_job"
|
7
7
|
require "active_record"
|
8
8
|
|
9
|
-
def Rails.root
|
10
|
-
Pathname.new(__dir__).join("..")
|
11
|
-
end
|
12
|
-
|
13
9
|
ActiveJob::Base.queue_adapter = :inline
|
14
|
-
ActiveJob::Base.logger = Logger.new(
|
10
|
+
ActiveJob::Base.logger = Logger.new(nil)
|
15
11
|
|
16
12
|
Rabbit.config.project_id = "test_project_id"
|
17
13
|
Rabbit.config.group_id = "test_group_id"
|
data/lib/rabbit/daemon.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "sneakers"
|
4
|
-
require "lamian"
|
5
4
|
require "sneakers/runner"
|
6
5
|
|
7
6
|
require "rabbit/extensions/bunny/channel"
|
@@ -12,12 +11,6 @@ module Rabbit
|
|
12
11
|
extend self
|
13
12
|
|
14
13
|
def run(logger: Sneakers.logger)
|
15
|
-
unless logger
|
16
|
-
logger = Logger.new(Rails.root.join("log", "sneakers.log"))
|
17
|
-
logger.level = Logger::DEBUG
|
18
|
-
Lamian.extend_logger(logger)
|
19
|
-
end
|
20
|
-
|
21
14
|
self.logger = logger
|
22
15
|
|
23
16
|
Sneakers.configure(**sneakers_config(logger: logger))
|
@@ -30,7 +23,7 @@ module Rabbit
|
|
30
23
|
end
|
31
24
|
|
32
25
|
def config
|
33
|
-
@config ||=
|
26
|
+
@config ||= Rabbit.sneakers_config
|
34
27
|
end
|
35
28
|
|
36
29
|
def connection
|
@@ -49,7 +42,7 @@ module Rabbit
|
|
49
42
|
def sneakers_config(logger:)
|
50
43
|
{
|
51
44
|
connection: connection,
|
52
|
-
env:
|
45
|
+
env: Rabbit.config.environment,
|
53
46
|
exchange_type: :direct,
|
54
47
|
exchange: Rabbit.config.app_name,
|
55
48
|
hooks: Rabbit.config.hooks,
|
data/lib/rabbit/publishing.rb
CHANGED
@@ -10,23 +10,35 @@ module Rabbit
|
|
10
10
|
|
11
11
|
MUTEX = Mutex.new
|
12
12
|
|
13
|
-
def publish(msg)
|
13
|
+
def publish(msg) # rubocop:disable Metrics/MethodLength
|
14
14
|
return if Rabbit.config.skip_publish?
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
attempt = 0
|
17
|
+
begin
|
18
|
+
pool.with_channel msg.confirm_select? do |ch|
|
19
|
+
ch.basic_publish *msg.basic_publish_args
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
raise MessageNotDelivered, "RabbitMQ message not delivered: #{msg}" \
|
22
|
+
if msg.confirm_select? && !ch.wait_for_confirms
|
21
23
|
|
22
|
-
|
24
|
+
log msg
|
25
|
+
end
|
26
|
+
rescue *Rabbit.config.connection_reset_exceptions => error
|
27
|
+
attempt += 1
|
28
|
+
if attempt <= Rabbit.config.connection_reset_max_retries
|
29
|
+
sleep(Rabbit.config.connection_reset_timeout)
|
30
|
+
reinitialize_channels_pool
|
31
|
+
retry
|
32
|
+
else
|
33
|
+
raise error
|
34
|
+
end
|
35
|
+
rescue Timeout::Error
|
36
|
+
raise MessageNotDelivered, <<~MESSAGE
|
37
|
+
Timeout while sending message #{msg}. Possible reasons:
|
38
|
+
- #{msg.real_exchange_name} exchange is not found
|
39
|
+
- RabbitMQ is extremely high loaded
|
40
|
+
MESSAGE
|
23
41
|
end
|
24
|
-
rescue Timeout::Error
|
25
|
-
raise MessageNotDelivered, <<~MESSAGE
|
26
|
-
Timeout while sending message #{msg}. Possible reasons:
|
27
|
-
- #{msg.real_exchange_name} exchange is not found
|
28
|
-
- RabbitMQ is extremely high loaded
|
29
|
-
MESSAGE
|
30
42
|
end
|
31
43
|
|
32
44
|
def pool
|
@@ -40,8 +52,8 @@ module Rabbit
|
|
40
52
|
end
|
41
53
|
|
42
54
|
def create_client
|
43
|
-
config =
|
44
|
-
config = config[
|
55
|
+
config = Rabbit.sneakers_config
|
56
|
+
config = config[:bunny_options].to_h.symbolize_keys
|
45
57
|
|
46
58
|
Bunny.new(config).start
|
47
59
|
end
|
@@ -56,5 +68,9 @@ module Rabbit
|
|
56
68
|
|
57
69
|
@logger.debug "#{metadata.join ' / '}: #{JSON.dump(message.data)}"
|
58
70
|
end
|
71
|
+
|
72
|
+
def reinitialize_channels_pool
|
73
|
+
MUTEX.synchronize { @pool = ChannelsPool.new(create_client) }
|
74
|
+
end
|
59
75
|
end
|
60
76
|
end
|
data/lib/rabbit/receiving/job.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "lamian"
|
4
|
-
require "active_job"
|
5
|
-
|
6
3
|
require "rabbit"
|
7
4
|
require "rabbit/receiving"
|
8
5
|
require "rabbit/receiving/message"
|
9
6
|
require "rabbit/receiving/handler_resolver"
|
10
7
|
require "rabbit/receiving/malformed_message"
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
begin
|
10
|
+
require "active_job"
|
11
|
+
|
12
|
+
class Rabbit::Receiving::Job < ActiveJob::Base
|
13
|
+
def perform(message, arguments)
|
15
14
|
message = Rabbit::Receiving::Message.build(message, arguments)
|
16
15
|
handler = Rabbit::Receiving::HandlerResolver.handler_for(message)
|
17
16
|
handler.new(message).call
|
@@ -20,4 +19,6 @@ class Rabbit::Receiving::Job < ActiveJob::Base
|
|
20
19
|
Rabbit.config.exception_notifier.call(error)
|
21
20
|
end
|
22
21
|
end
|
22
|
+
rescue LoadError
|
23
|
+
warn "ActiveJob not found! You will need to define Rabbit::Receiving::Job class by yourself."
|
23
24
|
end
|
@@ -9,9 +9,21 @@ class Rabbit::Receiving::Worker
|
|
9
9
|
include Sneakers::Worker
|
10
10
|
|
11
11
|
def work_with_params(message, delivery_info, arguments)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
attempt = 0
|
13
|
+
begin
|
14
|
+
# args and info have custom rabbit classes, have to convert them to hash
|
15
|
+
receive_message(message, delivery_info.to_h, arguments.to_h)
|
16
|
+
ack!
|
17
|
+
rescue *Rabbit.config.connection_reset_exceptions => error
|
18
|
+
attempt += 1
|
19
|
+
if attempt <= Rabbit.config.connection_reset_max_retries
|
20
|
+
sleep(Rabbit.config.connection_reset_timeout)
|
21
|
+
reinitialize_connection
|
22
|
+
retry
|
23
|
+
else
|
24
|
+
handle_error!(error)
|
25
|
+
end
|
26
|
+
end
|
15
27
|
rescue => error
|
16
28
|
handle_error!(error)
|
17
29
|
end
|
@@ -31,4 +43,10 @@ class Rabbit::Receiving::Worker
|
|
31
43
|
sleep 1
|
32
44
|
requeue!
|
33
45
|
end
|
46
|
+
|
47
|
+
def reinitialize_connection
|
48
|
+
stop
|
49
|
+
@queue.instance_variable_set(:@banny, nil)
|
50
|
+
run
|
51
|
+
end
|
34
52
|
end
|
data/lib/rabbit/version.rb
CHANGED
data/lib/rabbit.rb
CHANGED
@@ -30,17 +30,20 @@ module Rabbit
|
|
30
30
|
attribute :skip_publishing_in, default: %i[test development]
|
31
31
|
attribute :use_backoff_handler, :Boolean, default: false
|
32
32
|
attribute :backoff_handler_max_retries, Integer, default: 6
|
33
|
+
attribute :connection_reset_max_retries, Integer, default: 10
|
34
|
+
attribute :connection_reset_timeout, Float, default: 0.2
|
35
|
+
attribute :connection_reset_exceptions, Array, default: [Bunny::ConnectionClosedError]
|
33
36
|
|
34
37
|
attribute :receive_logger, default: lambda {
|
35
|
-
Logger.new(
|
38
|
+
Logger.new(Rabbit.root.join("log", "incoming_rabbit_messages.log"))
|
36
39
|
}
|
37
40
|
|
38
41
|
attribute :publish_logger, default: lambda {
|
39
|
-
Logger.new(
|
42
|
+
Logger.new(Rabbit.root.join("log", "rabbit.log"))
|
40
43
|
}
|
41
44
|
|
42
45
|
attribute :malformed_logger, default: lambda {
|
43
|
-
Logger.new(
|
46
|
+
Logger.new(Rabbit.root.join("log", "malformed_messages.log"))
|
44
47
|
}
|
45
48
|
|
46
49
|
def validate!
|
@@ -48,7 +51,7 @@ module Rabbit
|
|
48
51
|
raise InvalidConfig, "missing group_id" unless group_id
|
49
52
|
raise InvalidConfig, "missing exception_notifier" unless exception_notifier
|
50
53
|
|
51
|
-
unless
|
54
|
+
unless %i[test development production].include?(environment)
|
52
55
|
raise "environment should be one of (test, development, production)"
|
53
56
|
end
|
54
57
|
end
|
@@ -74,6 +77,23 @@ module Rabbit
|
|
74
77
|
@config
|
75
78
|
end
|
76
79
|
|
80
|
+
def root
|
81
|
+
if defined?(Rails)
|
82
|
+
Rails.root
|
83
|
+
else
|
84
|
+
Pathname.new(Dir.pwd)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def sneakers_config
|
89
|
+
if defined?(Rails)
|
90
|
+
Rails.application.config_for("sneakers")
|
91
|
+
else
|
92
|
+
config = YAML.load_file("config/sneakers.yml", aliases: true)
|
93
|
+
config[Rabbit.config.environment.to_s].to_h.symbolize_keys
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
77
97
|
def configure
|
78
98
|
yield(config)
|
79
99
|
config.validate!
|
data/rabbit_messaging.gemspec
CHANGED
@@ -20,8 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_dependency "bunny", "~> 2.0"
|
23
|
-
spec.add_dependency "kicks"
|
24
|
-
spec.add_dependency "lamian"
|
25
|
-
spec.add_dependency "rails", ">= 6.1"
|
23
|
+
spec.add_dependency "kicks"
|
26
24
|
spec.add_dependency "tainbox"
|
27
25
|
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Umbrellio
|
8
|
+
autorequire:
|
8
9
|
bindir: bin
|
9
10
|
cert_chain: []
|
10
|
-
date: 2025-
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
14
|
name: bunny
|
@@ -25,20 +26,6 @@ dependencies:
|
|
25
26
|
version: '2.0'
|
26
27
|
- !ruby/object:Gem::Dependency
|
27
28
|
name: kicks
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
29
|
-
requirements:
|
30
|
-
- - "~>"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3'
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '3'
|
40
|
-
- !ruby/object:Gem::Dependency
|
41
|
-
name: lamian
|
42
29
|
requirement: !ruby/object:Gem::Requirement
|
43
30
|
requirements:
|
44
31
|
- - ">="
|
@@ -51,20 +38,6 @@ dependencies:
|
|
51
38
|
- - ">="
|
52
39
|
- !ruby/object:Gem::Version
|
53
40
|
version: '0'
|
54
|
-
- !ruby/object:Gem::Dependency
|
55
|
-
name: rails
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '6.1'
|
61
|
-
type: :runtime
|
62
|
-
prerelease: false
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '6.1'
|
68
41
|
- !ruby/object:Gem::Dependency
|
69
42
|
name: tainbox
|
70
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +71,7 @@ files:
|
|
98
71
|
- Rakefile
|
99
72
|
- bin/console
|
100
73
|
- bin/setup
|
74
|
+
- config/sneakers.yml
|
101
75
|
- environments/development.rb
|
102
76
|
- lib/rabbit.rb
|
103
77
|
- lib/rabbit/daemon.rb
|
@@ -123,6 +97,7 @@ files:
|
|
123
97
|
homepage: https://github.com/umbrellio/rabbit_messaging
|
124
98
|
licenses: []
|
125
99
|
metadata: {}
|
100
|
+
post_install_message:
|
126
101
|
rdoc_options: []
|
127
102
|
require_paths:
|
128
103
|
- lib
|
@@ -137,7 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
112
|
- !ruby/object:Gem::Version
|
138
113
|
version: '0'
|
139
114
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.5.3
|
116
|
+
signing_key:
|
141
117
|
specification_version: 4
|
142
118
|
summary: Rabbit (Rabbit Messaging)
|
143
119
|
test_files: []
|