Reactor in spring integration

Artem. Glad to see the new version of si. Can reactor or rxjava be used in spring integration thread? Like this

For example: Enter xml with some collection => reactive separator-> reactive transformer-> reactive outgoing

+3


source to share


1 answer


First of all, thanks for your feedback and attention to our work. We try to follow the real world trends and go forward to be always on time; -).

Well, as for a reactor or similar solution for jet streams.

I'm sure it would be nice to make your "scratch". Even if Spring Integration looks like reactive threads, it doesn't matter that we have to combine them that way.

First of all, Spring Integration is a "managed" streaming declaration that requires a Spring Container, so if you want to combine it with a Reactor, you must access the Spring container from this code that provides Stream

. On the other hand, in order to access the Reactor integration Stream

from Spring, we have to make this Spring bean finally.

The upcoming Spring Integration 4.1 introduces Promise<?> Gateway

. So if yours is Controller

or Service

is a Spring bean and the code consists of a Reactor Stream

, you access the Spring integration flow using the gateway interface, and the result of that integration flow will be populated as Event

for the next action down the flow.

Something similar you can do the other way around when you need push

to integrate Spring instead of pull

.



Let's assume you have a 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"/>

      

In any case, I do not recommend constantly moving from one world to another, because we can lose the best of them. Or reactor thread is main thread, Spring integration.

I would be glad to hear other thoughts from our Reactor team :-).

+2


source







All Articles