Child pages
  • JAX-RS RxJava
Skip to end of metadata
Go to start of metadata

RxJava2 Flowable and Observable support

Introduction

RxJava 2 Flowable and Observable are supported on the client and the server side starting from CXF 3.2.0.

org.apache.cxf/cxf-rt-rs-extension-rx/3.2.0 and io.reactivex.rxjava2/rxjava/2.1.3 dependencies are required.

Client

The following simple example uses FlowableRxInvoker. org.apache.cxf.jaxrs.rx2.client.ObservableRxInvoker can be used if needed instead.

Server

As a method return value

One simply returns io.reactivex.Flowable from the method and the runtime will make sure the response is finalized once the Flowable flow is complete.

The only requirement is that one has to register a custom JAX-RS invoker, org.apache.cxf.jaxrs.rx2.server.FlowableInvoker. It does all the default JAXRSInvoker does and only checks if Flowable is returned - if yes then it links it internally with the JAX-RS AsyncResponse.

If needed, io.reactivex.Observable can be returned instead (with org.apache.cxf.jaxrs.rx2.server.ObservableInvoker registered)

Combining Flowable with AsyncResponse

 

 

 

RxJava1 rx.Observable support

Introduction

RxJava 1 rx.Observable is supported on the client and the server side starting from CXF 3.2.0.

org.apache.cxf/cxf-rt-rs-extension-rx/3.2.0 and io.reactivex/rxjava/1.3.0 dependencies are required.

Client

 

Server

As a method return value

One simply returns an Observable from the method and the runtime will make sure the response is finalized once the Observable flow is complete.

The only requirement is that one has to register a custom JAX-RS invoker, org.apache.cxf.jaxrs.rx.server.ObservableInvoker. It does all the default JAXRSInvoker does and only checks if Observable is returned - if yes then it links it internally with the JAX-RS AsyncResponse.

 

  • No labels