Apache Camel Examples

repository·main·Indexed 19 days ago

https://github.com/apache/camel-examples

Example implementations for Apache Camel, featuring the Resume API for large-scale data processing. Includes demonstrations for distributed messaging with Hazelcast on Kubernetes, as well as Resume API modules for file offsets, file sets with Write Ahead Log (WAL), AWS Kinesis, and CassandraQL, often utilizing Kafka for offset management.

Tokens
30.8K
Snippets
168
Records
229
Agent score
67%

What's inside apache-camel-examples

  1. Overview of the Resume API File Set Example

    main

    This example demonstrates how to use the Resume API to process large directories containing many files (approximately 500 in this demo) using the Camel file component.

    Key features include:

    • Batch Processing: The route reads files in batches (e.g., 50 files) and then stops.
    • Stateful Resumption: When the process restarts, it resumes from the last file processed in the previous execution.
    • Offset Management: Processing offsets are persisted in a Kafka topic to ensure continuity across restarts.

    Note: This demo is designed to run within a container. Running it outside a container requires additional infrastructure not covered in this documentation. The execution speed is intentionally slowed down for demonstration purposes.

  2. Overview of Main Endpoint DSL with AWS2 S3 to Kafka

    main

    This example demonstrates how to use the Camel Endpoint DSL to define endpoints using type-safe fluent builders (compiled Java methods). The specific workflow implemented in this example polls an AWS S3 bucket and forwards the data to a Kafka topic.

    Prerequisites

    • AWS Credentials: The example uses the AWS default credentials provider. Ensure your environment is configured according to the AWS SDK for Java credentials guide.
    • Configuration: You must specify your S3 bucket name and the target Kafka topic in the application.properties file.
  3. Overview of the Clusterized File Set Resume API Example

    main

    This example demonstrates how to use the Resume API to process a large directory (approximately 500 files) in a clusterized environment.

    Key features include:

    • Clustering: Uses the camel-master component alongside the camel-file component to distribute work across multiple nodes (e.g., Camel 1 and Camel 2).
    • Batch Processing: The configuration reads files in batches (e.g., 25 files) and then stops, allowing a secondary node to take over.
    • State Persistence: Processing offsets are stored in a Kafka topic, allowing a primary node to resume from the exact file it last processed after a restart or failover.
    • Infrastructure: The demo utilizes Kafka and Zookeeper. For simplicity, the demo reuses the same Zookeeper instance for both Kafka and the cluster coordination.

    Note: This demo is designed to run in containers. Running it outside of a containerized environment requires manual setup of the necessary infrastructure and is not supported by this guide.

  4. Overview of Camel Main Endpoint DSL with AWS2 components

    main

    This example demonstrates how to use the Camel Endpoint DSL to define endpoints using type-safe fluent builders (compiled Java methods) specifically for AWS2 components including EventBridge, SQS, and S3.

    The project is organized into three functional submodules:

    1. EventBridge module (aws2-eventbridge-creator): Creates an EventBridge rule that targets an SQS queue.
    2. SQS Consumer module (aws2-sqs-consumer): Consumes events arriving in the SQS queue.
    3. S3 Events inject module (aws2-s3-events-inject): Uploads a file to an S3 bucket (and automatically creates the bucket as a first step).

    Configuration is managed via the application.properties file.

  5. Overview of Camel Example Route Loader with multiple DSLs

    main

    This example demonstrates Apache Camel's ability to load routes during startup using the route loader system. This system supports multiple Domain Specific Languages (DSLs), allowing you to define routes in different formats without them being part of the standard compiled source code.

    Supported DSLs in this example include:

    • Java: Routes defined in .java files (e.g., MyRouteBuilder.java) are loaded and dynamically compiled at runtime using camel-java-joor-dsl.
    • YAML: Routes defined in .yaml files (e.g., my-yaml-route.yaml) are loaded via the camel-yaml-dsl engine.
    • XML: Routes defined in .xml files (e.g., cheese-route.xml) are loaded via the camel-xml-io-dsl engine.
  6. Overview of Camel Example Kamelet

    main

    This example demonstrates how to use Route Templates (parameterized routes) to define a skeleton route. These templates can then be used to dynamically create and add new routes using Kamelets.

    Key components of this example:

    • Route Templates: Defined in MyRouteTemplates.java.
    • Routes: Defined in MyRoutes.java.
    • Application Entrypoint: The example runs standalone via Camel Main in MyApplication.java.
  7. Overview of Resume API Examples

    main
    The resume-api module provides several implementation examples demonstrating different use cases for the Resume API. These examples showcase how to handle large-scale data processing tasks such as large files and large directories, with options for using a Write Ahead Log (WAL) for enhanced reliability.
  8. Overview of the Resume API File Offsets Example

    main

    This example demonstrates how to use the Apache Camel Resume API to process large files incrementally. It utilizes the file component to read text files.

    Key Behavior:

    • The route processes a fixed number of lines (e.g., 30 lines) and then stops.
    • Upon restart, the Resume API allows the route to continue from the exact line where the previous execution left off.
    • Offsets (the state of where processing stopped) are persisted in a Kafka topic to ensure continuity across restarts.

    Note: This demo is designed to run within a containerized environment. Running it outside of containers requires manual setup of the necessary infrastructure (like Kafka).

  9. Use Route Templates in XML

    main

    This example demonstrates how to use Apache Camel Route Templates to define parameterized route skeletons using XML DSL.

    Key components of this pattern:

    1. Template Definition: Define the skeleton route using XML DSL in a template resource (e.g., templates/my-route-templates.xml).
    2. Route Instantiation: Use a builder resource (e.g., builders/my-template-builder.xml) to instantiate specific routes from the template by providing different sets of parameters.
    3. Execution: The example is designed to run standalone via Camel Main using a Java entry point (MyApplication.java).
  10. Explore JMX Example Routing and Configuration

    main

    To understand the specific routing logic and MBean interactions implemented in this example, you can inspect the following directories:

    • Java Logic: Located in src/main/java.
    • Spring XML Configuration: Located in src/main/resources/META-INF/spring.