简体   繁体   English

新的Cassandra项目 - Astyanax还是Java Driver?

[英]New Cassandra project - Astyanax or Java Driver?

I'm starting a new project with Cassandra (and plan to use the latest stable (1.2.x) version). 我正在与Cassandra开始一个新项目(并计划使用最新的稳定版(1.2.x))。 I have tried several different Java libraries, like Hector , Astyanax , Cassandra-jdbc... 我尝试了几种不同的Java库,比如HectorAstyanax ,Cassandra-jdbc ......

Among them, (in short) my choice is Astyanax. 其中,(简而言之)我的选择是Astyanax。 But then I also found and tried DataStax's Java Driver, which support new CQL binary protocol, and is much cleaner if you are only using CQL. 但后来我也发现并尝试了DataStax的Java驱动程序,它支持新的CQL二进制协议,如果你只使用CQL则更加清晰。 And it seems version 1.0.0 GA will be released soon. 似乎版本1.0.0 GA即将发布。

Which one would you recommend? 你会推荐哪一个? Thanks. 谢谢。

I'd advise you to go with a cql3 based driver. 我建议你使用基于cql3的驱动程序。 Some choices are the the JDBC driver or even better Datastax's driver which supports asynchronous connections. 有些选择是JDBC驱动程序 ,甚至是更好的Datastax驱动程序 ,它支持异步连接。 You might have to build datastax's driver yourself, but this can be done with ease using maven. 您可能必须自己构建datastax的驱动程序,但这可以通过使用maven轻松完成。

Thrift isn't going to be getting any new features in Cassandra, its being kept for backwards comparability and most C* community members advice to use cql based drivers for new projects: Thrift不会在Cassandra中获得任何新功能,它被保留用于向后兼容性,并且大多数C *社区成员建议使用基于cql的驱动程序用于新项目:

As described above, we believe that CQL3 is a simpler and overall better API for Cassandra than the thrift API is. 如上所述,我们认为CQL3是一个比thrift API更简单,整体更好的Cassandra API。 Therefore, new projects/applications are encouraged to use CQL3 因此,鼓励新项目/应用程序使用CQL3

- source - 来源

Also CQL's performance is getting better very quickly. 此外,CQL的性能也在迅速提升。 Here are some outdated benchmarks. 以下是一些过时的基准测试。
UPDATE UPDATE

Since the answer was written a maven central repository was created for the driver so now to use it just add the dependency to maven: 由于答案是写的,因此为驱动程序创建了一个maven中央存储库 ,所以现在使用它只需将依赖项添加到maven:

<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>cassandra-driver-parent</artifactId>
    <version>1.0.0</version>
</dependency>

I have personally used Hector, Astyanax, Pelops, Fluent Cassandra, Datastax's Driver and Pycassa and after using so many API's i finally realized that Astyanax suits me the best (Its my personal consideration). 我个人使用了Hector,Astyanax,Pelops,Fluent Cassandra,Datastax的Driver和Pycassa,在使用了这么多API之后我终于意识到Astyanax最适合我(我个人考虑)。

The feature i found in astyanax which differentiate it from others in the league are 我在astyanax中找到的功能与联盟中的其他功能区别开来

  • Ease of use of the API 易于使用API
  • Composite column support 复合柱支持
  • Connection pooling 连接池
  • Latency 潜伏
  • Documentation 文档
  • Updated 更新

I have used Astyanax. 我用过Astyanax。 It is well documented and easy to use provided you have no problem writing 5 times more code than CQL. 它具有良好的文档和易于使用,前提是您编写的代码比CQL多5倍。

Right now I am using CQL as people I've worked with haven't fully grasped the Astyanax code - why they have to write class for column names. 现在我正在使用CQL,因为我曾与之合作的人还没有完全掌握Astyanax代码 - 为什么他们必须为列名编写类。 I think you will never understand the internals of Cassandra properly if you don't use Astyanax or Hector. 如果你不使用Astyanax或Hector,我想你永远不会理解Cassandra的内部结构。

You should definitely go with the new DataStax Java Driver and Cassandra 1.2 for a new project that is just starting. 你肯定应该使用新的DataStax Java驱动程序和Cassandra 1.2来开始一个新项目。 The driver just went GA, and both the driver and Cassandra 1.2 will only get more stable over the next few months as you develop your new project. 司机刚开始使用GA,在开发新项目时,驱动程序和Cassandra 1.2在接下来的几个月内只会变得更加稳定。

I agree with Zanson/Valchkou. 我赞同Zanson / Valchkou。 DataStax Java Driver is the future. DataStax Java Driver是未来的发展方向。 It's very convenient to operate Cassandra with SQL. 使用SQL操作Cassandra非常方便。 Meanwhile, I also recommend CassandraExecutor , a simple wrapper of DataStax Java Driver . 同时,我还推荐了CassandraExecutor ,它是DataStax Java Driver的一个简单包装器。 Comparing to the Java Driver, CassandraExecutor has below features: 与Java驱动程序相比,CassandraExecutor具有以下功能:

  • Consistent/Integrated/Concise APIs for (sync/Async) operations(CRUD) with SQL/entity. 使用SQL /实体进行(同步/异步)操作(CRUD)的一致/集成/简明API。
  • DataSet , which supports distinct/merge/sort/groupBy/join/union/unionAll/except/intersect/paginate/filter/count/toJOSN/toXML/toCVS... DataSet ,支持distinct / merge / sort / groupBy / join / union / unionAll / except / intersect / paginate / filter / count / toJOSN / toXML / toCVS ...

Here is a simple CRUD(create/read/update/delete) sample: 这是一个简单的CRUD(创建/读取/更新/删除)示例:

Account account = createAccount();
// create
String sql_insert = NE.insert(ID, GUI, FIRST_NAME, LAST_NAME, LAST_UPDATE_TIME, CREATE_TIME).into(Account.class).sql();
cassandraExecutor.execute(sql_insert, account);

// read
String sql_selectByGUI = NE.select(ID, GUI, FIRST_NAME, LAST_NAME).from(Account._).where(L.eq(ID, L.QME)).sql();
Account dbAccount = cassandraExecutor.queryForEntity(Account.class, sql_selectByGUI, account);

// update
String sql_updateByLastName = NE.update(Account.class).set(FIRST_NAME).where(L.eq(ID, L.QME)).sql();

dbAccount.setFirstName("newFirstName");
cassandraExecutor.execute(sql_updateByLastName, dbAccount);

// delete
String sql_deleteByFirstName = NE.deleteFrom(Account.class).where(L.eq(ID, L.QME)).sql();
cassandraExecutor.execute(sql_deleteByFirstName, dbAccount);

(Declaration:I'm the developer of CassandraExecutor) (声明:我是CassandraExecutor的开发者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM