[英]Tell Datastax Java Cassandra driver to timeout cluster connection
How do you tell the Datastax Java Cassandra driver to time-out when it attempts to connect to your cluster? 在尝试连接到群集时,如何告诉Datastax Java Cassandra驱动程序超时?
I'm particularly interested in the case when the hosts are reachable, but the Cassandra ports are blocked or the Cassandra daemons are not running. 我对主机可以访问的情况特别感兴趣,但是Cassandra端口被阻塞或者Cassandra守护进程没有运行。 I'm writing a command-line client that ought to exit and report a suitable error message if it can not connect in a reasonable time.
我正在编写一个命令行客户端,如果它无法在合理的时间内连接,它应该退出并报告合适的错误消息。 At present it seems that the driver will wait forever for a contact point to response, if the contact point is reachable.
目前看来,如果联系点可以到达,驱动程序将永远等待接触点响应。
That is, I want Cluster.build()
to throw a NoHostAvailableException
if the driver can not communicate with the Cassandra daemon of any of the contact points within a given maximum time. 也就是说,如果驱动程序无法在给定的最大时间内与任何联系点的Cassandra守护进程通信,我希望
Cluster.build()
抛出NoHostAvailableException
。
RetryPolicy
won't work: that is for retrying queries, and I want the timeout to apply before we are ready to run queries. RetryPolicy
将不起作用:那是为了重试查询,我希望在我们准备运行查询之前应用超时。 ReconnectinoPolicy
initially looked promising, but the contract for the interface gives no means for indicating "consider this node to be dead forever more" ReconnectinoPolicy
最初看起来很有希望,但是接口的合同没有办法表明“认为这个节点永远死了” That is, I want Cluster.build() to throw a NoHostAvailableException if the driver can not communicate with the Cassandra daemon of any of the contact points within a given maximum time.
也就是说,如果驱动程序无法在给定的最大时间内与任何联系点的Cassandra守护进程通信,我希望Cluster.build()抛出NoHostAvailableException。
This is supposed to be the case. 应该是这种情况。 The driver will try to connect to each of the contact points and throw an exception if it fails to connect to any.
驱动程序将尝试连接到每个联系点,如果无法连接到任何联系点,则抛出异常。 You can control the maximum time the driver will try connecting (to each node) through SocketOptions.setConnectTimeoutMillis() (the default is 5 seconds).
您可以通过SocketOptions.setConnectTimeoutMillis()控制驱动程序尝试连接(到每个节点)的最长时间(默认值为5秒)。
My experience is that Cluster.build() does return an exception if no node can be connected to, but if your experience differs, you might want to report it as a bug (but a bit more detail on how you reproduce this would help). 我的经验是,如果没有节点可以连接,Cluster.build()确实会返回异常,但如果您的体验不同,您可能希望将其报告为错误(但有关如何重现这一点的更多细节会有所帮助) 。
That being said: 话虽如此:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.