mirror of
https://github.com/hanzomsg/nats.js.git
synced 2026-10-30 20:31:36 +00:00
* refactor: replace `parse` with `parseArgs` and update dependencies in examples and configurations - Migrated from `@std/flags` to `@std/cli` across various scripts. - Updated related imports, arguments parsing logic, and versioned dependencies. Signed-off-by: Alberto Ricart <[email protected]> * chore(deps): bump `@types/node` to ^25.0.0 across all packages Signed-off-by: Alberto Ricart <[email protected]> * chore(release): bump all packages to version 3.3.0 Signed-off-by: Alberto Ricart <[email protected]> * chore(workflows): update Deno to 2.6.x, Node to 25.x in CI configurations Signed-off-by: Alberto Ricart <[email protected]> * fix(node_transport): specify `Uint8Array` type for `frame` argument in `socket.on("data")` listener v25, the inferred type changed to string | NonSharedBuffer Signed-off-by: Alberto Ricart <[email protected]> * chore(workflows): update GitHub Actions to use latest versions of `checkout`, `setup-node`, and `setup-deno` Signed-off-by: Alberto Ricart <[email protected]> --------- Signed-off-by: Alberto Ricart <[email protected]>
67 lines
1.5 KiB
TypeScript
Executable File
67 lines
1.5 KiB
TypeScript
Executable File
#!/usr/bin/env deno run --allow-all --unstable
|
|
|
|
import { parseArgs } from "@std/cli";
|
|
import {
|
|
connect,
|
|
type ConnectionOptions,
|
|
credsAuthenticator,
|
|
} from "@nats-io/transport-deno";
|
|
|
|
const argv = parseArgs(
|
|
Deno.args,
|
|
{
|
|
alias: {
|
|
"s": ["server"],
|
|
"q": ["queue"],
|
|
"f": ["creds"],
|
|
},
|
|
default: {
|
|
s: "127.0.0.1:4222",
|
|
q: "",
|
|
},
|
|
boolean: ["headers", "debug"],
|
|
string: ["server", "queue", "creds"],
|
|
},
|
|
);
|
|
|
|
const opts = { servers: argv.s } as ConnectionOptions;
|
|
const subject = argv._[0] ? String(argv._[0]) : ">";
|
|
|
|
if (argv.debug) {
|
|
opts.debug = true;
|
|
}
|
|
|
|
if (argv.creds) {
|
|
const data = await Deno.readFile(argv.creds);
|
|
opts.authenticator = credsAuthenticator(data);
|
|
}
|
|
|
|
if (argv.h || argv.help || !subject) {
|
|
console.log(
|
|
"Usage: nats-sub [-s server] [--creds=/path/file.creds] [-q queue] [--headers] subject",
|
|
);
|
|
Deno.exit(1);
|
|
}
|
|
|
|
const nc = await connect(opts);
|
|
console.info(`connected ${nc.getServer()}`);
|
|
nc.closed()
|
|
.then((err) => {
|
|
if (err) {
|
|
console.error(`closed with an error: ${err.message}`);
|
|
}
|
|
});
|
|
|
|
const sub = nc.subscribe(subject, { queue: argv.q as string });
|
|
console.info(`${argv.q !== "" ? "queue " : ""}listening to ${subject}`);
|
|
for await (const m of sub) {
|
|
console.log(`[${sub.getProcessed()}]: ${m.subject}: ${m.string()}`);
|
|
if (argv.headers && m.headers) {
|
|
const h = [];
|
|
for (const [key, value] of m.headers) {
|
|
h.push(`${key}=${value}`);
|
|
}
|
|
console.log(`\t${h.join(";")}`);
|
|
}
|
|
}
|