Skip to content

IkoAfianando/rust-camel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rust Message Processor (Rust Camel)

A Rust implementation of enterprise integration patterns inspired by Apache Camel. This project demonstrates how to build a robust message processing system using Rust's async capabilities and clean architecture principles.

🌟 Features

  • Message processing pipeline similar to Apache Camel
  • Clean Architecture implementation
  • Async processing with Tokio
  • REST API with Actix-web
  • Docker support for development and production
  • Comprehensive test suite
  • Health check endpoints
  • Logging and error handling
  • Type-safe message processing

πŸ—οΈ Architecture

The project follows Clean Architecture principles with the following layers:

src/
β”œβ”€β”€ domain/          # Core business logic and interfaces
β”‚   β”œβ”€β”€ models/      # Domain entities
β”‚   └── ports/       # Interface definitions
β”œβ”€β”€ application/     # Use cases and business rules
β”‚   β”œβ”€β”€ processors/  # Message processors
β”‚   β”œβ”€β”€ pipeline/    # Processing pipeline
β”‚   └── services/    # Application services
β”œβ”€β”€ infrastructure/  # External implementations
β”‚   β”œβ”€β”€ repositories/
β”‚   └── adapters/
└── interfaces/      # Delivery mechanisms
    β”œβ”€β”€ api/         # REST API
    └── cli/         # Command line interface

πŸš€ Getting Started

Prerequisites

  • Rust 1.75 or higher
  • Docker and Docker Compose (optional)
  • curl (for testing)

Local Development

  1. Clone the repository:
git clone https://github.com/yourusername/rust-camel.git
cd rust-camel
  1. Build the project:
cargo build
  1. Run tests:
cargo test
  1. Run the application:
cargo run

Using Docker

  1. Development environment:
# Build and start development environment
./dev.sh build
./dev.sh start

# Run tests in Docker
./dev.sh test
  1. Production environment:
# Build and start production environment
./dev.sh prod-build
./dev.sh prod-start

πŸ“‘ API Endpoints

Create Message

curl -X POST http://localhost:8080/api/messages \
  -H "Content-Type: application/json" \
  -d '{"body":"This is a test message"}'

Process Message

curl -X POST http://localhost:8080/api/messages/process \
  -H "Content-Type: application/json" \
  -d '{
    "message_id":"<ID_FROM_PREVIOUS_RESPONSE>",
    "additional_data":"optional extra information"
  }'

Health Check

curl http://localhost:8080/health

πŸ”§ Configuration

The application can be configured using environment variables:

RUST_LOG=debug              # Log level (debug, info, warn, error)
RUST_BACKTRACE=1           # Enable backtraces

πŸ§ͺ Testing

The project includes several types of tests:

  1. Unit tests:
cargo test
  1. Specific test:
cargo test test_process_message
  1. With logging:
RUST_LOG=debug cargo test -- --nocapture

πŸ“¦ Available Processors

  1. LoggingProcessor

    • Logs message processing events
    • Configurable prefix
  2. EnricherProcessor

    • Adds metadata to messages
    • Configurable enrichment data
  3. TransformProcessor

    • Transforms message content
    • Customizable transformation functions
  4. FilterProcessor

    • Filters messages based on conditions
    • Configurable predicates

πŸ› οΈ Development Tools

The project includes several development tools:

# Development script
./dev.sh [command]

Available commands:
  build       - Build development environment
  start       - Start development environment
  stop        - Stop development environment
  test        - Run tests
  prod-build  - Build production image
  prod-start  - Start production environment
  logs        - Show logs
  clean       - Clean up containers and volumes

πŸ”’ Security

  • Non-root user in production Docker image
  • Proper error handling
  • Input validation
  • No sensitive data logging

πŸ“Š Monitoring

  • Health check endpoint
  • Logging with different levels
  • Docker healthcheck configuration

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by Apache Camel
  • Built with Rust and its amazing ecosystem
  • Thanks to all contributors

πŸ“š Further Reading

πŸ€” FAQ

Q: Why use Rust instead of Java/Apache Camel? A: Rust offers memory safety, zero-cost abstractions, and excellent performance. This implementation provides similar patterns with Rust's benefits.

Q: How do I add a new processor? A: Implement the Processor trait for your new processor and add it to the pipeline. See existing processors for examples.

Q: How do I customize the processing pipeline? A: Modify the pipeline configuration in main.rs to add, remove, or reorder processors.

πŸ“§ Contact

Find me on twitter: @Iko Afianando

Project Link: https://github.com/IkoAfianando/rust-camel

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors