routesdynamicwso2esbwso2-data-services-server

WSO2 ESB route endpoints based on results from DSS


So pretty much I want to call

/sendAllUsersAnEmail

Which will call the DSS and do something along the lines of SELECT user_id FROM users WHERE status = 'PENDING'

Here is the issue. How can I get the ESB to loop through the results (or can I get the DSS to call an API directly?) and make a call to /sendEmail/{user_id} for each user? or is this not possible and do I need to return the results to an outside language and call the esb again for each results.


Solution

  • If I understand what you need it´s something like that:

    You have a table inside your system DB, with the user_id from users pending to do something in your system and you need to consult this table, get the list of user_id and for every entry in this list made a call to a restful service passing the user_id

    So my idea is:

    1. Use a data service to obtain the user_id list.
    2. Create a proxy service that in seq1 call this data service and in a seq2 get the result.
    3. In seq2 use the iterator mediator and splits the messages into parts and processes them asynchronously like in this sample: https://docs.wso2.com/display/ESB481/Sample+400%3A+Message+Splitting+and+Aggregating+the+Responses

    An example:

    <iterate expression="//m0:getQuote/m0:request" preservePayload="true"
             attachPath="//m0:getQuote"
             xmlns:m0="http://services.samples">
        <target>
            <sequence>
                <send>
                    <endpoint>
                        <address
                            uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                    </endpoint>
                </send>
            </sequence>
        </target>
    </iterate>