Vert x与cassandra englishtown实现

时间:2017-03-22 13:49:20

标签: cassandra vert.x

我使用带有cassandra的vert x框架正是英文城实现。(https://github.com/ef-labs/vertx-cassandra) 我将DefaultCassandraSession用于localhost 但是当试图检查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);

    }

如何解决会话问题?或者请链接我无法找到的工作示例。

1 个答案:

答案 0 :(得分:1)

尝试这个...它对我有用

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();
        });
    }
}