DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • RBAC With API Gateway and Open Policy Agent (OPA)
  • Developers Are Scaling Faster Than Ever: Here’s How Security Can Keep Up
  • Multi-Stream Joins With SQL
  • WireMock: The Ridiculously Easy Way (For Spring Microservices)
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Aggregating Everything - Map/Reduce and Camel?

Aggregating Everything - Map/Reduce and Camel?

Col Wilson user avatar by
Col Wilson
·
Jan. 23, 13 · Interview
Like (0)
Save
Tweet
Share
4.55K Views

Join the DZone community and get the full member experience.

Join For Free

If you are used to Map/Reduce you will be used to the idea of breaking tasks down into little chunks and then collecting the partial results together into some final format.

So, recently when I was parsing zillions of rows of data and aggregating related data into partial CSV files  and then aggregating the bits of partial of data to reports I thought - Aha! MapReduce.

For a whole bunch of good design decisions I was using Apache Camel - a neat pipelining tool which with a bit of help from ActiveMQ provides the sort of long running stability that I needed. Camel however does not do Map/Reduce, but it does have the Aggregator Integration pattern, which you can use to so a similar thing.

Image courtesy of Carlos Oliveira
Imagine you empty your jar of loose change on a table. You stack the nickles in stacks of ten coins, the dimes is stacks of ten coins and the quarters in stacks of ten coins. You add up all the 50 cents, $1s and $2.50s and you know how much you have. That's Map/Reduce.

Now, imagine you empty your jar of loose change into one of those coin counting machines in the Mall. Internally all the coins are sorted by falling through a hole which is either nickle, dime or quarter shaped and as they emerge from the other side they are counted*. That's aggregation Camel style.

I did hit a bit of a snag. I couldn't work out how to tell the Aggregator Integration patternthat there were no more files to come... Stop... Woaa-there... Desist!

It turns out that hidden away (in the middle of the docs) the File endpoint rather usefully sets a flag in the headers called CamelBatchComplete which is just what I was looking for:

<route id="report_month_to_date">
    <from uri="file:partials" />
    <unmarshal><csv/></unmarshal>
    <to uri="bean:myCsvHandler?method=doHandleCsvData" />
    <aggregate strategyRef="serviceStrategy">
        <correlationExpression>
            <simple>${header.month} == ${date:now:yyyyMM}</simple>
        </correlationExpression>
        <completionPredicate>
            <simple>${header.CamelBatchComplete}</simple>
        </completionPredicate>
        <to uri="file:reports/?fileName=${header.month}.csv" />
    </aggregate>
</route>

Good luck fellow travelers.

* I have no idea how a coin counting machine works.


COinS Apache Camel Data (computing) Database Machine Integration JAR (file format) CSV hadoop

Published at DZone with permission of Col Wilson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • RBAC With API Gateway and Open Policy Agent (OPA)
  • Developers Are Scaling Faster Than Ever: Here’s How Security Can Keep Up
  • Multi-Stream Joins With SQL
  • WireMock: The Ridiculously Easy Way (For Spring Microservices)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: