nats_messaging 1.2.6 → 1.2.8
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/nats_messaging/nats_service.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d87203d37b1e6d38e56cfbc33115ea9138d5d01e40674f2c034f6bbfbaa4df2
|
4
|
+
data.tar.gz: 1aa73a94a81abad33c4cd3fb726c21bfbe82d222b640aabdf82b2aa8c96096eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f66d3a80f97030d6232802e6024fd2d27313dbf2ff128222bf4b63f53f58fb2b0f81427811f7b25ef328450d82fa8e2afef5f8977c2fb12776da6090cd0676dc
|
7
|
+
data.tar.gz: e2ad71e5fc0d5d675ea5af51e579e7f1946dcd197fe51aec96310c7af57737c6dd4257cb8bb33a8eb62e6b61f29654efaf2070c99e9020e9f063c7dcb8262079
|
@@ -86,7 +86,7 @@ module NatsMessaging
|
|
86
86
|
response = @nats.request(subject, packed_message, timeout: 5) # Timeout of 5 seconds
|
87
87
|
unpacked_response = MessagePack.unpack(response.data) # Deserializar respuesta
|
88
88
|
puts "NATS: Received reply: #{unpacked_response}"
|
89
|
-
yield(subject,
|
89
|
+
yield(subject, unpacked_response) if block_given?
|
90
90
|
unpacked_response
|
91
91
|
rescue NATS::IO::Timeout
|
92
92
|
puts "NATS: Request timed out for subject: #{subject}"
|
@@ -98,7 +98,7 @@ module NatsMessaging
|
|
98
98
|
end
|
99
99
|
|
100
100
|
# Listen to a subject and reply with a message using MessagePack
|
101
|
-
def listen_and_reply(subject, reply_message)
|
101
|
+
def listen_and_reply(subject, reply_message=nil)
|
102
102
|
# Cancel active subscription if it already exists for this subject
|
103
103
|
if @subscriptions[subject]
|
104
104
|
@subscriptions[subject].unsubscribe
|
@@ -111,6 +111,8 @@ module NatsMessaging
|
|
111
111
|
begin
|
112
112
|
unpacked_data = MessagePack.unpack(msg.data) # Deserializar mensaje recibido
|
113
113
|
puts "NATS: Received request on #{subject}: #{unpacked_data}"
|
114
|
+
yield_return = yield(subject, unpacked_data) if block_given?
|
115
|
+
reply_message = yield_return if reply_message.nil?
|
114
116
|
packed_reply = reply_message.to_msgpack # Serializar respuesta
|
115
117
|
# Asegurar que msg.reply existe antes de responder
|
116
118
|
if msg.reply
|
@@ -119,7 +121,6 @@ module NatsMessaging
|
|
119
121
|
else
|
120
122
|
puts "NATS: No reply subject for #{subject}, cannot respond"
|
121
123
|
end
|
122
|
-
yield(msg.subject, unpacked_data) if block_given?
|
123
124
|
unpacked_data
|
124
125
|
rescue => e
|
125
126
|
puts "NATS: Error while processing message: #{e.message}"
|
@@ -129,5 +130,6 @@ module NatsMessaging
|
|
129
130
|
puts "NATS: Error while replying: #{e.message}"
|
130
131
|
end
|
131
132
|
end
|
133
|
+
|
132
134
|
end
|
133
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nats_messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bea Graboloza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nats-pure
|