1
votes

I wonder if Apache Camel can be replaced by Reactor or some other Reactive Streams (RS) library.

I'm new to Reactor and RS world, but seems that I managed to prepare some Flux that is listening to JMS messages, although I'm not sure how correct my approach is (this project helped me do it - https://github.com/tonvanbart/gs-messaging-jms-reactive). Main component:

@Component
public class PublisherMessageListener {

    private final DefaultMessageListenerContainer jmsContainer;

    public PublisherMessageListener(DefaultMessageListenerContainer jmsContainer, EventProcessor processor) {
        this.jmsContainer = jmsContainer;
        publisher().subscribe(processor::process);
    }

    private Flux<String> publisher() {
        return Flux.from(subscriber -> {
            MessageListener listener = message -> {
                if (message instanceof TextMessage) {
                    TextMessage textMessage = (TextMessage) message;
                    try {
                        subscriber.onNext(textMessage.getText());
                    } catch (Exception e) {
                        subscriber.onError(new RuntimeException(e));
                    }
                }
            };
            jmsContainer.setMessageListener(listener);
        });
    }
}

I send messages using jmsTemplate.convertAndSend(DESTINATION_NAME, "{ 'type': 'CUSTOMER', 'id': 1 }") and EventProcessor processes each message.

Is reactive part correct?

I'd like to also understand, if exception handling with redeliveries can be done in Reactor as well as aggregation of messages. These things:

onException(RuntimeException.class)
    .maximumRedeliveries(2)
    .to(ERROR_URI);

from(URI)
    .aggregate(expression(this::getKey), AggregationStrategies.useLatest())
    .completionTimeout(DELAY_MILLIS)

I started playing with Reactor as it will be in Spring at some point. Akka Streams seem more Scala oriented to me (don't know about its Java support). Reactor also seemed more Java 8 oriented than RxJava as well as I liked Reactor's Flux and Mono instead of only one Flowable. But if you can provide good arguments why specific library is better, i'd be happy to hear them.

1
Is there a particular reason you want to replace Camel? What advantages are you trying to gain? - Souciance Eqdam Rashti
Well, not strong arguments, but I thought Reactive Streams and Camel are somewhat similar, but RS seemed more lightweight as well as I wanted to try something new. =D - RunninglVlan

1 Answers

2
votes

As of camel 2.11 there is a camel-rx module that itegrates RxJava APIs. http://camel.apache.org/rx.html