In Spring Integration, processing is developed by connecting processing with channel, but if you want to combine multiple processing as one processing, it is convenient to use chain.
I will omit the specific bean definition, but when the flow definition is as follows
Before applying chain
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:int="http://www.springframework.org/schema/integration"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
   ">
  <!--Messaging gateway-->
  <int:gateway id="gateway" default-request-channel="wwwChannel"
    service-interface="com.example.WwwGateway">
  <int:filter input-channel="wwwChannel" output-channel="xxxChannel"/>
  <int:transformer input-channel="xxxChannel" output-channel="yyyChannel" />
  <int:service-activator input-channel="yyyChannel" output-channel="zzzChannel" />
With chain ...
After applying the chain
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:int="http://www.springframework.org/schema/integration"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
   ">
  <!--Messaging gateway-->
  <int:gateway id="gateway" default-request-channel="wwwChannel"
    service-interface="com.example.WwwGateway">
  <int:chain input-channel="wwwChannel" output-channel="zzzChannel">
    <int:filter/>
    <int:transformer />
    <int:service-activator />
  </chain>
Can be written!
It also has the advantage of preventing the flow definition from becoming full of channels: blush :.
So, the main subject is from here.
If you are developing a complicated application, you want a chain that puts together a chain that puts together multiple processes.
Intuitively, I wrote it like ↓, considering how to write chain.
I tried to put together a chain
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:int="http://www.springframework.org/schema/integration"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
   ">
  <!--Messaging gateway-->
  <int:gateway id="gateway" default-request-channel="wwwChannel"
    service-interface="com.example.WwwGateway">
  <!--Chain that puts process A and process B together-->
  <int:chain input-channel="wwwChannel" output-channel="zzzChannel">
    <int:chain id="aProcess"/>
    <int:chain id="bProcess"/>
  </chain>
  <!--Process A-->
  <int:chain id="aProcess">
    <int:filter/>
    <int:transformer />
    <int:service-activator />
  </chain>
  <!--Process B-->
  <int:chain id="bProcess">
    <int:filter/>
    <int:transformer />
    <int:service-activator />
  </chain>
So, as a result of execution, a runtime error ...: disappointed_relieved:
Specify an appropriate ʻinput-channel for the chainof the process A and thechain of the process B, or write the chainof the process A in thechain` that combines the process A and the process B. Was no good.
I was worried for a while, but when I read the document again, the method was written: sweat :.
At the bottom of 6.6.2 Configuring a Chain, under Calling a Chain from within a Chain,
Sometimes you need to make a nested call to another chain from within a chain and then come back and continue execution within the original chain. To accomplish this you can utilize a Messaging Gateway by including a
element. 
I see……
When I wrote the <int: gateway> tag in the chain that combines process A and process B and described the input-channel of process A and process B in the request-channel attribute, the expected behavior was achieved. Ta!
You did it!
Revised
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:int="http://www.springframework.org/schema/integration"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
   ">
  <!--Messaging gateway-->
  <int:gateway id="gateway" default-request-channel="wwwChannel"
    service-interface="com.example.WwwGateway">
  <!--Chain that puts process A and process B together-->
  <int:chain input-channel="wwwChannel" output-channel="zzzChannel">
    <int:gateway request-channel="aChannel" />
    <int:gateway request-channel="bChannel" />
  </chain>
  <!--Process A-->
  <int:chain id="aProcess" input-channel="aChannel">
    <int:filter/>
    <int:transformer />
    <int:service-activator />
  </chain>
  <!--Process B-->
  <int:chain id="bProcess" input-channel="bChannel">
    <int:filter/>
    <int:transformer />
    <int:service-activator />
  </chain>
Read the docs: joy:
Recommended Posts