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]>
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
/*
|
|
* Copyright 2023 The NATS Authors
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
import { parseArgs } from "@std/cli";
|
|
import { connect, type ConnectionOptions } from "@nats-io/transport-deno";
|
|
|
|
import { humanizeBytes } from "./03_util.ts";
|
|
|
|
const argv = parseArgs(
|
|
Deno.args,
|
|
{
|
|
alias: {
|
|
"s": ["server"],
|
|
"a": ["asset"],
|
|
"c": ["chunk"],
|
|
},
|
|
default: {
|
|
s: "demo.nats.io",
|
|
c: 0,
|
|
a: 1024 * 1024,
|
|
},
|
|
string: ["server"],
|
|
},
|
|
);
|
|
|
|
const copts = { servers: argv.s } as ConnectionOptions;
|
|
const nc = await connect(copts);
|
|
|
|
const max_chunk = argv.c;
|
|
const size = argv.a as number;
|
|
console.log(`requesting ${humanizeBytes(size)}`);
|
|
|
|
const start = performance.now();
|
|
const iter = await nc.requestMany(
|
|
"data",
|
|
JSON.stringify({ max_chunk, size }),
|
|
{
|
|
strategy: "sentinel",
|
|
maxWait: 10000,
|
|
},
|
|
);
|
|
|
|
let received = 0;
|
|
let count = 0;
|
|
for await (const m of iter) {
|
|
count++;
|
|
received += m.data.length;
|
|
if (m.data.length === 0) {
|
|
// sentinel
|
|
count--;
|
|
}
|
|
}
|
|
|
|
console.log(performance.now() - start, "ms");
|
|
|
|
console.log(`received ${count} responses: ${humanizeBytes(received)} bytes`);
|
|
await nc.close();
|