rabbit_messaging 1.3.0 → 1.5.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 +16 -0
- data/Gemfile.lock +1 -1
- data/README.md +32 -0
- data/lib/rabbit/helper.rb +17 -0
- data/lib/rabbit/publishing.rb +35 -13
- data/lib/rabbit/receiving/receive.rb +10 -3
- data/lib/rabbit/receiving/worker.rb +21 -3
- data/lib/rabbit/version.rb +1 -1
- data/lib/rabbit.rb +4 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da5252952f99344a807697e8c3bedd069160a41af4709af9b0120b5d0e486e90
|
4
|
+
data.tar.gz: c35f327f41ab3f2d9f358c1ac4d4e3bf688b9c2922da5624d96d61c70f57356c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b403d0df5c612f549d310bf9170b9ea7046fdbc65afbce868a4c291297f0b8060d4840b6a19fd7808a775f3d52946f7ebe1c79c23ef10133a2e37bc0847d2ad1
|
7
|
+
data.tar.gz: b4de5dda09cf5dc34ac46c7f8352aa840e477fddaca799ba80435d4ce4c72f525594075042d639145df0e3f424857c2e149709b6e506080be99c391823cb38c0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.5.0] - 2025-05-19
|
5
|
+
### Added
|
6
|
+
- Added ability to split log message into parts
|
7
|
+
- Optional `logger_message_size_limit` config for message size limit
|
8
|
+
|
9
|
+
## [1.4.0] - 2025-03-10
|
10
|
+
### Added
|
11
|
+
- Introduced new configuration attributes for connection reset handling:
|
12
|
+
- `connection_reset_max_retries`
|
13
|
+
- `connection_reset_timeout`
|
14
|
+
- `connection_reset_exceptions`
|
15
|
+
### Changed
|
16
|
+
- Improved handling of `Bunny::ConnectionClosedError`:
|
17
|
+
- Added automatic reconnection with retries.
|
18
|
+
- Implemented configurable timeouts between retries.
|
19
|
+
|
4
20
|
## [1.2.0] - 2025-02-10
|
5
21
|
### Added
|
6
22
|
- Add `ExponentialBackoffHandler` for handling errors in rabbit messages
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -127,6 +127,38 @@ 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
|
+
```
|
154
|
+
|
155
|
+
- `logger_message_size_limit` (`Integer`)
|
156
|
+
|
157
|
+
Maximum logger message size. Split message to parts if message is more than limit. Default: 9500.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
config.logger_message_size_limit = 9500
|
161
|
+
```
|
130
162
|
---
|
131
163
|
|
132
164
|
### Client
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rabbit
|
4
|
+
module Helper
|
5
|
+
def self.generate_message(message_part, parts, index)
|
6
|
+
if parts == 1
|
7
|
+
message_part
|
8
|
+
elsif index.zero?
|
9
|
+
"#{message_part}..."
|
10
|
+
elsif index == parts - 1
|
11
|
+
"...#{message_part}"
|
12
|
+
else
|
13
|
+
"...#{message_part}..."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
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
|
@@ -54,7 +66,17 @@ module Rabbit
|
|
54
66
|
message.event, message.confirm_select? ? "confirm" : "no-confirm"
|
55
67
|
]
|
56
68
|
|
57
|
-
|
69
|
+
message_parts = JSON.dump(message.data)
|
70
|
+
.scan(/.{1,#{Rabbit.config.logger_message_size_limit}}/)
|
71
|
+
|
72
|
+
message_parts.each_with_index do |message_part, index|
|
73
|
+
message = Rabbit::Helper.generate_message(message_part, message_parts.size, index)
|
74
|
+
@logger.debug "#{metadata.join ' / '}: #{message}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def reinitialize_channels_pool
|
79
|
+
MUTEX.synchronize { @pool = ChannelsPool.new(create_client) }
|
58
80
|
end
|
59
81
|
end
|
60
82
|
end
|
@@ -5,6 +5,7 @@ require "tainbox"
|
|
5
5
|
require "rabbit"
|
6
6
|
require "rabbit/receiving/queue"
|
7
7
|
require "rabbit/receiving/job"
|
8
|
+
require "rabbit/helper"
|
8
9
|
|
9
10
|
class Rabbit::Receiving::Receive
|
10
11
|
include Tainbox
|
@@ -21,9 +22,15 @@ class Rabbit::Receiving::Receive
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def log!
|
24
|
-
Rabbit.config.
|
25
|
-
|
26
|
-
|
25
|
+
message_parts = message.scan(/.{1,#{Rabbit.config.logger_message_size_limit}}/)
|
26
|
+
|
27
|
+
message_parts.each_with_index do |message_part, index|
|
28
|
+
message = Rabbit::Helper.generate_message(message_part, message_parts.size, index)
|
29
|
+
|
30
|
+
Rabbit.config.receive_logger.debug(
|
31
|
+
[message, delivery_info, arguments].join(" / "),
|
32
|
+
)
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
def process_message
|
@@ -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,6 +30,10 @@ 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]
|
36
|
+
attribute :logger_message_size_limit, Integer, default: 9_500
|
33
37
|
|
34
38
|
attribute :receive_logger, default: lambda {
|
35
39
|
Logger.new(Rabbit.root.join("log", "incoming_rabbit_messages.log"))
|
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.5.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-05-19 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
14
|
name: bunny
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- lib/rabbit/daemon.rb
|
77
78
|
- lib/rabbit/event_handler.rb
|
78
79
|
- lib/rabbit/extensions/bunny/channel.rb
|
80
|
+
- lib/rabbit/helper.rb
|
79
81
|
- lib/rabbit/publishing.rb
|
80
82
|
- lib/rabbit/publishing/channels_pool.rb
|
81
83
|
- lib/rabbit/publishing/job.rb
|
@@ -96,6 +98,7 @@ files:
|
|
96
98
|
homepage: https://github.com/umbrellio/rabbit_messaging
|
97
99
|
licenses: []
|
98
100
|
metadata: {}
|
101
|
+
post_install_message:
|
99
102
|
rdoc_options: []
|
100
103
|
require_paths:
|
101
104
|
- lib
|
@@ -110,7 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
113
|
- !ruby/object:Gem::Version
|
111
114
|
version: '0'
|
112
115
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
116
|
+
rubygems_version: 3.5.3
|
117
|
+
signing_key:
|
114
118
|
specification_version: 4
|
115
119
|
summary: Rabbit (Rabbit Messaging)
|
116
120
|
test_files: []
|