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
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  • What ChatGPT Needs Is Context
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Which Is Better for IoT: Azure RTOS or FreeRTOS?

Trending

  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  • What ChatGPT Needs Is Context
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Which Is Better for IoT: Azure RTOS or FreeRTOS?
  1. DZone
  2. Coding
  3. Frameworks
  4. Exploring Apache Camel Core - DataSet Component

Exploring Apache Camel Core - DataSet Component

Zemian Deng user avatar by
Zemian Deng
·
Sep. 08, 13 · Interview
Like (0)
Save
Tweet
Share
7.96K Views

Join the DZone community and get the full member experience.

Join For Free

A good sample data generator can help you test a program more thoroughly and help measure the processing throughput. The camel-core comes with a dataset component that can help you do this easily. All you need is to provide a bean that implements the org.apache.camel.component.dataset.DataSet interface, and bind it in the CamelContext registry. Here is an example:

package camelcoredemo;

import org.slf4j.*;
import org.apache.camel.*;
import org.apache.camel.builder.*;
import org.apache.camel.main.Main;
import org.apache.camel.component.dataset.*;

public class DataSetDemoCamel extends Main {
    static Logger LOG = LoggerFactory.getLogger(DataSetDemoCamel.class);
    public static void main(String[] args) throws Exception {
        DataSetDemoCamel main = new DataSetDemoCamel();
        main.enableHangupSupport();
        main.addRouteBuilder(createRouteBuilder());
        main.bind("sampleGenerator", createDataSet());
        main.run(args);
    }
    static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                from("dataset://sampleGenerator")
                .to("log://demo");
            }
        };
    }
    static DataSet createDataSet() {
        return new SimpleDataSet();
    }
}

Compile and run it.

mvn compile exec:java -Dexec.mainClass=camelcoredemo.DataSetDemoCamel

In this example, we have used the built-in org.apache.camel.component.dataset.SimpleDataSet implementation, which by default, will generate 10 messages with a text body set to <hello>world!</hello>. You may easily change the value, or even provide your own implementation starting with the org.apache.camel.component.dataset.DataSetSupport base class to customize your data set.

Use DataSet Component to Measure Throughput

One useful feature of the dataset component I found is using it to load test your Route. To do this, you have to adjust a couple of settings. Let’s say I want to load a large text file as sample input data and feed it to the Route, and then measure its throughput.

 static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                from("dataset://sampleGenerator?produceDelay=0")
                .to("log://demo?groupSize=100");
            }
        };
    }
    static DataSet createDataSet() {
        SimpleDataSet result = new SimpleDataSet();
        result.setSize(500);
        result.setDefaultBody(readFileToString("my-large-sample.txt");
        return result;
    }

Replace above in the Main class and you will notice that it pumps 500 messages into the Route, and it samples every 100 messages and displays its through-rates. I have to add a produceDelay=0 option to the generator so it will not pause between messages. Then I have added a groupSize=100 option to the log component for throughput measurement. I skipped the readFileToString(String) demo code since I assume you can easily figure that out on your own. (Hint: Check out the Apache commons-io library.)

There is another side of the dataset component that you may use, and that is to receive and verify message content. You would simply use the same URL in a to(url) line. Internally Camel would assert your message body against your original.

There are more options available from the DataSet component that you may explore. Try it out with a Route and see it for yourself.

Apache Camel

Published at DZone with permission of Zemian Deng, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  • What ChatGPT Needs Is Context
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Which Is Better for IoT: Azure RTOS or FreeRTOS?

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: