Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this library Vertx 3 compatible ? #54

Open
javajack opened this issue Mar 24, 2016 · 9 comments
Open

Is this library Vertx 3 compatible ? #54

javajack opened this issue Mar 24, 2016 · 9 comments
Labels

Comments

@javajack
Copy link

Vertx 3 is already having some data access libraries

http://vertx.io/docs/vertx-sql-common/java/
and
http://vertx.io/docs/vertx-jdbc-client/java/

But I want to leverage this API as it is more intuitive in nature.

Can we use this library with Vertx 3 for asynchronous processing ?

@davidmoten
Copy link
Owner

Hi, I'm not familiar with Vertx 3 so you're on your own here (unless a subscriber to this list knows the product).

@zsiegel
Copy link
Contributor

zsiegel commented Jul 8, 2016

@javajack Yes you can. Just be sure to schedule the work with the RxHelpers class in the vert-rx package

@zsiegel
Copy link
Contributor

zsiegel commented Jul 8, 2016

@javajack a quick example might look something like this...

db.select().autoMap(User.class)
     .subscribeOn(RxHelper.blockingScheduler(vertx))
     .observerOn(RxHelper.scheduler(vertx))
     .subscribe()

@davidmoten I am a fairly new user of this library but my understanding would be that the library is respecting the thread preference by saying subscribeOn and observeOn. In my quick testing this seems to be the case.

@vietj
Copy link

vietj commented Jul 8, 2016

it would be great to have this library to work well with Vert.x

perhaps we can collaborate on integration test with Vert.x 3.x and documentation ?

@davidmoten
Copy link
Owner

@zsiegel yep that's right, normal manipulations with observables are fine as long as some sort of mapping of the ResultSet to an object occurred synchronously. The library leads you that way anyway with the method chaining. You have to do something like this to get into trouble with threads:

db.select()
    .get(rs -> rs) 
    .observeOn(Schedulers.io())
    .map(rs -> rs.getString(1))
    .toList().toBlocking().single();

In the above statement the resultset is mapped to an object on a different thread than the thread on which the resultset was created. Jdbc drivers don't guarantee thread safety in this scenario. As long as you avoid this sort of usage you can do whatever you like to your observables.

@davidmoten
Copy link
Owner

and thanks for answering this one @zsiegel !

@kdurnoga
Copy link

Is setting schedulers with observeOn/subscribeOn needed when using rxjava2-jdbc with non-blocking connections?

@zsiegel
Copy link
Contributor

zsiegel commented Jan 29, 2018

@kdurnoga you should always use the .subscribeOn to ensure you are getting the proper threading behavior. RxJava runs on the current thread by default

@davidmoten
Copy link
Owner

Best to ask rxjava2-jdbc questions on it's project. Default behaviour in rxjava2-jdbc is to run on the io() scheduler because of the non-blocking connection pool. If you have explicit requirements about what thread gets the results use observeOn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants