我在cassandra实现中使用了with x框架。( https://github.com/ef-labs/vertx-cassandra )我使用DefaultCassandraSession作为本地主机。
但是,当尝试检查sesssion时,不是初始化的。这里的代码:
public class CassandraClientVerticle extends AbstractVerticle{
private CassandraSession session;
@Override
public void init(Vertx vertx, Context context) {
CassandraConfigurator configurator = new JsonCassandraConfigurator(vertx);
session = new DefaultCassandraSession(new Cluster.Builder(), configurator,vertx);
}
@Override
public void start() throws Exception {
System.out.println(session.initialized());
}
}这是我称之为vertx的服务器:
public static void main(String[] args) {
Server server = null;
try {
server = new Server();
server.startServer();
} catch(Exception e) {
if(server != null) {
server.exit("Server execution failure", e);
} else {
LOG.error("Server execution failure", e);
}
}
}
public void startServer() throws Exception {
conf = Configuration.init();
Consumer<Vertx> runner = vertx -> {
try {
DeploymentOptions httpVerticleOptions = createHttpVerticleOptions();
vertx.deployVerticle(HttpVerticle.class.getName(), httpVerticleOptions);
vertx.deployVerticle(CassandraClientVerticle.class.getName());
} catch (Throwable t) {
exit("Vert.x runner failure", t);
}
};
VertxOptions vertxOptions = createVertxOptions();
vertx = Vertx.vertx(vertxOptions);
runner.accept(vertx);
}如何解决会话问题?或者请链接我找不到的工作示例。
发布于 2017-06-01 23:33:59
试试这个..。对我来说很管用
public class MainVerticle extends AbstractVerticle {
private CassandraSession cassandraSession;
@Override
public void init(Vertx vertx, Context context) {
super.init(vertx, context);
cassandraSession = new DefaultCassandraSession( new Cluster.Builder(), new JsonCassandraConfigurator(vertx), vertx);
}
@Override
public void start(Future<Void> startFuture) throws Exception {
cassandraSession.onReady( (v) -> {
System.out.printf( "==> CASSANDRA SESSION INITIALIZED\n\t[%b]\n", cassandraSession.initialized() );
startFuture.complete();
});
}
}https://stackoverflow.com/questions/42953571
复制相似问题