使用 Hazelcast 客户端部署选项部署 Cassandra 驱动程序时出现以下错误
Deploying Cassandra driver using Hazelcast client deployment option giving following error
我正在尝试使用由 Cassandra 支持的 MapStore。为此,使用 ClientUserCodeDeploymentConfig 将这些 MapStore 和 MapLoader 实现推送到 Hazelcast 成员,如下所示
public class CassandraMapStoreFactory implements MapStoreFactory<String, Long> {
@Override
public MapLoader<String, Long> newMapStore(String mapName, Properties properties) {
return new CassandraPersistence(buildSession());
}
private Session buildSession() {
try {
ConsistencyLevel consistencyLevel = ConsistencyLevel.LOCAL_QUORUM;
PoolingOptions poolingOptions = new PoolingOptions()
.setMaxRequestsPerConnection(HostDistance.LOCAL, 1024)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 256);
Cluster cluster = Cluster.builder()
.addContactPoints("15.207.180.45")
.withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel))
.withSocketOptions(new SocketOptions().setReadTimeoutMillis(12000))
.withPoolingOptions(poolingOptions)
.withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(10000, 2))
.build();
return cluster.connect("sample");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
下面是将客户端代码推送到 Hazelcast 的代码 member/server
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
ClientUserCodeDeploymentConfig codeDeploymentConfig = new ClientUserCodeDeploymentConfig().setEnabled(true)
.addClass(CounterEntryProcessor.class).addClass(CassandraMapStoreFactory.class).addClass(CassandraPersistence.class).addJar("cassandra-driver-core-3.1.2.jar");
config.setUserCodeDeploymentConfig(codeDeploymentConfig);
config.setClassLoader(MapIdGeneratorWithClient.class.getClassLoader());
HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);
// map processing logic
hazelcastInstance.shutdown();
}
我在初始化 CassandraMapStoreFactory 时看到以下问题。 Java 9 模块功能似乎有问题,我正在使用 Java 11。请指导我如何在 client/server 部署方法中使用 Hazelcast 地图存储中的 Cassandra 驱动程序
Caused by: java.lang.IllegalAccessError: class com.datastax.driver.core.AbstractAddressableByIndexData cannot access its abstract superclass com.datastax.driver.core.AbstractGettableByIndexData (com.datastax.driver.core.AbstractAddressableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @3614246c; com.datastax.driver.core.AbstractGettableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @4890c0d0)
除非您绝对需要动态,否则我建议不要使用用户代码部署。标称路径实际上是在其 class 路径上使用必要的 classes 启动成员。
添加 JAR 就像设置 CLASSPATH
环境变量一样简单。它适用于 ZIP 分发和 Docker 图像。
这是展示它的 docker-compose.yaml
文件的摘录:
version: '3'
services:
server:
container_name: hz
image: hazelcast/hazelcast:4.0
ports:
- 5701:5701
volumes:
- /Users/nico/.m2/repository:/opt/hazelcast/classpath
environment:
- CLASSPATH=/opt/hazelcast/classpath/org/json/json/20200518/json-20200518.jar:/opt/hazelcast/classpath/org/jetbrains/kotlin/kotlin-stdlib/1.3.72/kotlin-stdlib-1.3.72.jar:/opt/hazelcast/classpath/com/github/kittinunf/fuel/fuel/2.2.3/fuel-2.2.3.jar:/opt/hazelcast/classpath/com/github/kittinunf/result/result/3.0.1/result-3.0.1.jar
我正在尝试使用由 Cassandra 支持的 MapStore。为此,使用 ClientUserCodeDeploymentConfig 将这些 MapStore 和 MapLoader 实现推送到 Hazelcast 成员,如下所示
public class CassandraMapStoreFactory implements MapStoreFactory<String, Long> {
@Override
public MapLoader<String, Long> newMapStore(String mapName, Properties properties) {
return new CassandraPersistence(buildSession());
}
private Session buildSession() {
try {
ConsistencyLevel consistencyLevel = ConsistencyLevel.LOCAL_QUORUM;
PoolingOptions poolingOptions = new PoolingOptions()
.setMaxRequestsPerConnection(HostDistance.LOCAL, 1024)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 256);
Cluster cluster = Cluster.builder()
.addContactPoints("15.207.180.45")
.withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel))
.withSocketOptions(new SocketOptions().setReadTimeoutMillis(12000))
.withPoolingOptions(poolingOptions)
.withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(10000, 2))
.build();
return cluster.connect("sample");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
下面是将客户端代码推送到 Hazelcast 的代码 member/server
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
ClientUserCodeDeploymentConfig codeDeploymentConfig = new ClientUserCodeDeploymentConfig().setEnabled(true)
.addClass(CounterEntryProcessor.class).addClass(CassandraMapStoreFactory.class).addClass(CassandraPersistence.class).addJar("cassandra-driver-core-3.1.2.jar");
config.setUserCodeDeploymentConfig(codeDeploymentConfig);
config.setClassLoader(MapIdGeneratorWithClient.class.getClassLoader());
HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);
// map processing logic
hazelcastInstance.shutdown();
}
我在初始化 CassandraMapStoreFactory 时看到以下问题。 Java 9 模块功能似乎有问题,我正在使用 Java 11。请指导我如何在 client/server 部署方法中使用 Hazelcast 地图存储中的 Cassandra 驱动程序
Caused by: java.lang.IllegalAccessError: class com.datastax.driver.core.AbstractAddressableByIndexData cannot access its abstract superclass com.datastax.driver.core.AbstractGettableByIndexData (com.datastax.driver.core.AbstractAddressableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @3614246c; com.datastax.driver.core.AbstractGettableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @4890c0d0)
除非您绝对需要动态,否则我建议不要使用用户代码部署。标称路径实际上是在其 class 路径上使用必要的 classes 启动成员。
添加 JAR 就像设置 CLASSPATH
环境变量一样简单。它适用于 ZIP 分发和 Docker 图像。
这是展示它的 docker-compose.yaml
文件的摘录:
version: '3'
services:
server:
container_name: hz
image: hazelcast/hazelcast:4.0
ports:
- 5701:5701
volumes:
- /Users/nico/.m2/repository:/opt/hazelcast/classpath
environment:
- CLASSPATH=/opt/hazelcast/classpath/org/json/json/20200518/json-20200518.jar:/opt/hazelcast/classpath/org/jetbrains/kotlin/kotlin-stdlib/1.3.72/kotlin-stdlib-1.3.72.jar:/opt/hazelcast/classpath/com/github/kittinunf/fuel/fuel/2.2.3/fuel-2.2.3.jar:/opt/hazelcast/classpath/com/github/kittinunf/result/result/3.0.1/result-3.0.1.jar