nats-io / nats.node

Node.js client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
1.55k stars 163 forks source link

Incorrect Stream Creation Targeting Hub Instead of Leaf Node #611

Closed Sachita007 closed 10 months ago

Sachita007 commented 10 months ago

Hello,

I'm experiencing an issue with stream creation when connected to a leaf node. Instead of creating the stream on the leaf node, it consistently creates on the hub server. Here are the details of my configuration:

leaf Server config

port: 4111
server_name: leaf-server
jetstream {
    store_dir="./store_leaf"
    domain=leaf
}
leafnodes {
    remotes = [
        {
            urls: "nats://localhost:7422"
            credentials:"******"
            account: ************************************************
        }
    ]
}

include ./resolver.conf 

Hub Server Config

port: 4222
server_name: hub-server
jetstream {
    store_dir="./store_server"
    domain=hub
}
leafnodes {
    port: 7422
}

include ./resolver.conf

My Code:

const nc = await connect(
        {
            url: "nats://localhost:4111",
            authenticator: credsAuthenticator(new TextEncoder().encode(creds)),
        },
    );

const js = nc.jetstream();
const jsm = await nc.jetstreamManager();

    // add a stream - jetstream can capture nats core messages
    const stream = "Stream";
    const subj = 'stream.*';
    const create = await jsm.streams.add({ name: stream, subjects: [subj] });

    // list all streams
    const streams = await jsm.streams.list().next();
    streams.forEach((si) => {
        console.log(si);
    });

Output:

{
  config: {
    name: 'Stream',
    subjects: [ 'stream.*' ],
    retention: 'limits',
    max_consumers: -1,
    max_msgs: -1,
    max_bytes: -1,
    max_age: 0,
    max_msgs_per_subject: -1,
    max_msg_size: -1,
    discard: 'old',
    storage: 'file',
    num_replicas: 1,
    duplicate_window: 120000000000,
    compression: 'none',
    allow_direct: false,
    mirror_direct: false,
    sealed: false,
    deny_delete: false,
    deny_purge: false,
    allow_rollup_hdrs: false,
    consumer_limits: {}
  },
  created: '2023-12-27T00:18:57.782234724Z',
  state: {
    messages: 0,
    bytes: 0,
    first_seq: 0,
    first_ts: '0001-01-01T00:00:00Z',
    last_seq: 0,
    last_ts: '0001-01-01T00:00:00Z',
    consumer_count: 0
  },
  domain: 'hub',
  ts: '2023-12-27T00:21:12.276385947Z'
}

In the above scenario, I connected to the leaf node and attempted to create the stream. Instead of being created on the leaf node, it is being created on the hub server.

Originally posted by @Sachita007 in https://github.com/nats-io/nats.js/discussions/610

Sachita007 commented 10 months ago

I would like to express my sincere apologies for any inconvenience caused by the issue I reported. After a more thorough review, I realized that my oversight led to the misunderstanding. I failed to notice that the documentation specifies the use of 'servers' instead of 'url' for connection parameters. As a result, the connection defaulted to the standard port instead of the one I intended.

I appreciate your understanding and patience as we navigate through these matters. In the future, I will make sure to carefully review the documentation before reporting any issues. Thank you for your time and assistance!