def show() {
String author = params.author
Book.get(params.id)
.map { Book book ->
rx.render view:"book", model:[book:book, author:author]
}
}
1.1.2 RxJava Support
Version: 3.2.8
1.1.2 RxJava Support
In addition to RxGORM, support for RxJava has been added to the Grails framework via an RxJava plugin.
Reactive controllers with RxJava
The RxJava plugin allows you to return Observable
responses from controllers and integrates seamlessly with RxGORM to make it possible handle requests reactively, in a non-blocking manner. For example:
Server Sent Events with RxJava
It is now possible to easily issue responses that return Server Sent Events with Grails and RxJava:
def index() {
rx.stream { Subscriber subscriber ->
for(i in (0..5)) {
if(i % 2 == 0) {
subscriber.onNext(
rx.render("Tick")
)
}
else {
subscriber.onNext(
rx.render("Tock")
)
}
sleep 1000
}
subscriber.onCompleted()
}
}
See the sample application for a demonstration of Server Sent Events in action |