Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive streams and components on OSGi

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Reactive streams and components on OSGi

Avatar for Christian Schneider

Christian Schneider

February 24, 2023

More Decks by Christian Schneider

Other Decks in Programming

Transcript

  1. 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
  2. Reactive … sounds good ... but what is it really?

    Responsive Resilient Elastic Message Driven Source: http://www.reactivemanifesto.org/
  3. Pull based approach Good for pull based protocols • JMS

    • Kafka • Imap Not so good for push based protocols • HTTP • EventAdmin • MQTT
  4. 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, ...
  5. 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); }
  6. 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));
  7. 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
  8. 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
  9. 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
  10. 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