A live NATS connection.
A JetStreamManager for ensuring streams, publishing, and durable pulls.
import { connect } from 'edgeport/nats';
import { jetstream } from 'edgeport/nats';
await using nc = await connect({ hostname: 'nats.example.com', username: 'u', password: 'p' });
const js = jetstream(nc);
await js.ensureStream('ORDERS', { subjects: ['orders.>'] });
const ack = await js.publish('orders.new', JSON.stringify({ id: 42 }));
console.log(ack.stream, ack.seq); // 'ORDERS' 1
const consumer = await js.pullSubscribe('ORDERS', 'worker', { ackWaitMs: 5000 });
const msgs = await consumer.fetch(10, { expiresMs: 2000 });
for (const m of msgs) {
console.log(m.subject, new TextDecoder().decode(m.data));
await m.ack(); // un-acked messages are redelivered to any re-bind of 'worker'
}
Creates a JetStream context bound to a NATS connection.
JetStream must be enabled on the server (the
-jsflag). The returned manager builds entirely on the connection's request/publish, so it shares the same socket and lifetime; closing the connection invalidates the manager.