getting started: couchbase server java sdk – couchbase live new york 2015

48
Getting Started with the Java SDK Michael Nitschinger, SDK Engineer @daschl

Upload: couchbase

Post on 12-Jan-2017

453 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

Getting Started with the Java SDK

Michael Nitschinger, SDK Engineer@daschl

Page 2: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

Overview

Page 3: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 3

Couchbase SDKs What does it mean to be a Couchbase SDK?

Cluster

Bucket

CRUD View Query

N1QL Query

FunctionalManage connections to the bucket within the cluster for different services.Provide a core layer where IO can be managed and optimized.Provide a way to manage buckets.

APIinsertDesignDocument()flush()listDesignDocuments()

FunctionalHold on to cluster information such as topology.

APIReference Cluster ManagementopenBucket()info()disconnect()

FunctionalGive the application developer a concurrent API for basic (k-v) or document management

APIget()insert()upsert()remove()

FunctionalAllow for querying, execution of other directives such as defining indexes and checking on index state.

APIabucket.NewN1QLQuery( “SELECT * FROM default LIMIT 5” ) .Consistency(gocouchbase.RequestPlus);

FunctionalAllow for view querying, building of queries and reasonable error handling from the cluster.

APIabucket.NewViewQuery().Limit().Stale()

Page 4: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 4

Languages and Interfaces for Couchbase Official SDKs

– Java – Version 2.2– .NET – Version 2.1– Node.js – Version 2.1– Python – Version 2.0

For each of these we have– Full Document support– Interoperability– Common yet idiomatic Programming Model

Others: Erlang, Perl, TCL, Clojure, Scala

PHP – Version 2.0 C – Version 2.5 Go – Version 1.0 Ruby – Version 2.0

DP

JDBC and ODBC

Page 5: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 5

Documents are integral to the SDKs. There are many implementations, depending on the

content type.

A Document contains:

The Document

5

Property DescriptionID The bucket-unique identifierContent The value that is storedExpiry An expiration timeCAS The Compare-And-Swap identifier

Page 6: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 6

Facts Split into two projects

– core-io– java-client

Current Versions (java-client)– 2.2.0 (GA)

Documentation available through http://developer.couchbase.com/documentation/server/4.0/sdks/java-2.2/java-intro.html

6

Page 7: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 7

Couchbase Core IO

7

Common infrastructure & feature set for all language bindings

Message oriented Asynchronous only Low overhead and performance focused Supports Java 6+ (including 8!)

Disruptor RingBuffer for implicit batching and backpressure Netty for high performance IO

Page 8: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 8

Detour: Java Client Architecture

8

Page 9: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 9

Detour: Smart Batching

Source: http://mechanical-sympathy.blogspot.co.at/2011/10/smart-batching.html 9

Page 10: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 10

Detour: Smart Batching

Source: http://mechanical-sympathy.blogspot.co.at/2011/10/smart-batching.html 10

Page 11: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 11

The Big Picture

11

Page 12: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 12

Couchbase Java Client

12

Java Binding on top of core-io

Clusters/Buckets Documents Sync & Async API Bucket and Cluster Management Various Utilities and Helpers

Page 13: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 13

Connecting

13

Page 14: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2014 Couchbase, Inc. — Proprietary and Confidential

©2015 Couchbase Inc. 14

From Sync to Async

14

Page 15: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 15

2.x API

Page 16: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

RxJava 101A Gentle Introduction

Page 17: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 17

Java implementation for Reactive Extensions https://github.com/ReactiveX

A library to compose asynchronous and event-driven programs through observable sequences.

RxJava: Introduction

single multiplesync T Iterable<T>async

Future<T>

Observable<T>

17

Page 18: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 18

Observables are the duals of Iterables They describe both Latency and Error side effects.

RxJava: Introduction

event Iterable<T> (pull) Observable<T> (push)data retrieval

T next() onNext(T)

error discovery

throws Exception onError(Exception)

completion returns onCompleted()

18

Page 19: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 19

Consuming Observables

19

The Observer subscribes and receives events.

A cold Observablestarts when subscribed.

onNext can be called0..N times

Page 20: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 20

RxJava: Creating Observables

just

20

Page 21: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 21

RxJava: Creating Observables

21

Page 22: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 22

RxJava: Creating Observables

22

Page 23: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 23

RxJava: Creating Observables

23

Page 24: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 24

RxJava: Creating Observables

24

Page 25: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 25

RxJava: Creating Observables

25

Page 26: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 26

RxJava: Transforming Observables

26

Page 27: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 27

RxJava: Transforming Observables

27

Page 28: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 28

RxJava: Transforming Observables

28

Page 29: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 29

RxJava: Transforming Observables

29

Page 30: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 30

RxJava: Transforming Observables

30

Page 31: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 31

RxJava: Transforming Observables

31

Page 32: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 32

RxJava: Transforming Observables

32

Page 33: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 33

RxJava: Transforming Observables

33

Page 34: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 34

RxJava: Filtering Observables

34

Page 35: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 35

RxJava: Filtering Observables

35

Page 36: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 36

RxJava: Filtering Observables

36

Page 37: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 37

RxJava: Filtering Observables

37

Page 38: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

Spring Data Couchbase

Page 39: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 39

Spring IO

Page 40: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 40

Spring Data Couchbase

• Integration with Spring Data Templates Repositories Exception Mapping also @Cacheable

• Maps POJO Entities to JSON (and back)• 2.0 M1 Released!

Page 41: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 41

Spring Data Landscape

JDBC/JPA

Page 42: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 42

Repositories – Do this

Page 43: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 43

Repositories – Get this

43

Page 44: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 44

Repositories – Backed by Views

findByFirstname()

findAll(), count()

44

Page 45: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 45

JavaConfig

45

Page 46: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 46

Putting it together

46

Page 47: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

©2015 Couchbase Inc. 47

There is more! Entity mapping (Alias keys, TTLs, @Version for optimistic

concurrency,...)

JavaConfig and XML support CouchbaseTemplate for lower level access @View to customize Views and DesignDocuments @Cacheable suport for transparent caching

Spring Boot and Spring XD integration upcoming

47

Page 48: Getting Started: Couchbase Server Java SDK – Couchbase Live New York 2015

Questions?