SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
© Copyright 2019 Pivotal Software, Inc. All rights Reserved.
Reactive Relational
Database Connectivity
Ben Hale – R2DBC Lead, Cloud Foundry Java Lead
@nebhale
Reactive
Programming
! Reactive Programming is the next frontier in
Java for high-efficiency applications
! Fundamentally non-blocking and often paired
with asynchronous behaviors
! Reactive has no opinion on async and many
flows are totally synchronous
! Key differentiator from async is Reactive (pull-
push) back pressure
WebFlux and WebClient
@GetMapping("/health")
Mono<Health> compositeHealth() {
return Mono.zip(
webClient.get().uri("https://alpha-service/health")
.retrieve().bodyToMono(Health.class),
webClient.get().uri("https://bravo-service/health")
.retrieve().bodyToMono(Health.class))
.map(t -> composite(t.getT1(), t.getT2()));
}
Roadblocks
! There are still some barriers to using Reactive
everywhere*
! Cross-process back pressure (networking)
! Working on RSocket to solve this issue
! Simon Baslé, Up Next
! Data Access
! MongoDB, Apache Cassandra, Couchbase
and Redis
! No Relational Database Access
An API designed from the ground
up for reactive programming
https://r2dbc.io
Design Principals
! Utilize Reactive Streams Types and Patterns
! Be completely non-blocking, all the way to the
database
! Utilize wire-protocol features where
available
! Shrink the driver SPI to the minimal set of
operations that are implementation specific,
regardless of usability
! Enable multiple "humane" APIs to be built on top
of the driver
Driver SPI
! One of JDBC's biggest failings was that the
same API had to serve as both a humane API for
users as well as an inhumane API for alternative
clients like JPA, jOOQ, Jdbi, etc.
! This lead to both an API that users didn't like
using and that driver authors didn't like
implementing
! It also lead to drivers duplicating effort
implementing the same "humane" affordances
like ? binding
Driver SPI - Connection Factory
Publisher<Connection> create()
ConnectionFactoryMetadata getMetadata()
Driver SPI - Connection
Publisher<Void> close()
Publisher<Void> beginTransaction()
Publisher<Void> setTransactionIsolationLevel(IsolationLevel isolationLevel)
Publisher<Void> commitTransaction()
Publisher<Void> rollbackTransaction()
Publisher<Void> createSavepoint(String name)
Publisher<Void> releaseSavepoint(String name)
Publisher<Void> rollbackTransactionToSavepoint(String name)
Batch createBatch()
Statement createStatement(String sql)
Driver SPI - Statement
Statement bind(Object identifier, Object value)
Statement bind(int index, Object value)
Statement bind(int index, <primitive types> value)
Statement bindNull(Object identifier, Class<?> type)
Statement bindNull(int index, Class<?> type)
Statement add()
Statement returnGeneratedValues(String... columns)
Publisher<Result> execute()
Driver SPI - Result and Row
Publisher<Integer> getRowsUpdated()
Publisher<T> map(BiFunction<Row, RowMetadata, ? extends T> f)
T get(Object identifier, Class<T> type);
Object get(Object identifier);
Simple Select
Publisher<Object> values = connectionFactory.create()
.flatMapMany(conn ->
conn.createStatement("SELECT value FROM test")
.execute()
.flatMap(result ->
result.map((row, metadata) -> row.get("value"))))
Simple Select
Publisher<String> values = connectionFactory.create()
.flatMapMany(conn ->
conn.createStatement("SELECT value FROM test")
.execute()
.flatMap(result ->
result.map((row, metadata) -> row.get("value",

String.class))))
Simple Prepared Insert
Publisher<Result> results = connectionFactory.create()
.flatMapMany(conn ->
conn.createStatement("INSERT INTO test VALUES($1, $2)")
.bind("$1", 100).bind("$2", 200).add()
.bind("$1", 300).bind("$2", 400).execute())
Transactional Prepared Insert
Publisher<Result> results = connectionFactory.create()
.flatMapMany(conn ->
conn.beginTransaction()
.thenMany(conn.createStatement("INSERT INTO test VALUES($1)")
.bind("$1", 100).add()
.bind("$1", 200).execute())
.delayUntil(p -> conn.commitTransaction())
.onErrorResume(t ->
conn.rollbackTransaction().then(Mono.error(t))))
Great! But a Bit
Verbose
! The Driver SPI contains the minimal set of
operations that are implementation specific and
nothing more
! Definitely usable, but very verbose and prone to
errors
! Explicit transaction management is
analogous to try-catch-finally-try-
catch in JDBC
! What we need is a "humane" client API. In fact
we need many humane client APIs!
Simple Select
Flux<String> values = r2dbc.withHandle(handle ->
handle.select("SELECT value FROM test")
.mapRow(row -> row.get("value", String.class)))
Simple Prepared Insert
Flux<Integer> updatedRows = r2dbc.withHandle(handle ->
handle.createUpdate("INSERT INTO test VALUES($1, $2)")
.bind("$1", 100).bind("$2", 200).add()
.bind("$1", 300).bind("$2", 400).execute())
Transactional Prepared Insert
Flux<String> updatedRows = r2dbc.inTransaction(handle ->
handle.createUpdate("INSERT INTO test VALUES($1, $2)")
.bind("$1", 100).bind("$2", 200).add()
.bind("$1", 300).bind("$2", 400).execute())
Spring Data DatabaseClient
DatabaseClient client = DatabaseClient.create(connectionFactory);
Flux<Person> rows = client.execute()
.sql("SELECT * FROM person WHERE name = :name")
.bind("name", "John Doe")
.as(Person.class)
.fetch()
.all();
Spring Data Repository
interface CustomerRepository extends
ReactiveCrudRepository<Customer, Long> {
@Query("select * from … WHERE lastname = :lastname")
Flux<Customer> findByLastname(String lastname);
}
repository.findByLastname("Matthews")
.doOnEach(c -> System.out.println(c.firstname))
Connection URLs
r2dbcs:postgresql://localhost:5432/db?schema=test
r2dbc:pool:postgresql://localhost:5432/db?schema=test,size=4
ConnectionFactory connectionFactory =
ConnectionFactories.get("r2dbcs:postgresql://localhost:5432/

db?schema=test");
What Can You Do
Today?
! R2DBC 0.8.0.M8, .RC1, .RELEASE
! Driver implementations for H2, Microsoft SQL
Server, PostgreSQL, MySQL (jasync-sql,
r2dbc-mysql)
! Batching
! Extensive Type Conversion
! BLOB/CLOB
! Savepoints
! Transactions
! Leveraging Database-specific features
! ServiceLoader-based driver discovery
! Connection URLs
What Can You Do
Today?
! Specification Document
! r2dbc-spi
! Connection Pooling (reactor-pool)
! Client Implementations
! Spring Data R2DBC
! r2dbc-client
! Observability
! r2dbc-proxy
! Micrometer support
What About the
Alternatives?
! Wrap JDBC in a thread pool
! Unbounded queue leads to resource
exhaustion
! Bounded queue leads to blocking
! Other specifications
! In early stages and similar in design
! Typically a small number of implementations
! Collaboration likely as the market won't
support multiple specifications
Safe Harbor
Statement
The following is intended to outline the general direction of
Pivotal's offerings. It is intended for information purposes
only and may not be incorporated into any contract. Any
information regarding pre-release of Pivotal offerings,
future updates or other planned modifications is subject to
ongoing evaluation by Pivotal and is subject to change.
This information is provided without warranty or any kind,
express or implied, and is not a commitment to deliver any
material, code, or functionality, and should not be relied
upon in making purchasing decisions regarding Pivotal's
offerings. These purchasing decisions should only be
based on features currently available. The development,
release, and timing of any features or functionality
described for Pivotal's offerings in this presentation remain
at the sole discretion of Pivotal. Pivotal has no obligation
to update forward looking information in this presentation.
What Does the
Future Hold?
! Additions/improvements to SPI
! Stored procedures
! Auto-commit, fetch size
! Additional implementations
! Google Cloud Spanner
! SAP Hanna and DB2 are investigating
! Prefer database vendors to own drivers
long-term
! Additional clients
! JOOQ, Jdbi, MyBatis have initial support
Resources
! Website

https://r2dbc.io
! Twitter

@r2dbc
! GitHub

https://github.com/r2dbc
! Mailing List

https://groups.google.com/forum/#!forum/r2dbc
! Weekly Call

Fridays 0630 PT/0930 ET/1530 CET
Questions

Contenu connexe

Tendances

Tendances (20)

Airflow for Beginners
Airflow for BeginnersAirflow for Beginners
Airflow for Beginners
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Developing Microservices with Apache Camel
Developing Microservices with Apache CamelDeveloping Microservices with Apache Camel
Developing Microservices with Apache Camel
 
GraphQL
GraphQLGraphQL
GraphQL
 
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow managementIntro to Airflow: Goodbye Cron, Welcome scheduled workflow management
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
 
Angular Observables & RxJS Introduction
Angular Observables & RxJS IntroductionAngular Observables & RxJS Introduction
Angular Observables & RxJS Introduction
 
Navigating Disaster Recovery in Kubernetes and CNCF Crossplane
Navigating Disaster Recovery in Kubernetes and CNCF Crossplane Navigating Disaster Recovery in Kubernetes and CNCF Crossplane
Navigating Disaster Recovery in Kubernetes and CNCF Crossplane
 
Redis-SGX: Dmitrii Kuvaiskii
Redis-SGX: Dmitrii KuvaiskiiRedis-SGX: Dmitrii Kuvaiskii
Redis-SGX: Dmitrii Kuvaiskii
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
 
kafka
kafkakafka
kafka
 
Streaming SQL with Apache Calcite
Streaming SQL with Apache CalciteStreaming SQL with Apache Calcite
Streaming SQL with Apache Calcite
 
From Postgres to Event-Driven: using docker-compose to build CDC pipelines in...
From Postgres to Event-Driven: using docker-compose to build CDC pipelines in...From Postgres to Event-Driven: using docker-compose to build CDC pipelines in...
From Postgres to Event-Driven: using docker-compose to build CDC pipelines in...
 
Completable future
Completable futureCompletable future
Completable future
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Apache Flink Deep Dive
Apache Flink Deep DiveApache Flink Deep Dive
Apache Flink Deep Dive
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 

Similaire à Reactive Relational Database Connectivity

High Performance Jdbc
High Performance JdbcHigh Performance Jdbc
High Performance Jdbc
Sam Pattsin
 

Similaire à Reactive Relational Database Connectivity (20)

Dropwizard Introduction
Dropwizard IntroductionDropwizard Introduction
Dropwizard Introduction
 
Jdbc
JdbcJdbc
Jdbc
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
R2DBC JEEConf 2019 by Igor Lozynskyi
R2DBC JEEConf 2019 by Igor LozynskyiR2DBC JEEConf 2019 by Igor Lozynskyi
R2DBC JEEConf 2019 by Igor Lozynskyi
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
 
Webinar Oracle adf12c EN
Webinar Oracle adf12c ENWebinar Oracle adf12c EN
Webinar Oracle adf12c EN
 
High Performance Jdbc
High Performance JdbcHigh Performance Jdbc
High Performance Jdbc
 
Going Reactive with Relational Databases
Going Reactive with Relational DatabasesGoing Reactive with Relational Databases
Going Reactive with Relational Databases
 
Web 2.0 Development with IBM DB2
Web 2.0 Development with IBM DB2Web 2.0 Development with IBM DB2
Web 2.0 Development with IBM DB2
 
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
 
"Offline mode for a mobile application, redux on server and a little bit abou...
"Offline mode for a mobile application, redux on server and a little bit abou..."Offline mode for a mobile application, redux on server and a little bit abou...
"Offline mode for a mobile application, redux on server and a little bit abou...
 
Oracle Drivers configuration for High Availability, is it a developer's job?
Oracle Drivers configuration for High Availability, is it a developer's job?Oracle Drivers configuration for High Availability, is it a developer's job?
Oracle Drivers configuration for High Availability, is it a developer's job?
 
Introduction to R2DBC
Introduction to R2DBCIntroduction to R2DBC
Introduction to R2DBC
 
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
 
Walking Through Spring Cloud Data Flow
Walking Through Spring Cloud Data FlowWalking Through Spring Cloud Data Flow
Walking Through Spring Cloud Data Flow
 
Jdbc
JdbcJdbc
Jdbc
 
Data access
Data accessData access
Data access
 
Devoxx 2018 - Pivotal and AxonIQ - Quickstart your event driven architecture
Devoxx 2018 -  Pivotal and AxonIQ - Quickstart your event driven architectureDevoxx 2018 -  Pivotal and AxonIQ - Quickstart your event driven architecture
Devoxx 2018 - Pivotal and AxonIQ - Quickstart your event driven architecture
 
The semantic web an inside look at the creation of control loop foundation
The semantic web   an inside look at the creation of control loop foundationThe semantic web   an inside look at the creation of control loop foundation
The semantic web an inside look at the creation of control loop foundation
 
SQL for NoSQL and how Apache Calcite can help
SQL for NoSQL and how  Apache Calcite can helpSQL for NoSQL and how  Apache Calcite can help
SQL for NoSQL and how Apache Calcite can help
 

Plus de VMware Tanzu

Plus de VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Dernier

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

Reactive Relational Database Connectivity

  • 1. © Copyright 2019 Pivotal Software, Inc. All rights Reserved. Reactive Relational Database Connectivity Ben Hale – R2DBC Lead, Cloud Foundry Java Lead @nebhale
  • 2. Reactive Programming ! Reactive Programming is the next frontier in Java for high-efficiency applications ! Fundamentally non-blocking and often paired with asynchronous behaviors ! Reactive has no opinion on async and many flows are totally synchronous ! Key differentiator from async is Reactive (pull- push) back pressure
  • 3. WebFlux and WebClient @GetMapping("/health") Mono<Health> compositeHealth() { return Mono.zip( webClient.get().uri("https://alpha-service/health") .retrieve().bodyToMono(Health.class), webClient.get().uri("https://bravo-service/health") .retrieve().bodyToMono(Health.class)) .map(t -> composite(t.getT1(), t.getT2())); }
  • 4. Roadblocks ! There are still some barriers to using Reactive everywhere* ! Cross-process back pressure (networking) ! Working on RSocket to solve this issue ! Simon Baslé, Up Next ! Data Access ! MongoDB, Apache Cassandra, Couchbase and Redis ! No Relational Database Access
  • 5. An API designed from the ground up for reactive programming https://r2dbc.io
  • 6. Design Principals ! Utilize Reactive Streams Types and Patterns ! Be completely non-blocking, all the way to the database ! Utilize wire-protocol features where available ! Shrink the driver SPI to the minimal set of operations that are implementation specific, regardless of usability ! Enable multiple "humane" APIs to be built on top of the driver
  • 7. Driver SPI ! One of JDBC's biggest failings was that the same API had to serve as both a humane API for users as well as an inhumane API for alternative clients like JPA, jOOQ, Jdbi, etc. ! This lead to both an API that users didn't like using and that driver authors didn't like implementing ! It also lead to drivers duplicating effort implementing the same "humane" affordances like ? binding
  • 8. Driver SPI - Connection Factory Publisher<Connection> create() ConnectionFactoryMetadata getMetadata()
  • 9. Driver SPI - Connection Publisher<Void> close() Publisher<Void> beginTransaction() Publisher<Void> setTransactionIsolationLevel(IsolationLevel isolationLevel) Publisher<Void> commitTransaction() Publisher<Void> rollbackTransaction() Publisher<Void> createSavepoint(String name) Publisher<Void> releaseSavepoint(String name) Publisher<Void> rollbackTransactionToSavepoint(String name) Batch createBatch() Statement createStatement(String sql)
  • 10. Driver SPI - Statement Statement bind(Object identifier, Object value) Statement bind(int index, Object value) Statement bind(int index, <primitive types> value) Statement bindNull(Object identifier, Class<?> type) Statement bindNull(int index, Class<?> type) Statement add() Statement returnGeneratedValues(String... columns) Publisher<Result> execute()
  • 11. Driver SPI - Result and Row Publisher<Integer> getRowsUpdated() Publisher<T> map(BiFunction<Row, RowMetadata, ? extends T> f) T get(Object identifier, Class<T> type); Object get(Object identifier);
  • 12. Simple Select Publisher<Object> values = connectionFactory.create() .flatMapMany(conn -> conn.createStatement("SELECT value FROM test") .execute() .flatMap(result -> result.map((row, metadata) -> row.get("value"))))
  • 13. Simple Select Publisher<String> values = connectionFactory.create() .flatMapMany(conn -> conn.createStatement("SELECT value FROM test") .execute() .flatMap(result -> result.map((row, metadata) -> row.get("value",
 String.class))))
  • 14. Simple Prepared Insert Publisher<Result> results = connectionFactory.create() .flatMapMany(conn -> conn.createStatement("INSERT INTO test VALUES($1, $2)") .bind("$1", 100).bind("$2", 200).add() .bind("$1", 300).bind("$2", 400).execute())
  • 15. Transactional Prepared Insert Publisher<Result> results = connectionFactory.create() .flatMapMany(conn -> conn.beginTransaction() .thenMany(conn.createStatement("INSERT INTO test VALUES($1)") .bind("$1", 100).add() .bind("$1", 200).execute()) .delayUntil(p -> conn.commitTransaction()) .onErrorResume(t -> conn.rollbackTransaction().then(Mono.error(t))))
  • 16. Great! But a Bit Verbose ! The Driver SPI contains the minimal set of operations that are implementation specific and nothing more ! Definitely usable, but very verbose and prone to errors ! Explicit transaction management is analogous to try-catch-finally-try- catch in JDBC ! What we need is a "humane" client API. In fact we need many humane client APIs!
  • 17. Simple Select Flux<String> values = r2dbc.withHandle(handle -> handle.select("SELECT value FROM test") .mapRow(row -> row.get("value", String.class)))
  • 18. Simple Prepared Insert Flux<Integer> updatedRows = r2dbc.withHandle(handle -> handle.createUpdate("INSERT INTO test VALUES($1, $2)") .bind("$1", 100).bind("$2", 200).add() .bind("$1", 300).bind("$2", 400).execute())
  • 19. Transactional Prepared Insert Flux<String> updatedRows = r2dbc.inTransaction(handle -> handle.createUpdate("INSERT INTO test VALUES($1, $2)") .bind("$1", 100).bind("$2", 200).add() .bind("$1", 300).bind("$2", 400).execute())
  • 20. Spring Data DatabaseClient DatabaseClient client = DatabaseClient.create(connectionFactory); Flux<Person> rows = client.execute() .sql("SELECT * FROM person WHERE name = :name") .bind("name", "John Doe") .as(Person.class) .fetch() .all();
  • 21. Spring Data Repository interface CustomerRepository extends ReactiveCrudRepository<Customer, Long> { @Query("select * from … WHERE lastname = :lastname") Flux<Customer> findByLastname(String lastname); } repository.findByLastname("Matthews") .doOnEach(c -> System.out.println(c.firstname))
  • 23. What Can You Do Today? ! R2DBC 0.8.0.M8, .RC1, .RELEASE ! Driver implementations for H2, Microsoft SQL Server, PostgreSQL, MySQL (jasync-sql, r2dbc-mysql) ! Batching ! Extensive Type Conversion ! BLOB/CLOB ! Savepoints ! Transactions ! Leveraging Database-specific features ! ServiceLoader-based driver discovery ! Connection URLs
  • 24. What Can You Do Today? ! Specification Document ! r2dbc-spi ! Connection Pooling (reactor-pool) ! Client Implementations ! Spring Data R2DBC ! r2dbc-client ! Observability ! r2dbc-proxy ! Micrometer support
  • 25. What About the Alternatives? ! Wrap JDBC in a thread pool ! Unbounded queue leads to resource exhaustion ! Bounded queue leads to blocking ! Other specifications ! In early stages and similar in design ! Typically a small number of implementations ! Collaboration likely as the market won't support multiple specifications
  • 26. Safe Harbor Statement The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation.
  • 27. What Does the Future Hold? ! Additions/improvements to SPI ! Stored procedures ! Auto-commit, fetch size ! Additional implementations ! Google Cloud Spanner ! SAP Hanna and DB2 are investigating ! Prefer database vendors to own drivers long-term ! Additional clients ! JOOQ, Jdbi, MyBatis have initial support
  • 28. Resources ! Website
 https://r2dbc.io ! Twitter
 @r2dbc ! GitHub
 https://github.com/r2dbc ! Mailing List
 https://groups.google.com/forum/#!forum/r2dbc ! Weekly Call
 Fridays 0630 PT/0930 ET/1530 CET