Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:22:58+00:00 2026-05-24T20:22:58+00:00

In my Spring Integration powered project I have a splitter and payload-router for sending

  • 0

In my Spring Integration powered project I have a splitter and payload-router for sending my data to various transformers. The new “transformed” objects are then passed back to an aggregator and processed.

Now I want to split up my aggregated results so they are persisted properly, since I need to route some of the objects to a seperate outbound-channel-adapter. To achieve this, I added a second splitter after my aggregator; but it seems only the first element in the aggregated collection is passed to the router.

This is my current flow:

<splitter ref="articleContentExtractor" />

<!-- This router works exactly as expected -->
<payload-type-router>
    ... routing to various transformers ...
    ... results are sent to articleOutAggregateChannel ...
</payload-type-router>

<aggregator ref="articleAggregator" />

<splitter />

<!-- This is where it seems to go wrong, the second
        splitter returns only the first object in the collection -->    
<payload-type-router resolution-required="true">
    <mapping type="x.y.z.AbstractContent" channel="contentOutChannel" />
    <mapping type="x.y.z.Staff" channel="staffOutChannel" />
</payload-type-router>

<outbound-channel-adapter id="contentSaveService" ref="contentExporter" 
    method="persist" channel="contentOutChannel" />

<outbound-channel-adapter id="staffSaveService" ref="staffExporter" 
    method="persist" channel="staffOutChannel" />

And my Aggregator code:

@Aggregator
public List<? super BaseObject> compileArticle(List<? super BaseObject> parts) {

    // Search for the required objects for referencing
    Iterator<? super BaseObject> it = parts.iterator();
    Article article = null;
    List<Staff> authors = new ArrayList<Staff>();

    while (it.hasNext()) {
        Object part = it.next();
        if (part instanceof Article) {
            article = (Article)part;
        }
        else if (part instanceof Staff) {
            authors.add((Staff)part);
        }
    }

    // Apply references
    article.setAuthors(authors);

    return parts;
}

What am I doing wrong? Am I using my aggregator properly?

Note: If I just remove both the aggregator and second splitter altogether, the rest of the flow works perfectly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:23:00+00:00Added an answer on May 24, 2026 at 8:23 pm

    It is hard to tell everything that is going on since I don’t have all your code, but I was able to make this flow work the way I think you wanted. The baseObjectTransformer does nothing but set a flag on the objects passing through it:

    ...
    <context:component-scan base-package="net.grogscave.example" />
    
    <channel id="inputChannel" />
    
    <splitter ref="articleContentExtractor" input-channel="inputChannel"
        output-channel="splitArticleStaff" />
    
    <channel id="splitArticleStaff" />
    
    <payload-type-router input-channel="splitArticleStaff">
        <mapping type="net.grogscave.example.domain.Article" channel="articleChannel" />
        <mapping type="net.grogscave.example.domain.Staff" channel="staffChannel" />
    </payload-type-router>
    
    <channel id="articleChannel" />
    
    <transformer input-channel="articleChannel" output-channel="articleOutAggregateChannel"
        ref="baseObjectTransformer"/>
    
    <channel id="staffChannel" />
    
    <transformer input-channel="staffChannel" output-channel="articleOutAggregateChannel"
        ref="baseObjectTransformer"/>
    
    <channel id="articleOutAggregateChannel" />
    
    <aggregator ref="articleAggregator" input-channel="articleOutAggregateChannel" output-channel="splitArticleInChannel"/>
    
    <channel id="splitArticleInChannel" />
    
    <splitter input-channel="splitArticleInChannel" output-channel="splitArticleOutChannel" />
    
    <channel id="splitArticleOutChannel" />
    
    <payload-type-router resolution-required="true" input-channel="splitArticleOutChannel">
        <mapping type="net.grogscave.example.domain.Article" channel="contentOutChannel" />
        <mapping type="net.grogscave.example.domain.Staff" channel="staffOutChannel" />
    </payload-type-router>
    
    <channel id="contentOutChannel">
        <queue capacity="10" />
    </channel>
    
    <channel id="staffOutChannel">
        <queue capacity="10" />
    </channel>
    ...
    

    I then just exercise this flow with the following code in a test case:

        ...
        AbstractApplicationContext context = new ClassPathXmlApplicationContext(
                "/META-INF/spring/split-agg-split.xml",
                SplitAggSplitTests.class);
    
        MessageChannel inputChannel = context.getBean("inputChannel",
                MessageChannel.class);
    
        PollableChannel contentOutChannel = context.getBean("contentOutChannel",
                PollableChannel.class);
    
        PollableChannel staffOutChannel = context.getBean("staffOutChannel",
                PollableChannel.class);
    
        inputChannel.send(new GenericMessage<String>("Dewey Wins!,A. Fool, C. Lewlis"));
    
        logger.info("==> Article recieved: "
                + contentOutChannel.receive(0).getPayload());
    
        for(int i = 0; i < 2; i++)
        {
            logger.info("==> Staff recieved: "
                    + staffOutChannel.receive(0).getPayload());
        }
        ...
    

    My logging output produces all three entities.

    All that being said, have you considered simply removing the extra splitter/aggregator and simply moving the setAuthors logic to your first splitter? I don’t know all the details of your flow, but it would seem to simplify things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring Integration project where I am trying to call a method
Does anybody has an experience with Spring Integration project as embedded ESB? I'm highly
I am new to Spring Integration. I've configured a Spring file inbound-channel-adapter, e.g. <file:inbound-channel-adapter
I'm considering message serialization support for spring-integration . This would be useful for various
I am working on a spring integration project (1.0.2) and can't get the @Header
I have a self-executable jar program that relies heavily on Spring Integration. The problem
I have an event-driven application based on MDB, spring integration and JPA for persistence.
I want to use Spring Batch and Spring Integration to import data from database
I am using spring 2.5.6 and spring-integration 1.0.3 and MQ client 6.0.2.2 I have
I have a spring-integration transformer that accepts a org.w3c.dom.Document and returns a domain object.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.