user3816170
user3816170

Reputation: 321

recipient-list-router Spring integration

i'm new in spring integration. In my configuration of spring integration i have :

  <int:chain input-channel="channel1_2" output-channel="channel1_3">
    <int:service-activator>
        <bean class="com.csv.CSVEntreprise"/>
    </int:service-activator>
</int:chain>

<int:channel id="channel1_3"/>

<int:recipient-list-router id="id-entreprise" input-channel="channel1_3">
    <int:recipient channel="channel1_3TRUE" />
    <int:recipient channel="channel1_3FALSE"/>
</int:recipient-list-router>

<int:channel id="channel1_3TRUE"/>
<int:channel id="channel1_3FALSE"/>

In the class CSVEntreprise i definied method with Boolean return, i want when it's return true use the channel channel1_3TRUE and when it's return false use the channel channel1_3FALSE ?

Upvotes: 2

Views: 3305

Answers (1)

Luhar
Luhar

Reputation: 1889

You might want to consider using a header value router (http://docs.spring.io/spring-integration/reference/html/messaging-routing-chapter.html).

You use your CSVEnterprise bean to set the Boolean value in the MessageHeaders.

Your @ServiceActivatorshould set the value of your header:

return MessageBuilder.withPayload(message)
                    .setHeader("MY_HEADER", Boolean.FALSE).copyHeadersIfAbsent(headers).build();

Then, use a header value router to determine which channel to route the order.

<int:header-value-router input-channel="channel1_3" header-name="MY_HEADER" id="headerValueRouter">
    <int:mapping value="true" channel="channel1_3TRUE"/>
    <int:mapping value="false" channel="channel1_3FALSE" />
</int:header-value-router>

Upvotes: 3

Related Questions