我正在使用以下配置在群集模式下运行nats服务器:
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"
}
}
我的应用尝试使用nats-c库连接到此集群,如下所示:
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);
此调用的返回值为NATS_TIMEOUT。从服务器的调试日志中,我可以看到客户端已连接但很快断开连接。
[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
知道为什么会这样吗?
答案 0 :(得分:0)
对不起,我的建议很晚,我建议您加入Slack或直接在github存储库(https://github.com/nats-io)中问您的问题
这里的问题是,您以群集模式启动单个服务器,它将无法成为领导者并接受任何客户端连接。
客户端能够创建一个NATS连接,但是流连接将失败,因为没有流服务器“接受”它。
此外,您显示的日志似乎只是NATS,而不是流服务器。