简体   繁体   中英

mule : Batch Processing vs For-each

I have a scenario where I have a list of IDs, for each ID fetch the data from multiple API and aggregate them (this is loading phase) and then write it to DB. I know that we can use batch processing for writing to db, but what about loading phase?

You should be able to use a foreach scope for this.

Your list of ID's will be in your payload before it reaches the foreach . You can use HTTP components set as request-response , this way all the data you need will be fetched before you reach your DB component for saving the data.

Fetching data from multiple APIs is something that takes time and has to be kept inside batch step. For each record, after fetching the data, move that to a VM queue. In the on complete phase, use a mule requester to fetch details from vm queue and insert in db. Inserting in db is a single step and does not require batch processing

You can use scatter-gather for each id and fetch data from multiple api's. Scatter-Gather sends a request message to multiple targets concurrently.Based on the responses you can implement aggregation strategy for responses.

Similar can be done using mule batch as well.

References: https://docs.mulesoft.com/mule-user-guide/v/3.9/scatter-gather

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM