rabbit_messaging 1.4.0 → 1.6.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/.rubocop.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -4
- data/README.md +8 -2
- data/bin/console +1 -3
- data/lib/rabbit/event_handler.rb +19 -12
- data/lib/rabbit/helper.rb +17 -0
- data/lib/rabbit/publishing/message.rb +20 -21
- data/lib/rabbit/publishing.rb +7 -1
- data/lib/rabbit/receiving/message.rb +35 -12
- data/lib/rabbit/receiving/receive.rb +16 -9
- data/lib/rabbit/version.rb +1 -1
- data/lib/rabbit.rb +82 -33
- data/rabbit_messaging.gemspec +0 -1
- metadata +4 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8382b750cf7777dc5870a678a6cdbb6868debf75cce98cfabb92770bf418ba
|
4
|
+
data.tar.gz: 3a77171c83255cfccf856c850c4e4586dbd193415ac169b21ab93515a12d0191
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ad7bcf9d06545805489937586fb8608d8fb396e4b10c4d25a5f3ceaac9bd719857047bdf222255745ffd44290c15797e1cab514cb0a0c21c6c27b8868ee1544
|
7
|
+
data.tar.gz: 5616808defed040cb3161746a006d5b2798eeb837f7a566e22608691f9a12a0434c483adc8d90dc75449547c4754c21759e1ddc59499fb763a50ad19195c4ae7
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
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
|
+
|
4
9
|
## [1.4.0] - 2025-03-10
|
5
10
|
### Added
|
6
11
|
- Introduced new configuration attributes for connection reset handling:
|
data/Gemfile.lock
CHANGED
@@ -8,10 +8,9 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
rabbit_messaging (1.
|
11
|
+
rabbit_messaging (1.6.0)
|
12
12
|
bunny (~> 2.0)
|
13
13
|
kicks
|
14
|
-
tainbox
|
15
14
|
|
16
15
|
GEM
|
17
16
|
remote: https://rubygems.org/
|
@@ -152,8 +151,6 @@ GEM
|
|
152
151
|
sorted_set (1.0.3)
|
153
152
|
rbtree
|
154
153
|
set (~> 1.0)
|
155
|
-
tainbox (2.1.2)
|
156
|
-
activesupport
|
157
154
|
thor (1.3.2)
|
158
155
|
timeout (0.4.3)
|
159
156
|
tzinfo (2.0.6)
|
data/README.md
CHANGED
@@ -151,6 +151,14 @@ require "rabbit_messaging"
|
|
151
151
|
```ruby
|
152
152
|
config.connection_reset_timeout = 0.2
|
153
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
|
+
```
|
154
162
|
---
|
155
163
|
|
156
164
|
### Client
|
@@ -200,8 +208,6 @@ to teardown and setup external connections between daemon restarts, for example
|
|
200
208
|
Rabbit.config.handler_resolver_callable = -> (group_id, event) { "recivers/#{group_id}/#{event}".camelize.constantize }
|
201
209
|
```
|
202
210
|
|
203
|
-
They use powerful `Tainbox` api to handle message data. Project_id also passed to them.
|
204
|
-
|
205
211
|
If you wish so, you can override `initialize(message)`, where message is an object
|
206
212
|
with simple api (@see lib/rabbit/receiving/message.rb)
|
207
213
|
|
data/bin/console
CHANGED
data/lib/rabbit/event_handler.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "tainbox"
|
4
3
|
require "active_support/core_ext/class/attribute"
|
5
4
|
|
6
5
|
class Rabbit::EventHandler
|
7
|
-
|
6
|
+
attr_accessor :project_id, :data, :message_info
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
attribute :message_info
|
8
|
+
class << self
|
9
|
+
attr_accessor :queue, :ignore_queue_conversion, :additional_job_configs
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def inherited(subclass)
|
12
|
+
super
|
13
|
+
subclass.ignore_queue_conversion = false
|
14
|
+
subclass.additional_job_configs = {}
|
15
|
+
end
|
16
16
|
|
17
|
-
class << self
|
18
17
|
private
|
19
18
|
|
20
19
|
def queue_as(queue = nil, &block)
|
@@ -31,9 +30,17 @@ class Rabbit::EventHandler
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def initialize(message)
|
34
|
-
|
35
|
-
|
36
|
-
self.
|
33
|
+
assign_attributes(message.data)
|
34
|
+
|
35
|
+
self.data = message.data
|
36
|
+
self.project_id = message.project_id
|
37
37
|
self.message_info = message.arguments
|
38
38
|
end
|
39
|
+
|
40
|
+
def assign_attributes(attrs = {})
|
41
|
+
attrs.each do |key, value|
|
42
|
+
setter = "#{key}="
|
43
|
+
public_send(setter, value) if respond_to?(setter)
|
44
|
+
end
|
45
|
+
end
|
39
46
|
end
|
@@ -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
|
@@ -1,28 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "tainbox"
|
4
|
-
|
5
3
|
module Rabbit::Publishing
|
6
4
|
class Message
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
attribute :event, String
|
11
|
-
attribute :data, default: {}
|
12
|
-
attribute :exchange_name, default: []
|
13
|
-
attribute :confirm_select, default: true
|
14
|
-
attribute :realtime, default: false
|
15
|
-
attribute :headers
|
16
|
-
attribute :message_id
|
5
|
+
attr_accessor :routing_key, :event, :data,
|
6
|
+
:confirm_select, :realtime, :headers, :message_id
|
7
|
+
attr_reader :exchange_name
|
17
8
|
|
18
9
|
alias_method :confirm_select?, :confirm_select
|
19
10
|
alias_method :realtime?, :realtime
|
20
11
|
|
12
|
+
def initialize(attributes = {})
|
13
|
+
self.routing_key = attributes[:routing_key]
|
14
|
+
self.event = attributes[:event]&.to_s
|
15
|
+
self.data = attributes.fetch(:data, {})
|
16
|
+
self.exchange_name = Array(attributes.fetch(:exchange_name, []))
|
17
|
+
self.confirm_select = attributes.fetch(:confirm_select, true)
|
18
|
+
self.realtime = attributes.fetch(:realtime, false)
|
19
|
+
self.headers = attributes.fetch(:headers, {})
|
20
|
+
self.message_id = attributes[:message_id]
|
21
|
+
end
|
22
|
+
|
21
23
|
def to_hash
|
22
|
-
{
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
instance_variables.each_with_object({}) do |var, hash|
|
25
|
+
key = var.to_s.delete("@").to_sym
|
26
|
+
value = instance_variable_get(var)
|
27
|
+
hash[key] = value
|
28
|
+
end.merge(data: JSON.parse(data.to_json))
|
26
29
|
end
|
27
30
|
|
28
31
|
def to_s
|
@@ -49,15 +52,11 @@ module Rabbit::Publishing
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def exchange_name=(names)
|
52
|
-
|
55
|
+
@exchange_name = Array(names).map(&:to_s)
|
53
56
|
end
|
54
57
|
|
55
58
|
def real_exchange_name
|
56
59
|
[Rabbit.config.group_id, Rabbit.config.project_id, *exchange_name].join(".")
|
57
60
|
end
|
58
|
-
|
59
|
-
def headers
|
60
|
-
super || {}
|
61
|
-
end
|
62
61
|
end
|
63
62
|
end
|
data/lib/rabbit/publishing.rb
CHANGED
@@ -66,7 +66,13 @@ module Rabbit
|
|
66
66
|
message.event, message.confirm_select? ? "confirm" : "no-confirm"
|
67
67
|
]
|
68
68
|
|
69
|
-
|
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
|
70
76
|
end
|
71
77
|
|
72
78
|
def reinitialize_channels_pool
|
@@ -1,20 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "tainbox"
|
4
|
-
|
5
3
|
require "rabbit/receiving/malformed_message"
|
6
4
|
|
7
5
|
module Rabbit::Receiving
|
8
6
|
class Message
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attribute :project_id
|
13
|
-
attribute :message_id
|
14
|
-
attribute :event
|
15
|
-
attribute :data
|
16
|
-
attribute :arguments
|
17
|
-
attribute :original_message
|
7
|
+
attr_accessor :group_id, :project_id, :message_id,
|
8
|
+
:event, :arguments, :original_message
|
9
|
+
attr_reader :data
|
18
10
|
|
19
11
|
def self.build(message, arguments)
|
20
12
|
group_id, project_id = arguments.fetch(:app_id).split(".")
|
@@ -29,9 +21,28 @@ module Rabbit::Receiving
|
|
29
21
|
)
|
30
22
|
end
|
31
23
|
|
24
|
+
def initialize(
|
25
|
+
group_id: nil,
|
26
|
+
project_id: nil,
|
27
|
+
message_id: nil,
|
28
|
+
event: nil,
|
29
|
+
data: nil,
|
30
|
+
arguments: nil,
|
31
|
+
original_message: nil
|
32
|
+
)
|
33
|
+
self.group_id = group_id
|
34
|
+
self.project_id = project_id
|
35
|
+
self.message_id = message_id
|
36
|
+
self.event = event
|
37
|
+
self.data = data unless data.nil?
|
38
|
+
self.arguments = arguments
|
39
|
+
self.original_message = original_message
|
40
|
+
end
|
41
|
+
|
32
42
|
def data=(value)
|
33
43
|
self.original_message = value
|
34
|
-
|
44
|
+
parsed = JSON.parse(value).deep_symbolize_keys
|
45
|
+
@data = parsed
|
35
46
|
rescue JSON::ParserError => error
|
36
47
|
mark_as_malformed!("JSON::ParserError: #{error.message}")
|
37
48
|
end
|
@@ -39,5 +50,17 @@ module Rabbit::Receiving
|
|
39
50
|
def mark_as_malformed!(errors = "Error not specified")
|
40
51
|
MalformedMessage.raise!(self, errors, caller(1))
|
41
52
|
end
|
53
|
+
|
54
|
+
def attributes
|
55
|
+
{
|
56
|
+
group_id: group_id,
|
57
|
+
project_id: project_id,
|
58
|
+
message_id: message_id,
|
59
|
+
event: event,
|
60
|
+
data: data,
|
61
|
+
arguments: arguments,
|
62
|
+
original_message: original_message,
|
63
|
+
}
|
64
|
+
end
|
42
65
|
end
|
43
66
|
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "tainbox"
|
4
|
-
|
5
3
|
require "rabbit"
|
6
4
|
require "rabbit/receiving/queue"
|
7
5
|
require "rabbit/receiving/job"
|
6
|
+
require "rabbit/helper"
|
8
7
|
|
9
8
|
class Rabbit::Receiving::Receive
|
10
|
-
|
9
|
+
attr_accessor :message, :delivery_info, :arguments
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def initialize(message: nil, delivery_info: nil, arguments: nil)
|
12
|
+
self.message = message
|
13
|
+
self.delivery_info = delivery_info
|
14
|
+
self.arguments = arguments
|
15
|
+
end
|
15
16
|
|
16
17
|
def call
|
17
18
|
log!
|
@@ -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
|
data/lib/rabbit/version.rb
CHANGED
data/lib/rabbit.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "tainbox"
|
4
|
-
|
5
3
|
require "rabbit/version"
|
6
4
|
require "rabbit/daemon"
|
7
5
|
require "rabbit/publishing"
|
@@ -14,37 +12,74 @@ module Rabbit
|
|
14
12
|
MessageNotDelivered = Class.new(StandardError)
|
15
13
|
|
16
14
|
class Config
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
15
|
+
attr_accessor :group_id,
|
16
|
+
:project_id,
|
17
|
+
:queue_suffix,
|
18
|
+
:hooks,
|
19
|
+
:environment,
|
20
|
+
:queue_name_conversion,
|
21
|
+
:receiving_job_class_callable,
|
22
|
+
:handler_resolver_callable,
|
23
|
+
:exception_notifier,
|
24
|
+
:before_receiving_hooks,
|
25
|
+
:after_receiving_hooks,
|
26
|
+
:skip_publishing_in,
|
27
|
+
:use_backoff_handler,
|
28
|
+
:backoff_handler_max_retries,
|
29
|
+
:connection_reset_max_retries,
|
30
|
+
:connection_reset_timeout,
|
31
|
+
:connection_reset_exceptions,
|
32
|
+
:logger_message_size_limit,
|
33
|
+
:receive_logger,
|
34
|
+
:publish_logger,
|
35
|
+
:malformed_logger
|
36
|
+
|
37
|
+
def initialize( # rubocop:disable Metrics/MethodLength
|
38
|
+
group_id: nil,
|
39
|
+
project_id: nil,
|
40
|
+
queue_suffix: nil,
|
41
|
+
hooks: {},
|
42
|
+
environment: :production,
|
43
|
+
queue_name_conversion: nil,
|
44
|
+
receiving_job_class_callable: nil,
|
45
|
+
handler_resolver_callable: nil,
|
46
|
+
exception_notifier: nil,
|
47
|
+
before_receiving_hooks: [],
|
48
|
+
after_receiving_hooks: [],
|
49
|
+
skip_publishing_in: %i[test development],
|
50
|
+
use_backoff_handler: false,
|
51
|
+
backoff_handler_max_retries: 6,
|
52
|
+
connection_reset_max_retries: 10,
|
53
|
+
connection_reset_timeout: 0.2,
|
54
|
+
connection_reset_exceptions: [Bunny::ConnectionClosedError],
|
55
|
+
logger_message_size_limit: 9_500,
|
56
|
+
receive_logger: nil,
|
57
|
+
publish_logger: nil,
|
58
|
+
malformed_logger: nil
|
59
|
+
)
|
60
|
+
self.group_id = group_id
|
61
|
+
self.project_id = project_id
|
62
|
+
self.queue_suffix = queue_suffix
|
63
|
+
self.hooks = hooks
|
64
|
+
self.environment = environment
|
65
|
+
self.queue_name_conversion = queue_name_conversion
|
66
|
+
self.receiving_job_class_callable = receiving_job_class_callable
|
67
|
+
self.handler_resolver_callable = handler_resolver_callable
|
68
|
+
self.exception_notifier = exception_notifier
|
69
|
+
self.before_receiving_hooks = before_receiving_hooks
|
70
|
+
self.after_receiving_hooks = after_receiving_hooks
|
71
|
+
self.skip_publishing_in = skip_publishing_in
|
72
|
+
self.use_backoff_handler = use_backoff_handler
|
73
|
+
self.backoff_handler_max_retries = backoff_handler_max_retries
|
74
|
+
self.connection_reset_max_retries = connection_reset_max_retries
|
75
|
+
self.connection_reset_timeout = connection_reset_timeout
|
76
|
+
self.connection_reset_exceptions = connection_reset_exceptions
|
77
|
+
self.logger_message_size_limit = logger_message_size_limit
|
78
|
+
|
79
|
+
self.receive_logger = receive_logger || default_receive_logger
|
80
|
+
self.publish_logger = publish_logger || default_publish_logger
|
81
|
+
self.malformed_logger = malformed_logger || default_malformed_logger
|
82
|
+
end
|
48
83
|
|
49
84
|
def validate!
|
50
85
|
raise InvalidConfig, "missing project_id" unless project_id
|
@@ -67,6 +102,20 @@ module Rabbit
|
|
67
102
|
def read_queue
|
68
103
|
[app_name, queue_suffix].reject { |x| x.nil? || x.empty? }.join(".")
|
69
104
|
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def default_receive_logger
|
109
|
+
Logger.new(Rabbit.root.join("log", "incoming_rabbit_messages.log"))
|
110
|
+
end
|
111
|
+
|
112
|
+
def default_publish_logger
|
113
|
+
Logger.new(Rabbit.root.join("log", "rabbit.log"))
|
114
|
+
end
|
115
|
+
|
116
|
+
def default_malformed_logger
|
117
|
+
Logger.new(Rabbit.root.join("log", "malformed_messages.log"))
|
118
|
+
end
|
70
119
|
end
|
71
120
|
|
72
121
|
extend self
|
data/rabbit_messaging.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Umbrellio
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bunny
|
@@ -38,20 +37,6 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: tainbox
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
40
|
description: Rabbit (Rabbit Messaging)
|
56
41
|
email:
|
57
42
|
- oss@umbrellio.biz
|
@@ -77,6 +62,7 @@ files:
|
|
77
62
|
- lib/rabbit/daemon.rb
|
78
63
|
- lib/rabbit/event_handler.rb
|
79
64
|
- lib/rabbit/extensions/bunny/channel.rb
|
65
|
+
- lib/rabbit/helper.rb
|
80
66
|
- lib/rabbit/publishing.rb
|
81
67
|
- lib/rabbit/publishing/channels_pool.rb
|
82
68
|
- lib/rabbit/publishing/job.rb
|
@@ -97,7 +83,6 @@ files:
|
|
97
83
|
homepage: https://github.com/umbrellio/rabbit_messaging
|
98
84
|
licenses: []
|
99
85
|
metadata: {}
|
100
|
-
post_install_message:
|
101
86
|
rdoc_options: []
|
102
87
|
require_paths:
|
103
88
|
- lib
|
@@ -112,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
97
|
- !ruby/object:Gem::Version
|
113
98
|
version: '0'
|
114
99
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
100
|
+
rubygems_version: 3.6.9
|
117
101
|
specification_version: 4
|
118
102
|
summary: Rabbit (Rabbit Messaging)
|
119
103
|
test_files: []
|