Opensabre Framework

repository·main·Indexed 19 days ago

https://github.com/opensabre/opensabre-framework

A microservices development platform based on Spring Cloud 2023, designed for high-security, financial-grade enterprise applications. It provides a suite of starter modules for core infrastructure, communication (RPC, EDA), data persistence, caching, and security. Key components include opensabre-starter-eda for asynchronous event dispatching, opensabre-starter-webflux and opensabre-starter-webmvc for reactive and servlet-based web layers, and opensabre-web for unified return models and user context management.

Tokens
10.4K
Snippets
28
Records
48
Agent score
64%

What's inside Opensabre

  1. Overview of Opensabre Microservices Platform

    main

    Opensabre is a microservices development platform built on Spring Cloud 2023. It is designed to provide a high-security, financial-grade microservices solution by integrating core components like Spring Security and Spring Cloud Alibaba.

    The platform provides out-of-the-box system management applications, including:

    • RBAC (Role-Based Access Control): Foundational permission management.
    • Authentication & Authorization: Secure identity and access management.
    • Gateway Management: Centralized entry point control.
    • Service Governance: Tools for managing microservice interactions and health.
    • Audit Logging: System-wide activity tracking.

    Opensabre enforces development standards and coding styles at the framework level, allowing developers to focus on business logic rather than infrastructure setup or architectural boilerplate. It is designed for modern deployment environments, supporting Docker and Kubernetes.

  2. Overview of opensabre-web

    main

    The opensabre-web package is a general-purpose utility library for web development. It encapsulates common classes and utilities that are independent of specific Spring MVC or Spring WebFlux implementations. Key features include:

    • Unified Return Models: Standardized structures for API responses.
    • Common Exception Definitions: Pre-defined exception types for consistent error handling.
    • Base Forms/VOs: Base classes for Value Objects and form data.
    • Validation Annotations: Custom annotations for data validation.
    • User Context: Utilities for managing and accessing user-related information within a request.
  3. Overview of opensabre-starter-webflux

    main

    The opensabre-starter-webflux module is a common utility package designed to accelerate the development of reactive web applications using Spring WebFlux. It provides several core capabilities out of the box:

    • Spring Boot Auto-configuration: Simplifies the setup of WebFlux components.
    • Global Exception Handling: Provides a centralized mechanism for managing errors in reactive streams.
    • Unified Response Model: Implements the Opensabre Result response model to ensure consistent API responses across your application.
  4. Overview of Opensabre Starter Modules

    main

    Opensabre provides a suite of 'starter' modules designed to provide foundational capabilities to microservices. Instead of manual configuration, applications include these modules as dependencies to automatically bootstrap specific functionalities like caching, RPC, security, and persistence.

    Key module categories include:

    • Core Infrastructure: opensabre-base-dependencies (dependency management), opensabre-starter-boot (application startup), and opensabre-starter-config (configuration management).
    • Communication & Discovery: opensabre-starter-register (service discovery), opensabre-starter-rpc (RPC integration), and opensabre-starter-eda (Event-Driven Architecture).
    • Data & State: opensabre-starter-cache (caching), opensabre-starter-persistence (database/transaction management), and opensabre-starter-webflux/webmvc (web layers).
    • Security & Governance: opensabre-starter-security (internal tokens and user context) and opensabre-starter-governance (rate limiting and auditing).
  5. Access OpenSabre Framework development documentation

    main

    The OpenSabre framework maintains its development documentation within the docs/ directory. While the root README provides repository-level information, specific module APIs and auto-configurations should be verified against the source code.

    Key documentation resources include:

    • Architecture and Modules: Details on multi-module boundaries, dependencies, and the source of truth.
    • Development and Verification: Instructions for building, testing, and compatibility requirements.
    • Starter Module Map: An index of all starter modules, including their descriptions, functions, usage, and roadmaps.
    • Roadmap: The evolution direction of the framework.
  6. How to handle and persist audit events

    main

    By default, the framework publishes AuditEvent objects. To persist these logs to a database or external system, you must implement a custom ApplicationListener<AuditEvent>.

    Best Practice: Since audit events are published after the operation completes, perform heavy persistence tasks (like database writes) inside your custom listener asynchronously to avoid impacting application performance.

  7. Identify stable public APIs and configuration surfaces

    main

    When integrating with Opensabre, the authoritative sources for public APIs, configuration properties, auto-configurations, and conditional loading are located within each module's source code:

    • Public APIs and Logic: src/main/java
    • Auto-configuration and Metadata: src/main/resources/META-INF/
    • Testing Utilities: The module's test suite.

    Note: Do not rely on internal implementation details as stable public APIs unless they are explicitly defined in public packages and covered by the project's versioning strategy.

  8. Understand the Opensabre Maven multi-module structure

    main

    Opensabre is organized as a Maven multi-module project. The root pom.xml serves as the single source of truth for all available modules. The framework is designed around 'Starters' that provide composable foundational capabilities to your applications.

    Key functional modules include:

    • opensabre-base-dependencies: Centralized management of dependency versions.
    • opensabre-test: Provides auxiliary tools and utilities for testing.
    • opensabre-web: Provides common Web capabilities.
    • Starter modules: Designed to be included in your application to provide specific, composable features.
  9. Implement cross-service transport with EventTransport

    main

    The EDA core does not include any MQ clients (RabbitMQ, Kafka, etc.). To enable cross-service communication, you must implement the EventTransport interface and register it as a Spring Bean.

    When publisher.publishRemote(event) is called, the EDA core iterates through all registered EventTransport beans and calls their publish method.

    Workflow for Cross-Service Messaging:

    1. Producer: Implement EventTransport to serialize and send the EdaEvent via your chosen MQ client.
    2. Consumer: When your MQ consumer receives a message, deserialize it and call publisher.publishLocal(event). This allows you to reuse the same local EdaEventHandler logic across services.

    Responsibility Boundary: Reliability features like acknowledgments, retries, dead-letter queues, message persistence, and serialization protocols (JSON/Avro/Protobuf) are the responsibility of your EventTransport implementation, not the EDA core.

    @Component
    class ApplicationMqTransport implements EventTransport {
        @Override
        public void publish(EdaEvent<?> event) {
            // Use your application's MQ client to serialize and send the event
        }
    }
  10. Choose a transport mechanism for Governance usage tracking

    main

    You can configure how usage records are transported using the following methods:

    1. EDA (Event-Driven Architecture): The default mode. Best for CAPTCHAs, notifications, and other asynchronous observations that should not impact the main business flow. You must implement the EDA EventTransport interface. This can be used to replace or wrap Spring Cloud Stream, RabbitMQ, or Kafka.
    2. HTTP: Suitable for direct reporting to Sysadmin. Set the following configuration property: opensabre.governance.usage.transport=HTTP

    Note on Rate Limiting: While EDA is used for usage observation, it cannot be used for real-time decision making. For rate limiting enforcement, you must use the synchronous GovernanceRateLimiter.