我在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。
我查看了这里的代码
并尝试了
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] ^
答案 0 :(得分:2)
只需使用原生_.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)
)
)
}