OSGi Community Event 2017 Presentation by Christian Schneider [Adobe]
Reactive frameworks allow to implement non blocking asynchronous processing in a convenient way. This talk explores how to apply reactive patterns to typical use cases on OSGi like REST services, MQTT Message processing, computations over sliding windows.
We combine messaging and reactor.io streams like also used in Spring 5 to create services that are highly scalable while not tying the user to the technologies being used.
The presented reactive components framework allows to abstract from the messaging technologies using OSGi services. These offer standard Publishers and Subscribers that work nicely with any reactive framework based on the reactive streams API.
This allows to create integrations like with Apache Camel but in a much leaner and OSGi compliant way.
2. Christian Schneider
» For the last 6 years:
Open Source Architect at Talend
» Since October:
Computer scientist at Adobe.
» Apache member and committer
» Twitter @schneider_chris
» Website liquid-reality.de
3. Reactive … sounds good ...
but what is it really?
Responsive
ResilientElastic
Message Driven
Source: http://www.reactivemanifesto.org/
7. Pull based approach
Good for pull based protocols
● JMS
● Kafka
● Imap
Not so good for push based protocols
● HTTP
● EventAdmin
● MQTT
8. ProjectReactor.io
» Built on reactive streams api
» Core of Spring 5
» Very similar to rxjava but optimized for Java 8+
» No additional dependencies
» OSGi ready
Flux.interval(of(1, ChronoUnit.MILLIS))
.window(2, 1)
.flatMap(win -> MathFlux.averageDouble(win));
.subscribe(System.out::println);
0.5, 1.5, 2.5, 3.5, ...
9. Apache Karaf Reactive components
» Component API
» No built in DSL
» Use any DSL based on reactive streams API
» Optimized for OSGi but also works in plain java
public interface RComponent {
<T> Publisher<T> from(String destination, Class<T> type);
<T> CloseableSubscriber<T> to(String destination, Class<T> type);
}
11. Using reactive components
Retrieve the mqtt reactive component as a service
@Reference(target="(name=mqtt)")
RComponent mqtt;
Send a counter to mqtt every second
Flux.interval(Duration.ofSeconds(1))
.map(ByteArrayConverter::fromLong)
.subscribe(mqtt.to("input", byte[].class));
12. Why not Apache Camel?
» No separate component API. All components depend on
camel core
» Acquired too many features over time without proper
design changes (async, transactions, tracing, …)
» No support for backpressure
13. Reactive Components and Camel
» Bridging from reactive components to
camel is possible
=> using camel-rx Adapter
» Camel component for reactive components
http://camel.apache.org/rx.html
14. Why not OSGi push streams instead
of reactive streams?
» OSGi Push streams is a great DSL and engine
but
» Only used on OSGi -> much smaller eco system
» Not compatible to reactive streams API
» Does not have a small API suitable for components
» Can not be used with a different DSL
16. Reactive
Is it the golden hammer?
» Can make system a lot more resilient in high load
situations (backpressure)
» Makes it easier to code in an asynchronous way
but
» Only works well if all steps are non blocking
» Much of the infrastructure as well as user
code is still blocking
» Coding in a reactive DSL is a very steep learning
curve