shared_broker 1.0.0 → 1.1.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/lib/shared_broker/adapters/redis.rb +64 -0
- data/lib/shared_broker/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a691e6fa4ea7eb0d9b7974a55ed217c25a325be29c7beba0211d05633e947c02
|
|
4
|
+
data.tar.gz: '09abf8886190595bbcf09d7faeaf0676f848c763b8efef6ed092c8b23eac5853'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 96d856ee56c3d1db971a0a751920d03b65c3f67922b77ef67e42443f2586cc6e6063a5301fff1e050e8f2b81ab334e4479d80739604938c76f1880824692b097
|
|
7
|
+
data.tar.gz: 46d39087d7e875d84cd8a82223e68edadd965651e795c013c1da85cbfc847663fe594ed90bf8b1f60c5eb7ade7f14056f4aed3fbb5fe2a46e43fa5bc7aaf7ed0
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require "json"
|
|
5
|
+
require "time"
|
|
6
|
+
|
|
7
|
+
module SharedBroker
|
|
8
|
+
module Adapters
|
|
9
|
+
class Redis < Base
|
|
10
|
+
def initialize(redis_url:)
|
|
11
|
+
begin
|
|
12
|
+
require "redis"
|
|
13
|
+
rescue LoadError
|
|
14
|
+
raise unless defined?(::Redis)
|
|
15
|
+
end
|
|
16
|
+
@redis = ::Redis.new(url: redis_url)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def publish(topic, message, correlation_id: nil)
|
|
20
|
+
unless message.is_a?(Hash)
|
|
21
|
+
raise ArgumentError, "Expected message to be a Hash, got #{message.class} with value #{message.inspect}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
payload = message.merge(_correlation_id: correlation_id)
|
|
25
|
+
@redis.publish(topic, payload.to_json)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def subscribe(topic, queue_name, max_retries: 3, backoff_base: 2, &block)
|
|
29
|
+
Thread.new do
|
|
30
|
+
@redis.subscribe(topic) do |on|
|
|
31
|
+
on.message do |_channel, msg_json|
|
|
32
|
+
data = JSON.parse(msg_json, symbolize_names: true)
|
|
33
|
+
attempts = 0
|
|
34
|
+
begin
|
|
35
|
+
block.call(data)
|
|
36
|
+
rescue => e
|
|
37
|
+
attempts += 1
|
|
38
|
+
if attempts <= max_retries
|
|
39
|
+
sleep(backoff_base**attempts)
|
|
40
|
+
retry
|
|
41
|
+
else
|
|
42
|
+
publish_to_dlq(topic, queue_name, msg_json, e)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def publish_to_dlq(topic, queue_name, payload_json, exception)
|
|
53
|
+
dlq_key = "dlq:#{topic}:#{queue_name}"
|
|
54
|
+
dlq_payload = {
|
|
55
|
+
payload: JSON.parse(payload_json, symbolize_names: true),
|
|
56
|
+
x_failed_at: Time.now.utc.iso8601,
|
|
57
|
+
x_exception_class: exception.class.name,
|
|
58
|
+
x_exception_message: exception.message
|
|
59
|
+
}
|
|
60
|
+
@redis.rpush(dlq_key, dlq_payload.to_json)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shared_broker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gemini Antigravity
|
|
@@ -137,18 +137,19 @@ files:
|
|
|
137
137
|
- lib/shared_broker/adapters/in_memory.rb
|
|
138
138
|
- lib/shared_broker/adapters/kafka.rb
|
|
139
139
|
- lib/shared_broker/adapters/rabbit_mq.rb
|
|
140
|
+
- lib/shared_broker/adapters/redis.rb
|
|
140
141
|
- lib/shared_broker/cipher.rb
|
|
141
142
|
- lib/shared_broker/circuit_breaker.rb
|
|
142
143
|
- lib/shared_broker/telemetry.rb
|
|
143
144
|
- lib/shared_broker/validation.rb
|
|
144
145
|
- lib/shared_broker/version.rb
|
|
145
146
|
- sig/shared_broker.rbs
|
|
146
|
-
homepage: https://github.com/
|
|
147
|
+
homepage: https://github.com/wesleyskap/shared_broker
|
|
147
148
|
licenses:
|
|
148
149
|
- MIT
|
|
149
150
|
metadata:
|
|
150
|
-
source_code_uri: https://github.com/
|
|
151
|
-
changelog_uri: https://github.com/
|
|
151
|
+
source_code_uri: https://github.com/wesleyskap/shared_broker
|
|
152
|
+
changelog_uri: https://github.com/wesleyskap/shared_broker/blob/main/CHANGELOG.md
|
|
152
153
|
post_install_message:
|
|
153
154
|
rdoc_options: []
|
|
154
155
|
require_paths:
|