RxMongo no response sent

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

RxMongo no response sent

durbinjo593
So I think this might be related to this post:

http://forum.ratpack.io/Understanding-when-use-of-ratpack-handling-Context-promise-is-necessary-td789.html

...but I'm still stumped.

The code in this project has a few issues, but from what I can tell, inserts, deletes, get all operations, and updates are all working against Mongo. I get no responses from ratpack, however, and debugging shows that the subscription of the observables within the Ratpack.groovy script itself is receiving the relevant, subscribed object.

The code in the project connect to a free mongo lab instance with a few (2 at the time of writing this) records.

Repo: https://github.com/joshdurbin/rx-mongo-ratpack

Zip: https://github.com/joshdurbin/rx-mongo-ratpack/archive/master.zip
Reply | Threaded
Open this post in threaded view
|

Re: RxMongo no response sent

danhyun
Hi Josh,

You need to let Ratpack know that you're performing some async actions here.

We can take advantage of `Observable.compose` and `RxRatpack.bindExec` to let us subscribe to these mongo-rx based Observables back from Ratpack land.

I've issued a pull request here https://github.com/joshdurbin/rx-mongo-ratpack/pull/1

I've implemented `getPeople()`, `getPerson()`, and `insertPerson()` using this technique. Feel free to implement the rest of the Service methods.
Reply | Threaded
Open this post in threaded view
|

Re: RxMongo no response sent

durbinjo593
Awesome!!! Got it. Makes sense... previous versions of apps had blocking 'blocks' which were managed by ExecControl or used the http client. What you did, mentioned here makes sense.

Thanks for the help.
Reply | Threaded
Open this post in threaded view
|

Re: RxMongo no response sent

danhyun
You'd use the blocking blocks to perform I/O bound activity so as to not block the main processing thread.

Brief summary of when to use what:

`ExecControl.blocking()` allows you to take normal I/O bound blocking calls, e.g. making a database call or writing to a file without NIO and execute it in a separate thread so it doesn't block the thread processing the handler chain.

`ExecControl.promise()` allows asynchronous activity, e.g. `Thread.start()` to be coordinated within Ratpack. `ExecControl.promise()` provides a `Fulfiller` which allows you to respond to the state changes in the asynchronous activity via `Fulfiller.success()` and `Fulfiller.error()`.

With the `ratpack-rx` module we provide a convenience method that allows you to take third party Observables and subscribe back in Ratpack land. `RxRatpack.bindExec` allows you to easily consume third party Observables from Ratpack land. It's really syntactic sugar for `ExecControl.promise`. There are a few more goodies in `RxRatpack` that you may be interested in http://ratpack.io/manual/current/api/ratpack/rx/RxRatpack.html
rus
Reply | Threaded
Open this post in threaded view
|

Re: RxMongo no response sent

rus
In reply to this post by durbinjo593
Because of the groovy extensions in ratpack-rx you can also do

db
    .getCollection('people')
    .find()
    .toObservable()
    .bindExec()

instead of using `compose`