Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Foreach mediator #2252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SanojPunchihewa
Copy link
Contributor

Purpose

Add new Foreach mediator which will iterate collection referred using body or variable and update the original collection or output the result to a variable.

Syntax

<foreach collection="expression" parallel-execution=(true | false) result-target=(variable) result-type="JSON" >
        <sequence>
        (mediator)+
        </sequence>+
</foreach>

Sample configuration

  1. Output iteration results to variable
<foreach collection="${payload.data.list}" result-target="fileList" result-type="JSON" parallel-execution="true">
    <sequence>
        <log category="INFO">
            <message>Processing message : ${payload} with counter : ${var.counter}</message>
        </log>
        <payloadFactory media-type="json">
            <format><![CDATA[{
                "_name": ${payload.name},
                "age": 5
                }]]>
                </format>
        </payloadFactory>
        <call> 
            <endpoint>
                <http method="post" uri-template="http://localhost:5454/api/pet1"/>
            </endpoint>
        </call>
    </sequence>
</foreach>
  1. Update the original collection
<foreach collection="${var.folderList}" parallel-execution="true">
    <sequence>
        <log category="INFO">
            <message>Processing message : ${payload}</message>
        </log>
        <call>
            <endpoint>
                <http method="post" uri-template="http://localhost:5454/api/transform">
                </http>
            </endpoint>
        </call>
    </sequence>
</foreach>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant