Skip to content

Commit

Permalink
[FEAT] implemented noResolve connect option
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jun 13, 2024
1 parent 04a23e1 commit 953684f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ more performant or appropriate.
The following is the list of connection options and default values.

| Option | Default | Description |
| ----------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|-------------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `authenticator` | none | Specifies the authenticator function that sets the client credentials. |
| `debug` | `false` | If `true`, the client prints protocol interactions to the console. Useful for debugging. |
| `ignoreClusterUpdates` | `false` | If `true` the client will ignore any cluster updates provided by the server. |
Expand All @@ -770,6 +770,7 @@ The following is the list of connection options and default values.
| `noAsyncTraces` | `false` | When `true` the client will not add additional context to errors associated with request operations. Setting this option to `true` will greatly improve performance of request/reply and JetStream publishers. |
| `noEcho` | `false` | Subscriptions receive messages published by the client. Requires server support (1.2.0). If set to true, and the server does not support the feature, an error with code `NO_ECHO_NOT_SUPPORTED` is emitted, and the connection is aborted. Note that it is possible for this error to be emitted on reconnect when the server reconnects to a server that does not support the feature. |
| `noRandomize` | `false` | If set, the order of user-specified servers is randomized. |
| `noResolve` | | If set to true, will not resolve host names. |
| `pass` | | Sets the password for a connection. |
| `pedantic` | `false` | Turns on strict subject format checks. |
| `pingInterval` | `120000` | Number of milliseconds between client-sent pings. |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"cjs-jetstream": "deno run --allow-all ./bin/cjs-fix-imports.ts -o jetstream/ ./.deps/nats.deno/jetstream/",
"cjs": "npm run cjs-nbc && npm run cjs-jetstream",
"clean": "shx rm -Rf ./lib/* ./nats-base-client ./.deps",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.26.0 https://github.com/nats-io/nats.deno.git",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch main https://github.com/nats-io/nats.deno.git",
"fmt": "deno fmt ./src/ ./examples/ ./test/",
"prepack": "npm run clone-nbc && npm run cjs && npm run check-package && npm run build",
"ava": "nyc ava --verbose -T 60000",
Expand Down
2 changes: 1 addition & 1 deletion src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function connect(opts: ConnectionOptions = {}): Promise<NatsConnection> {
factory: (): Transport => {
return new NodeTransport();
},
dnsResolveFn: nodeResolveHost,
dnsResolveFn: opts.noResolve === true ? undefined : nodeResolveHost,

Check failure on line 30 in src/connect.ts

View workflow job for this annotation

GitHub Actions / test (22.x, 1.43.5)

Property 'noResolve' does not exist on type 'ConnectionOptions'.

Check failure on line 30 in src/connect.ts

View workflow job for this annotation

GitHub Actions / test (20.x, 1.43.5)

Property 'noResolve' does not exist on type 'ConnectionOptions'.

Check failure on line 30 in src/connect.ts

View workflow job for this annotation

GitHub Actions / test (18.x, 1.43.5)

Property 'noResolve' does not exist on type 'ConnectionOptions'.
} as TransportFactory);
return NatsConnectionImpl.connect(opts);
}
10 changes: 10 additions & 0 deletions test/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const { deferred, delay, nuid } = require(
const { Lock } = require("./helpers/lock");
const { NatsServer } = require("./helpers/launcher");
const { jetstreamServerConf } = require("./helpers/jsutil.js");
const {getResolveFn} = require("../nats-base-client/transport");

const u = "demo.nats.io:4222";

Expand Down Expand Up @@ -796,3 +797,12 @@ test("basics - js fetch on stopped server doesn't close", async (t) => {
await nc.close();
await ns.stop();
});

test("basics - noResolve", async (t) => {
const ns = await NatsServer.start();
const nc = await connect({port: ns.port, noResolve: true});
t.plan(1);
t.is(getResolveFn(), undefined);
await nc.close();
await ns.stop();
})

0 comments on commit 953684f

Please sign in to comment.