rabbit_messaging 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e91522365755a8fd4311204e3419daed0e81cbc30a4e47d72e8db6ff7a1230b2
4
- data.tar.gz: 470eecbf8666625d4ca314d01c24c4d1de2b8a3896838bd127d86bc9e43226b8
3
+ metadata.gz: dd33b8817709c4f36e9ae42150aefbf6b9430ea6a764e9b57328b322ac8a092d
4
+ data.tar.gz: 03d3b93e6a05a28376f171921b52858ecbbd2bcf12a25f0e7bf51c53579048ce
5
5
  SHA512:
6
- metadata.gz: 35e7ba113d41de62dc9a5eceb5c7dc47e1398182889af1c54025d87f2c1bc05fc49d80d45a791151773843c23669720f5edc10f05cadc153820c6532b248186b
7
- data.tar.gz: 75332f60efe6ed6485bf4dc8e36162f5e7d39f5df6134ca7a16c1ba9223ab06f790ee76a7a1892bfd3dd20411164abdf8d6947ca0fbbd7a670453ec3e9a9f8f0
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.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- rabbit_messaging (1.3.0)
11
+ rabbit_messaging (1.4.0)
12
12
  bunny (~> 2.0)
13
13
  kicks
14
14
  tainbox
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
@@ -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
- pool.with_channel msg.confirm_select? do |ch|
17
- ch.basic_publish *msg.basic_publish_args
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
- raise MessageNotDelivered, "RabbitMQ message not delivered: #{msg}" \
20
- if msg.confirm_select? && !ch.wait_for_confirms
21
+ raise MessageNotDelivered, "RabbitMQ message not delivered: #{msg}" \
22
+ if msg.confirm_select? && !ch.wait_for_confirms
21
23
 
22
- log msg
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
@@ -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
@@ -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
- # args and info have custom rabbit classes, have to convert them to hash
13
- receive_message(message, delivery_info.to_h, arguments.to_h)
14
- ack!
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rabbit
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.0"
5
5
  end
data/lib/rabbit.rb CHANGED
@@ -30,6 +30,9 @@ 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
38
  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.3.0
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-02-11 00:00:00.000000000 Z
11
+ date: 2025-04-14 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: bunny
@@ -96,6 +97,7 @@ files:
96
97
  homepage: https://github.com/umbrellio/rabbit_messaging
97
98
  licenses: []
98
99
  metadata: {}
100
+ post_install_message:
99
101
  rdoc_options: []
100
102
  require_paths:
101
103
  - lib
@@ -110,7 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  - !ruby/object:Gem::Version
111
113
  version: '0'
112
114
  requirements: []
113
- rubygems_version: 3.6.3
115
+ rubygems_version: 3.5.3
116
+ signing_key:
114
117
  specification_version: 4
115
118
  summary: Rabbit (Rabbit Messaging)
116
119
  test_files: []