user1200972
user1200972

Reputation: 33

parallel multicast route w/POST at end

I have a camel route that receives a single message that contains multiple tasks. Using parallel multicast I can run these tasks side by side. This seems to work. However, I need the post for the task results to happen as soon as any task finishes. What happens instead is before postResult can post results back, it waits for both task types to finish.

class Tasks
    List<Task> tasks;

class ParallelTask1
    // Return taskResult1

class ParallelTask2
    // Return taskResult2

class PostTaskResult
    // Post Result

How do I rework this route to post in parallel?

from(tasks)
    .multicast()
    .parallelProcessing()
        .to(parallelTask1)
        .to(parallelTask2)
    .end()
    .to(postResult);

Upvotes: 0

Views: 60

Answers (1)

TacheDeChoco
TacheDeChoco

Reputation: 3913

Not sure to have fully understood the requirements, but you could move the postResult stuff "inside" rather than "outside" the multicast:

from(tasks)
    .multicast()
    .parallelProcessing()
        .to("direct:parallelTask1")
        .to("direct:parallelTask2")
    .end()
    .log("All tasks are terminated");

 from("direct:parallelTask1")
    .to(parallelTask1)
    .log("Task1 terminated")
    .bean(postResult, "postTask1Result");

from("direct:parallelTask2")
    .to(parallelTask2)
    .log("Task2 terminated")
    .bean(postResult, "postTask2Result");

Upvotes: 1

Related Questions