codereal
codereal

Reputation: 150

Spring Integration Flows

So I am working on a spring integration application which has hundreds of flows.All these flows basically represent a service in the application like

Report Generation
Customer Search
Get Customer Transactions
Customer Activity Stream
etc.

I wanted to validate requests sent to these flows(basically checking parameter specifications are met),so i created another flow separately for validating requests,so that any request sent to the above services will first go through the validation flow. Now I am wondering how to factor that into the service flows.

See below for details.

Validation flow --- >

    <int:channel id="svcExeGovernorEntryLoggerChannel"/>

    <int:channel id="svcExeGovernorEntryRespChannel" >
        <int:interceptors>
            <int:wire-tap channel="svcExeGovernorEntryLoggerChannel"/>
        </int:interceptors>
    </int:channel>

    <int:transformer id="serviceExecutionGovernorEntry" ref="serviceExecutionGovernor" method="serviceExecutionEntry" input-channel="svcExeGovernorEntryReqChannel" output-channel="svcExeGovernorEntryRespChannel"/> 

    <int:logging-channel-adapter id="svcExeGovernorEntryLogger" channel="svcExeGovernorEntryLoggerChannel"  logger-name="svcExeGovernor-entry-logger" />

</beans>

I tried using a bridge as below,but these does not work,its send the output another service.

<int:channel id="customerCrawlReqChannel">
        <int:interceptors>
            <int:wire-tap channel="customerCrawlLoggerChannel"/>
        </int:interceptors>
    </int:channel>
    <int:channel id="customerCrawlRespChannel">
        <int:interceptors>
            <int:wire-tap channel="customerCrawlLoggerChannel"/>
        </int:interceptors>
    </int:channel>
    <int:channel id="customerCrawlLoggerChannel"/>
    <int:channel id="customerCrawlResultChannel">
        <int:interceptors>
            <int:wire-tap channel="customerCrawlLoggerChannel"/>
        </int:interceptors>
    </int:channel>
    <int:channel id="customerCrawlJsonChannel"/>

    <http:inbound-gateway id="customerCrawlInboundGateway"
                          supported-methods="POST"
                          mapped-request-headers="User-Agent,Content-Type"
                          request-payload-type="java.lang.String"
                          path="/service/customercrawl"
                          reply-timeout="50000"
                          request-channel="customerCrawlReqChannel"
                          reply-channel="customerCrawlRespChannel">        
    </http:inbound-gateway>


    <int:bridge input-channel="customerCrawlReqChannel" output-channel="svcExeGovernorEntryReqChannel"/>


    <int:transformer id="customerCrawlPrvder" ref="crawlCustomerProviderService" method="crawlCustomer" input-channel="svcExeGovernorEntryRespChannel" output-channel="customerCrawlResultChannel"/>        


    <int:header-enricher input-channel="customerCrawlResultChannel"        output-channel="customerCrawlRespChannel">
        <int:header name="Content-Type" expression="'application/json'" />
    </int:header-enricher>       
    <int:logging-channel-adapter   
    id="customerCrawlLogger"channel="customerCrawlLoggerChannel"  logger-
    name="customerCrawl-logger"/>

Any suggestion around this please,thanks in advance.

Upvotes: 0

Views: 828

Answers (1)

Gary Russell
Gary Russell

Reputation: 174739

If there are multiple subscribers to svcExeGovernorEntryRespChannel then those responses will be round-robin distributed to those consumers; there's nothing in the framework that can tell which subscriber flow to return to.

If you want to add the same validation flow to multiple flows in the same context, use a mid-flow gateway...

<int:service-activator 
            input-channel="customerCrawlReqChannel" 
            output-channel="customerCrawlReqAfterValidationChannel"
            ref="validationGW" />

<int:gateway id="validationGW"
            default-request-channel="svcExeGovernorEntryLoggerChannel"
            default-reply-channel="svcExeGovernorEntryRespChannel" />

This is like a method call in java with the input message as a parameter and the output message the result.

Or, you can use a routing slip. Set up the route to the next element after the validation, and remove the output channel from the last element in the validation flow.

Upvotes: 1

Related Questions