Skip to content

HeyAlaia/RuleEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Eport Daemon Rule Engine

Version Java Spring Boot Spring Cloud License

🌐 Language / 语言

English | δΈ­ζ–‡

πŸ“‹ Overview

Eport Daemon Rule Engine is an enterprise-grade rule engine system built for port management operations. It provides a unified framework supporting both Drools and LiteFlow rule engines, enabling flexible business rule management and execution in distributed microservice environments.

The system is designed to handle complex business logic validation, data processing workflows, and automated decision-making processes commonly found in port and logistics management systems.

✨ Key Features

  • πŸ”„ Dual Rule Engine Support: Native support for both Drools and LiteFlow rule engines
  • πŸ—οΈ Microservice Architecture: Built on Spring Cloud with Nacos service discovery
  • πŸ”Œ Flexible Rule Loading: Support for local file system and Redis-based rule storage
  • πŸ“Š Enterprise Integration: Seamless integration with existing Eport ecosystem
  • πŸ›‘οΈ Security & Authentication: Built-in OAuth2 and JWT security mechanisms
  • πŸ“ˆ Performance Monitoring: Comprehensive logging and monitoring capabilities
  • 🐳 Container Ready: Docker support for easy deployment
  • πŸ”§ Hot Reload: Dynamic rule reloading without service restart

πŸ› οΈ Technology Stack

Core Framework

  • Java 21: Latest LTS version with modern language features
  • Spring Boot 3.x: Enterprise application framework
  • Spring Cloud 2023.x: Microservice infrastructure
  • Nacos: Service discovery and configuration management

Rule Engines

  • Drools 10.1.0: Business rule management system
  • LiteFlow 2.15.0: Lightweight rule orchestration engine

Data & Storage

  • MyBatis Plus: Enhanced ORM framework
  • MySQL/MSSQL/Oracle/PostgreSQL: Multi-database support
  • Druid: High-performance connection pool
  • Redis: Caching and rule storage

Infrastructure

  • Docker: Containerization
  • Undertow: High-performance web server
  • Maven: Build and dependency management

πŸš€ Quick Start

Prerequisites

  • JDK 21+: Required for compilation and runtime
  • Maven 3.6+: For project build management
  • Docker: Optional, for containerized deployment
  • Nacos Server: For service registration and configuration

Installation Steps

  1. Clone Repository
git clone https://github.com/your-org/eport-rule-engine.git
cd eport-rule-engine
  1. Build Project
# Build all modules
mvn clean package

# Build specific profile
mvn clean package -P cloud
  1. Configure Services

Update application.yml in the starter module:

spring:
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
      config:
        server-addr: localhost:8848
  1. Run Application
# Run from starter module
cd eport-rule-engine-starter
java -jar target/eport-rule-engine-starter-5.9.0.jar

Docker Deployment

# Build Docker image
cd eport-rule-engine-starter
docker build -t eport-rule-engine:latest .

# Run container
docker run -d \
  --name eport-rule-engine \
  -p 19992:19992 \
  -e NACOS_HOST=your-nacos-server \
  eport-rule-engine:latest

πŸ“š Project Structure

