Repository navigation
Replies: 1 comment
|
Replace the connection stored in The setup is: from nats.client import connect
from nats.jetstream import PublishAck, new as new_jetstream
client = await connect("nats://localhost:4222")
js = new_jetstream(client)
# Store js in the state used by your publisher.
# Close client when your application shuts down.For your wrapper: async def publish(self, cmd: "NatsPublishCommand") -> PublishAck:
payload, content_type = await self.codec.encode(cmd.body, self.serializer)
headers_to_send = {
"content-type": content_type or "",
**cmd.headers_to_publish(js=True),
}
if cmd.stream is not None:
headers_to_send["Nats-Expected-Stream"] = cmd.stream
if cmd.msg_ttl is not None:
headers_to_send["Nats-TTL"] = str(int(cmd.msg_ttl))
options = {}
if cmd.timeout is not None:
options["timeout"] = cmd.timeout
return await self.__state.connection.publish(
subject=cmd.destination,
payload=payload,
headers=headers_to_send,
**options,
)The new See the official migration guide and publish/ack implementation. I validated this wrapper with Python 3.13.16, Prepared with OpenAI Codex assistance; verified against the published packages and a local server. |
Uh oh!
There was an error while loading. Please reload this page.
So, we’re using JetStreamContext for publishing, which returns PubAck, but we need to switch to nats-jetstream to receive PublishAck — how can we do this in the most appropriate way?
Something like that, where .connection is the JetstreamContext.
All reactions