nats_messaging 1.2.7 → 1.3.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/nats_messaging/nats_service.rb +6 -5
- 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: 85ff48cb51b0c9bfc615d5c2f8e9a555a64ff08d264e7273d27f521b94b4c4da
|
4
|
+
data.tar.gz: 4162a4cbfd74d39ec9af5a4f4a5cbf5e80e3635439be570f5263f44adba633cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2452efb96a79d7eaba51826b634b3a8917b00a1a4f7942c150b5f538a34108f60735e8e3df31bfca5b2b473c24917cfa017e36353fc42fab33795212d0959e5b
|
7
|
+
data.tar.gz: 28358eb8aad977fdb708061be7b1090d39ef097f52ede12bf2b0018feb18c95e40dc7a0666089f84e1bb9a9a372f3988e2ee17e783b5072c878b201fa40f9c54
|
@@ -98,12 +98,11 @@ 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
|
105
105
|
end
|
106
|
-
unpacked_data = nil
|
107
106
|
begin
|
108
107
|
# Create a new subscription
|
109
108
|
puts "NATS: Listening on #{subject} with reply message: #{reply_message}"
|
@@ -111,15 +110,16 @@ module NatsMessaging
|
|
111
110
|
begin
|
112
111
|
unpacked_data = MessagePack.unpack(msg.data) # Deserializar mensaje recibido
|
113
112
|
puts "NATS: Received request on #{subject}: #{unpacked_data}"
|
114
|
-
|
113
|
+
yield_return = yield(subject, unpacked_data) if block_given?
|
114
|
+
reply = reply_message.nil? ? yield_return : reply_message
|
115
|
+
packed_reply = reply.to_msgpack # Serializar respuesta
|
115
116
|
# Asegurar que msg.reply existe antes de responder
|
116
117
|
if msg.reply
|
117
118
|
@nats.publish(msg.reply, packed_reply)
|
118
|
-
puts "NATS: Replied to #{subject} with message: #{
|
119
|
+
puts "NATS: Replied to #{subject} with message: #{reply}"
|
119
120
|
else
|
120
121
|
puts "NATS: No reply subject for #{subject}, cannot respond"
|
121
122
|
end
|
122
|
-
yield(msg.subject, unpacked_data) if block_given?
|
123
123
|
unpacked_data
|
124
124
|
rescue => e
|
125
125
|
puts "NATS: Error while processing message: #{e.message}"
|
@@ -129,5 +129,6 @@ module NatsMessaging
|
|
129
129
|
puts "NATS: Error while replying: #{e.message}"
|
130
130
|
end
|
131
131
|
end
|
132
|
+
|
132
133
|
end
|
133
134
|
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.
|
4
|
+
version: 1.3.0
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nats-pure
|