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 Scatter Gather mediator #2231

Merged
merged 6 commits into from
Dec 13, 2024

Conversation

SanojPunchihewa
Copy link
Contributor

@SanojPunchihewa SanojPunchihewa commented Nov 6, 2024

Purpose

Add new mediator to clone the messages and aggregate the results.

Syntax

<scatter-gather parallel-execution=(true | false) result-target=(body | variable) content-type=(JSON | XML) root-element=(string) >
    <aggregation expression="expression" condition="expression" timeout="long"
    min-messages="expression" max-messages="expression"/>
        <sequence>
        (mediator)+
        </sequence>+
</scatter-gather>

Sample configuration

<scatter-gather parallel-execution="true">
    <aggregation value="json-eval($)"/>
        <sequence>
            <payloadFactory media-type="json" template-type="default">
                <format>{
                    "pet": {
                        "name": "pet1",
                        "type": "dog"
                    },
                    "status": "success"
                    }</format>
                <args>
                </args>
            </payloadFactory>
            <log category="INFO" level="custom">
                <property name="Message" value="==== DONE scatter target 1 ===="/>
            </log>
        </sequence>
        <sequence>
            <call>
                <endpoint>
                    <http method="get" uri-template="http://localhost:5454/api/pet2"/>
                </endpoint>
            </call>
            <log category="INFO" level="custom">
                <property name="Message" value="==== DONE scatter target 2 ===="/>
            </log>
        </sequence>
</scatter-gather>

@SanojPunchihewa SanojPunchihewa force-pushed the scatter-gather branch 3 times, most recently from 8e410ba to 1c0e2ef Compare November 22, 2024 05:51
@SanojPunchihewa SanojPunchihewa force-pushed the scatter-gather branch 2 times, most recently from 684fb76 to 6c6b6eb Compare December 2, 2024 03:40
@SanojPunchihewa SanojPunchihewa force-pushed the scatter-gather branch 4 times, most recently from cae9aeb to d304c77 Compare December 4, 2024 04:30
MessageContext newCtx = null;
if (Objects.equals(contentType, JSON_TYPE)) {
JsonArray jsonArray = new JsonArray();
log.debug("Merging aggregated JSON responses to body");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check before log debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not doing any string concatenations, we don't need to check debugEnabled

@SanojPunchihewa SanojPunchihewa force-pushed the scatter-gather branch 2 times, most recently from 1b4379f to f320da0 Compare December 5, 2024 08:45

OMAttribute contentTypeAttr = elem.getAttribute(CONTENT_TYPE_Q);
if (contentTypeAttr == null || StringUtils.isBlank(contentTypeAttr.getAttributeValue())) {
String msg = "The 'content-type' attribute is required for the configuration of a Scatter Gather mediator";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed to derive this from the message context, and make this optional right? Was that changed?

Copy link
Contributor Author

@SanojPunchihewa SanojPunchihewa Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are creating a new message after aggregating the responses we cannot derive this. Since the new synapse expression return a JSON object from XML payload and vice versa, the new message will be converted to the given content type. Further we need to have a root element to append XML payload, Hence we will need to have this content type parameter.

GDLMadushanka
GDLMadushanka previously approved these changes Dec 13, 2024
@SanojPunchihewa SanojPunchihewa merged commit 546f86c into wso2:master Dec 13, 2024
1 of 2 checks passed
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.

3 participants