eport-rule-engine/
β”œβ”€β”€ eport-rule-engine-core/          # Core rule engine implementation
β”‚   β”œβ”€β”€ src/main/java/
β”‚   β”‚   └── com/eport/daemon/rule/
β”‚   β”‚       β”œβ”€β”€ common/              # Common constants and enums
β”‚   β”‚       β”œβ”€β”€ engine/              # Rule engine abstractions
β”‚   β”‚       β”‚   β”œβ”€β”€ impl/            # Drools and LiteFlow implementations
β”‚   β”‚       β”‚   β”œβ”€β”€ AbstractRuleEngine.java
β”‚   β”‚       β”‚   β”œβ”€β”€ RuleEngine.java
β”‚   β”‚       β”‚   β”œβ”€β”€ RuleEngineBuilder.java
β”‚   β”‚       β”‚   └── RuleEngineFactory.java
β”‚   β”‚       β”œβ”€β”€ pojo/                # Data models
β”‚   β”‚       β”œβ”€β”€ storage/             # Rule storage and loading
β”‚   β”‚       β”‚   └── impl/            # Local and Redis implementations
β”‚   β”‚       └── utils/               # Utility classes
β”‚   └── pom.xml
β”œβ”€β”€ eport-rule-engine-starter/       # Spring Boot application starter
β”‚   β”œβ”€β”€ src/main/java/
β”‚   β”‚   └── com/eport/daemon/rule/
β”‚   β”‚       β”œβ”€β”€ EportDaemonRuleEngineApplication.java
β”‚   β”‚       └── liteflow/            # LiteFlow components
β”‚   β”œβ”€β”€ src/test/                    # Test cases and examples
β”‚   β”‚   β”œβ”€β”€ java/                    # Unit tests
β”‚   β”‚   └── resources/rules/         # Sample rules
β”‚   β”‚       β”œβ”€β”€ drools/              # Drools rule files (.drl)
β”‚   β”‚       └── liteflow/            # LiteFlow rule files (.xml)
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── pom.xml
β”œβ”€β”€ pom.xml                          # Parent POM
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
└── README_CN.md

πŸ”§ Configuration

Rule Engine Configuration

The system supports multiple rule engines through the EngineType enumeration:

  • DROOLS: Traditional rule-based engine for complex business logic
  • LITEFLOW: Lightweight orchestration engine for workflow management

Rule Storage Options

Configure rule loading strategy in your application:

  • Local File System: Load rules from classpath or file system
  • Redis: Centralized rule storage with hot reload capabilities

Database Support

The system supports multiple database types:

  • MySQL
  • Microsoft SQL Server
  • Oracle Database
  • PostgreSQL

πŸ“ Rule Examples

Drools Rules (.drl)

package rules.engine.set.ruleset1
import com.alibaba.fastjson.JSONObject

rule "vehicle_weight_check"
when
    $fact:JSONObject(getInteger("weight") != null && getInteger("weight") >= 60)
then
    $fact.put("overweight", 1);
    System.out.println("Vehicle is overweight");
end

LiteFlow Rules (.xml)

<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <chain name="validation_chain">
        THEN(weight_check, cargo_check, WHEN(special_check, standard_check));
    </chain>
</flow>

πŸ§ͺ Testing

Run the test suite to verify functionality:

# Run all tests
mvn test

# Run specific test classes
mvn test -Dtest=SimpleLiteFlowTest
mvn test -Dtest=SimpleServiceTest

πŸš€ API Endpoints

The service exposes RESTful APIs under the /admin context path:

  • Base URL: http://localhost:19992/admin
  • API Documentation: Access Swagger UI at /admin/swagger-ui.html

πŸ“ˆ Monitoring & Observability

Health Checks

  • Spring Boot Actuator endpoints
  • Custom health indicators for rule engines

Logging

  • Structured logging with Logback
  • Configurable log levels per component
  • Integration with centralized logging systems

Metrics

  • Application performance metrics
  • Rule execution statistics
  • System resource monitoring

πŸ”’ Security

  • OAuth2 Authentication: Secure API access
  • JWT Token Support: Stateless authentication
  • Role-based Authorization: Fine-grained access control
  • API Encryption: Request/response encryption support

🀝 Contributing

We welcome contributions to improve the Eport Rule Engine! Please follow these guidelines:

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

Development Guidelines

  • Follow Java coding standards and best practices
  • Write comprehensive unit tests for new features
  • Update documentation for API changes
  • Ensure backward compatibility when possible

πŸ“„ License

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

πŸ“ž Support & Contact

Project Maintainer: @HeyAlaia

Enterprise Support: Contact our enterprise team for commercial support and customization services.


Built with ❀️ for the Eport ecosystem

About

RuleEngine By Everything

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published