gpt4 book ai didi

scala - 如何从 datastax ClusterBuilder 构建 Phantom CassandraConnection

转载 作者:行者123 更新时间:2023-12-04 14:24:36 25 4
gpt4 key购买 nike

我在 datastax 驱动程序上编写了以下代码以建立 cassandra 连接。

  val cluster = Cluster.builder()
.withCompression(ProtocolOptions.Compression.LZ4)
.addContactPoints(List("a", "b").asJava)
.withCredentials("foo", "bar")
.withPort(1111)
.withProtocolVersion(ProtocolVersion.V4)
.withPoolingOptions(new PoolingOptions()
.setConnectionsPerHost(HostDistance.LOCAL, 1, 12)
.setConnectionsPerHost(HostDistance.REMOTE, 1, 12)
.setMaxRequestsPerConnection(HostDistance.LOCAL, 1028)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 1028)
)
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM))

我正在尝试迁移此代码以开始使用 PhantomDSL。

我想使用上述所有选项构建一个 PhantomDSL CassandraConnection。

我在这里查看了代码

https://github.com/outworkers/phantom/blob/develop/phantom-connectors/src/main/scala/com/outworkers/phantom/connectors/CassandraConnection.scala

尝试过

val phantomConnection = new CassandraConnection("foo", cluster, false)

我得到的错误是

[error] MyConnection.scala:37: type mismatch;
[error] found : com.datastax.driver.core.Cluster.Builder
[error] required: com.outworkers.phantom.connectors.ClusterBuilder
[error] (which expands to) com.datastax.driver.core.Cluster.Builder => com.datastax.driver.core.Cluster.Builder
[error] Error occurred in an application involving default arguments.
[error] new CassandraConnection("foo", cluster, false)
[error] ^

最佳答案

只需使用 native _.withClusterBuilder 方法即可实现您想要的效果。很抱歉回复晚了,我们会监控针对此标签的问题,但出于某种原因,这从未出现在我们的任何收件箱中。

object Connector {
val default: CassandraConnection = ContactPoint.local
.withClusterBuilder(
_.withCompression(ProtocolOptions.Compression.LZ4)
.withCredentials("foo", "bar")
.withPort(1111)
.withProtocolVersion(ProtocolVersion.V4)
).noHeartbeat().keySpace(
KeySpace("phantom").ifNotExists().`with`(
replication eqs SimpleStrategy.replication_factor(1)
)
)
}

关于scala - 如何从 datastax ClusterBuilder 构建 Phantom CassandraConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48600984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com