nats.java icon indicating copy to clipboard operation
nats.java copied to clipboard

At initial connect random server URL from INFO not selected but seed URL always used

Open tbeets opened this issue 2 years ago • 2 comments

Enhancement

When initially establishing a NATS server connection, the Java client is not randomly selecting a server URL from eligible list (connect_urls) returned in the INFO from the NATS server. Instead, the client is always establishing the NATS server connection with a random choice from the seed servers.

Versions of io.nats:jnats and nats-server:

io.nats:jnats: 2.13.1 nats-server: 2.6.6

OS/Container environment:

Linux (Ubuntu 20.04 LTS)

Steps or code to reproduce the issue:

  1. Instantiate a NATS cluster of at least two nodes.
  2. Verify that routes are made and that each server is advertising the (connect_urls) of all the nodes.
  3. Choose a single node as the static "seed" URL to use in the Java client.
  4. Create several client connections.
  5. Monitor connections on each node in cluster and note that all connections made to the "seed" server only and all other server nodes have zero connections.

Example: tbeets/benchmark

Execute tb-3-topic-1kb.yaml benchmark and note that all 6 client connections (3 publishers, 3 consumers) made to seed node only.

Expected result:

Server connections would be roughly evenly distributed to the nodes in the cluster.

Actual result:

All connections on the seed node only.

tbeets avatar Jan 03 '22 22:01 tbeets

I have learned that this is working as designed (not a bug) but the behavior may be opposite what many developers assume to be the behavior. Changed to Enhancement.

tbeets avatar Jan 04 '22 00:01 tbeets

So in order to do this, we would have to make a connection to the server, get the server's list and then do another connection. This is certainly something your client can do own it's own by using the getConnectURLs method in the ServerInfo object returned by Connection.getServerInfo()

scottf avatar Jun 08 '22 14:06 scottf