Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

Consultez-les par la suite

1 sur 31 Publicité

Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra

Télécharger pour lire hors ligne

Speaker: Tim Berglund, Global Director of Training at DataStax

So you’re a JVM developer, you understand Cassandra’s architecture, and you’re on your way to knowing its data model well enough to build descriptive data models that perform well. What you need now is to know the Java Driver.

What seems like an inconsequential library that proxies your application’s queries to your Cassandra cluster is actually a sophisticated piece of code that solves a lot of problems for you that early Cassandra developers had to code by hand. Come to this session to see features you might be missing and examples of how to use the Java driver in real applications.

Speaker: Tim Berglund, Global Director of Training at DataStax

So you’re a JVM developer, you understand Cassandra’s architecture, and you’re on your way to knowing its data model well enough to build descriptive data models that perform well. What you need now is to know the Java Driver.

What seems like an inconsequential library that proxies your application’s queries to your Cassandra cluster is actually a sophisticated piece of code that solves a lot of problems for you that early Cassandra developers had to code by hand. Come to this session to see features you might be missing and examples of how to use the Java driver in real applications.

Publicité
Publicité

Plus De Contenu Connexe

Diaporamas pour vous (20)

Les utilisateurs ont également aimé (11)

Publicité

Similaire à Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra (20)

Plus par DataStax Academy (20)

Publicité

Plus récents (20)

Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra

  1. 1. Building Java Applica)ons with Cassandra "VNDGTINWPF
  2. 2. 2000 4000 6000 8000 E000 C000 A000 0000 Client Machine Load Balancer
  3. 3. tim name: Tim role: teacher kristen name: Kristen role: marketing billy role: CEO matt name: Matt role: founder status: active status: chill
  4. 4. https://github.com/datastax/java-­‐driver
  5. 5. DataStax Java Driver • Open source (ASL 2.0) • Where CQL happens • Ac9vely developed • Now faster than ThriD • Doesn’t make you want to die
  6. 6. Every Use Case has a Story
  7. 7. Your Story: ň/C[DG6JTKHVKUPQVVJGEQQNGUVʼn
  8. 8. Gradle Build apply plugin: 'java' repositories { jcenter() } dependencies { compile 'com.datastax.cassandra:cassandra-driver-core:2.1.2' testCompile 'org.testng:testng:6.8.8' testCompile 'junit:junit:4.11' }
  9. 9. Cluster Interface Cluster cluster = Cluster.builder() .addContactPoints(“192.168.50.1”) .build(); Session session = cluster.connect(“IoT_keyspace); session.execute( INSERT INTO sensor (sensor_id, reading, time) VALUES (24601, 2.171828, now())”);
  10. 10. Your Story: ň+LWUVYCPVVQFQCSWGT[ʼn
  11. 11. BasicQueries ResultSet resultSet = session.execute(SELECT * FROM sensor); ListRow rows = resultSet.all(); for(Row row : rows) { String sensorId = row.getString(sensor_id ); double reading = row.getDouble(reading ); Date time = row.getDate(time ); }
  12. 12. Prepared Statements PreparedStatement insertReading = session.prepare( INSERT INTO sensor (sensor_id, reading, time) VALUES (?, ?, ?)” ); Statement statement = insertReading .bind(24601, 2.71828, new Date()) .setConsistencyLevel(ConsistencyLevel.QUORUM); session.execute(statement);
  13. 13. Your Story: ň+YCPVNQCFDCNCPEKPIʼn
  14. 14. 2000 4000 6000 8000 E000 C000 A000 0000 Client Machine
  15. 15. Cluster Interface Cluster cluster = Cluster.builder() .addContactPoints(“192.168.50.1”) .build();
  16. 16. Cluster Interface Cluster cluster = Cluster.builder() .addContactPoints(“192.168.50.1”, “192.168.50.4”, “192.168.50.8”) .build();
  17. 17. Your Story: ň+ņNNLWUVQRVKOKGEQQTFKPCVQT NQCFVJGPʼn
  18. 18. 2000 4000 6000 8000 E000 C000 A000 0000 Client Machine
  19. 19. 2000 4000 6000 8000 E000 C000 A000 0000 Client Machine 1.2ms 2.9ms 15.3ms
  20. 20. Outsmar(ng Yourself • Pick one node • Send all coordina9on traffic to that node • Hey, maybe make it a fat node! • WhiteListPolicy
  21. 21. WhiteListing ListInetSocketAddress whiteList = new ArrayListInetSocketAddress(); whiteList.add(...); Cluster c = Cluster.builder().withLoadBalancingPolicy( new WhiteListPolicy( new RoundRobinPolicy(), whiteList)).build();
  22. 22. Your Story: ň+OKUU,2#ʼn [QWJCXGKUUWGU
  23. 23. Mapper Object apply plugin: 'java' repositories { jcenter() } dependencies { compile 'com.datastax.cassandra:cassandra-driver-core:2.1.2' compile 'com.datastax.cassandra:cassandra-driver-mapping:2.1.2' testCompile 'org.testng:testng:6.8.8' testCompile 'junit:junit:4.11' }
  24. 24. CREATE TABLE sensor ( sensor_id int, reading double, time timestamp ); Mapper Object @UDT(keyspace = IoT_keyspace, name = sensor) public class Sensor { private int sensorId; private double reading; private Date Time; // getters and setters elided with extreme prejudice... }
  25. 25. Mapper Object MappingManager manager = new MappingManager(session); Mapper mapper = manager.mapper(Sensor.class); Sensor reading = mapper.get(24601);
  26. 26. Your Story: ň+NKMGUNQYSWGTKGUʼn
  27. 27. FutureResults ResultSetFuture future = session.executeAsync(SELECT * FROM sensor); // Returns immediately // Go do productive things here… // Then finally block on the results when you must ResultSet futureResults = future.get(); ListRow rows = resultSet.all();
  28. 28. FutureResults Executor executor = Executors.newCachedThreadPool(); ResultSetFuture future = session.executeAsync(SELECT * FROM sensor); future.addListener(new Runnable() { public void run() { // Do the things here… } }, executor);
  29. 29. Your Story: ň6TCPUOKVYKPFQYUJCXGDGGPC VJKPINQPIGTVJCPOQUVFGXGNQRGTU JCXGDGGPCNKXGʼn
  30. 30. Thank You! VNDGTINWPF

×