fix: wrap JetStream payloads with reply info
This commit is contained in:
parent
9fb614772f
commit
fcca4107db
@ -41,7 +41,8 @@ class QueueManager:
|
|||||||
raise RuntimeError("queue not initialized")
|
raise RuntimeError("queue not initialized")
|
||||||
reply = self._nc.new_inbox()
|
reply = self._nc.new_inbox()
|
||||||
sub = await self._nc.subscribe(reply)
|
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)
|
msg = await sub.next_msg(timeout=300)
|
||||||
await sub.unsubscribe()
|
await sub.unsubscribe()
|
||||||
return json.loads(msg.data.decode())
|
return json.loads(msg.data.decode())
|
||||||
@ -73,11 +74,12 @@ class QueueManager:
|
|||||||
|
|
||||||
async def _handle_message(self, msg) -> None:
|
async def _handle_message(self, msg) -> None:
|
||||||
try:
|
try:
|
||||||
payload = json.loads(msg.data.decode())
|
envelope = json.loads(msg.data.decode())
|
||||||
except Exception:
|
except Exception:
|
||||||
await msg.ack()
|
await msg.ack()
|
||||||
return
|
return
|
||||||
reply = msg.reply
|
payload = envelope.get("payload", envelope)
|
||||||
|
reply = envelope.get("reply") or msg.reply
|
||||||
try:
|
try:
|
||||||
result = await self._handler(payload)
|
result = await self._handler(payload)
|
||||||
if reply and self._nc:
|
if reply and self._nc:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user