fix: wrap JetStream payloads with reply info

This commit is contained in:
Brad Stein 2026-01-28 12:34:26 -03:00
parent 9fb614772f
commit fcca4107db

View File

@ -41,7 +41,8 @@ class QueueManager:
raise RuntimeError("queue not initialized")
reply = self._nc.new_inbox()
sub = await self._nc.subscribe(reply)
await self._js.publish(self._settings.nats_subject, json.dumps(payload).encode(), reply=reply)
envelope = {"reply": reply, "payload": payload}
await self._js.publish(self._settings.nats_subject, json.dumps(envelope).encode())
msg = await sub.next_msg(timeout=300)
await sub.unsubscribe()
return json.loads(msg.data.decode())
@ -73,11 +74,12 @@ class QueueManager:
async def _handle_message(self, msg) -> None:
try:
payload = json.loads(msg.data.decode())
envelope = json.loads(msg.data.decode())
except Exception:
await msg.ack()
return
reply = msg.reply
payload = envelope.get("payload", envelope)
reply = envelope.get("reply") or msg.reply
try:
result = await self._handler(payload)
if reply and self._nc: