Sotona
Sotona

Reputation: 158

Reactor in spring integration

Artem. Glad to see a new version of si. Is it possible to use reactor, or rxjava in spring integration flow? Like this

For example: Input xml with some collection=>reactive splitter->reactive transformer->reactive outbound

Upvotes: 3

Views: 1780

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

First of all thank you for the feedback and the attention to our work. We are trying to follow with the real world tendencies and go ahead to be always in time ;-).

Well, regarding Reactor or similar Reactive Streams solution.

I'm note sure that it would be good idea to do your "scratch" flow. Even as long as Spring Integration looks like Reactive Streams, it doesn't matter that we should combine them that way.

First of all Spring Integration is a 'managed' flow ad it requires Spring Container, so if you want to combine it with Reactor you should get access to the Spring Container from that code which provides Stream. From other side to get access to a Reactor Stream from Spring Integration we should make it a Spring bean finally.

The upcoming Spring Integration 4.1 introduces Promise<?> Gateway. So if your Controller or Service is a Spring bean and the code is composed via Reactor Stream you get access to the Spring Integration flow using Gateway interface - and the result of that Integration Flow will be populated as an Event to the next Stream Action.

Something similar you can do vise versa, when you need a push action for the Spring Integration instead of pull.

Assume you have Reactor Deffered bean:

@Bean
public Deffered<Integer, Stream<Integer>> reactorStream() {
    Deferred<Integer, Stream<Integer>> stream = Streams.<Integer>defer(new Environment());
    stream.compose().collect(5).timeout(1000);
    return stream;
}

After that we can go ahead and use it from channel-adapter:

<outbound-channel-adapter channel="reactorStreamChannel" ref="reactorStream" method="accept"/>

Anyway I don't recommend to jump from one 'world' to 'another' all the time, because we may lose the best from both of them. Or Reactor Stream is a main flow, all Spring Integration.

I'd be glad to hear some other thoughts from our Reactor team :-).

Upvotes: 2

Related Questions