Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Reactive streams and components on OSGi

424 Aufrufe

Veröffentlicht am

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 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.

Veröffentlicht in: Technologie

Reactive streams and components on OSGi

  1. 1. Reactive streams and components on OSGi Christian Schneider
  2. 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. 3. Reactive … sounds good ... but what is it really? Responsive ResilientElastic Message Driven Source: http://www.reactivemanifesto.org/
  4. 4. Reactive Streams Spec http://www.reactive-streams.org/ Publisher Subscriber Processor Subscription Extends both creates uses
  5. 5. Reactive Streams implementations Reactor
  6. 6. Backpressure Subscriber Subscription Publisher subscribe onsubscribe publisher.subscribe(subscriber) subscriber.onSubscribe(subscription) subscription.request(num events) subscriber.onNext(T event) onComplete() pull Async push limited to requested num
  7. 7. Pull based approach Good for pull based protocols ● JMS ● Kafka ● Imap Not so good for push based protocols ● HTTP ● EventAdmin ● MQTT
  8. 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. 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); }
  10. 10. Mqtt Reactive Component Configuration Mqtt component Service RComp name=mqtt
  11. 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. 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. 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. 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
  15. 15. Demo time Reactive in action
  16. 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
  17. 17. Thanks for your attention Questions?
  18. 18. Further reading Project Reactor Reactive Components Reactive Streams Push stream examples