Thor
Thor

Reputation: 650

Subscribe to RxJava Observable in the Background from Spring

I have an RxJava Observable that I'd like to process in the background in my web application. This is so that the service can react to an event on a message queue. Is there a Spring configuration that would allow me to subscribe to this Observable directly?

Something like the Spring TaskExector, that would allow for a background thread to handle the Observable events. But something a little more sophisticated where I wouldn't have to hold the thread alive.

Upvotes: 1

Views: 263

Answers (1)

Tassos Bassoukos
Tassos Bassoukos

Reputation: 16142

What we have done is have a Spring service that creates the Observable and subscribes to it in an @PostConstruct method, and unsubscribes in an @PreDestroy. This allows for stuff like counters and parallelism controls being exposed via JMX, and one can even stop/restart the observable via JMX or via service methods.

Upvotes: 2

Related Questions