0
votes

I have the below integration flow defined in my project

///

public IntegrationFlow acarsEventFlow() {
    return IntegrationFlows
            //.from(Jms.messageDrivenChannelAdapter(this.acarsMqListener)) //Get Message from MQ
            .from(org.springframework.integration.jms.dsl.Jms.messageDrivenChannelAdapter(
                    org.springframework.integration.jms.dsl.Jms.container(this.acarsMqConnectionFactory, this.acarsQueue)
                    .transactionManager(transactionManager(this.acarsMqConnectionFactory))
                    .get()))
            .wireTap(ACARS_WIRE_TAP_CHNL) 
            .transform(agmTransformer, "parseXMLMessage") //
            .handle(acarsProcessor, "pushRawMessage") // (1)Call web service to push the message payload and if it fails then don't commit the transaction and rollback the message
            .transform(agmTransformer, "populateSmi") 
            .filter(acarsFilter,"filterMessageOnSmi") // 
            .transform(agmTransformer, "populateImi") //
            .filter(acarsFilter,"filterMessageOnSmiImi") //
            .transform(acarsProcessor,"processEvent") //
            .publishSubscribeChannel(pubSub -> pubSub
                    .subscribe(flow -> flow
                        .bridge(e -> e.order(Ordered.HIGHEST_PRECEDENCE))
                        .enrichHeaders(h -> h.headerExpression(KafkaHeaders.MESSAGE_KEY, "payload.flightNbr")) //Add flight number as key
                        .transform("payload.message") // publish the transformed message
                        .handle(Kafka.outboundChannelAdapter(kafkaTemplate).topic(acarsKafkaTopic))) //publish to kafka
                    .subscribe(flow -> flow
                        .channel(UPDATE_DATA_STORE_CHNL))) 
            .get(); 

}

///

I am getting a message from a MQ, started a transaction manager to ensure that message is rolled back unless it is processed. Now in one of the handle method # pushRawMessage() [please refer to the comment (1)Call web service to push the message payload in the above snippet] I need to call a webservice. Currently I am just calling the webservice from inside the handler - pushRawMessage(). Is it a good idea to introduce a Messaging Gateway to call the 3rd party web service? if we introduce a mEssaging Gateway then how can we ensure that the original message is rolled back when the webservice is down?

1

1 Answers

0
votes

That's OK to have it like it is right now. Also it is good to use a .gateway() to perform some sub-flow for that web service process. As long as everything is done in the same thread, when you use only direct channels, everything is going to participate in the same transaction. Therefore any error in that sub-flow will cause a transaction to be rolled back.

You also can have that web service process as an async, as long as you use gateway(). It is going to wait for reply or error anyway in the current thread. So, transaction is going to be rolled back again.