Skip to content

Update servers manually in a non-cluster environment #307

@chdanielmueller

Description

@chdanielmueller

Proposed change

Expose a function on the NATSConnection to edit the servers after opening the connection.

For example something like this:

export interface NatsConnection {
  reconnect(
    servers?: Array<string> | string;
  ): Promise<void>;
}

Use case

This would allow to change the connection to another NATS instance or cluster.

My specific use case would be in projects with a simple single-node NATS.
We discover the node running in a container using an SRV record.
If the node would crash and restart it will get a new port and a new SRV record is created.
Using the force reconnect with the possibility to change the server we could drop in at the nc.status() events and validate if a new server:port is available and overwrite where to connect to.

Other use cases would include to switch to another cluster for purposes like maintenance or load balancing.

Contribution

Yes, I would be happy to implement this.

I would need guidance to how the server update should be implemented.
For example: Should it publish an event like a cluster would or should it directly modify the servers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions