0

I am running a nats server in cluster mode with ths following config:

port: 4222
net: '0.0.0.0'

cluster {
  listen: 0.0.0.0:6222
  routes: ["nats://0.0.0.0:6222"]
}

# NATS Streaming specific configuration
streaming {
  id: test_cluster
  store: file
  dir: "./cluster"
  cluster {
    log_path: /cluster/
    node_id: "a"
  }
}

My app tries to connect to this cluster using nats-c library as follows:

  stanConnection* connection = nullptr;
  stanConnOptions* options = nullptr;
  natsOptions* nats_options = nullptr;

  natsOptions_Create(&nats_options);
  natsOptions_SetURL(nats_options, "nats://localhost:4222");

  stanConnOptions_Create(&options);      
  stanConnOptions_SetNATSOptions(options, nats_options);

  natsStatus staus = stanConnection_Connect(&connection, "test_cluster", "service", options);

The return value from this call is NATS_TIMEOUT. From the debug logs of the server I can see that client gets connected but soon dis-connects.

[64465] 2019/05/03 12:18:05.884075 [INF] Starting nats-server version 1.4.1
[64465] 2019/05/03 12:18:05.884164 [DBG] Go build version go1.11.5
[64465] 2019/05/03 12:18:05.884169 [INF] Git commit [not set]
[64465] 2019/05/03 12:18:05.884359 [INF] Listening for client connections on 0.0.0.0:4222
[64465] 2019/05/03 12:18:05.884396 [DBG] Server id is Pp7TGOtwoXdn0P2gVkzuHa
[64465] 2019/05/03 12:18:05.884400 [INF] Server is ready
[64465] 2019/05/03 12:18:05.884810 [INF] Listening for route connections on 0.0.0.0:6222
[64465] 2019/05/03 12:18:05.884951 [DBG] Trying to connect to route on 0.0.0.0:6222
[64465] 2019/05/03 12:18:05.885432 [INF] 127.0.0.1:38780 - rid:1 - Route connection created
[64465] 2019/05/03 12:18:05.886053 [DBG] 127.0.0.1:6222 - rid:2 - Route connect msg sent
[64465] 2019/05/03 12:18:05.887177 [DBG] 127.0.0.1:6222 - rid:2 - Router connection closed
[64465] 2019/05/03 12:18:05.887424 [DBG] Detected route to self, ignoring "nats://0.0.0.0:6222"
[64465] 2019/05/03 12:18:05.887471 [INF] 127.0.0.1:6222 - rid:2 - Route connection created
[64465] 2019/05/03 12:18:05.887555 [DBG] 127.0.0.1:38780 - rid:1 - Router connection closed
[64465] 2019/05/03 12:18:13.232390 [DBG] ::1:59868 - cid:3 - Client connection created
[64465] 2019/05/03 12:18:15.240495 [DBG] ::1:59868 - cid:3 - Client connection closed

Any idea why this is happening?

user3612009
  • 655
  • 1
  • 6
  • 18

1 Answers1

0

Sorry for the late response, I would recommend that you join Slack or directly ask your questions in the github repo (https://github.com/nats-io)

The issue here is that you start a single server in cluster mode and it would not be able to become leader and accept any client connection.

The client is able to create a NATS connection, but the Streaming connection will fail because no Streaming server has "accepted" it.

Moreover, the log that you show seem to be only NATS, not the Streaming server.

I. Kozlovic
  • 796
  • 3
  • 3