How dm-drogeriemarkt/retrylib-spring-boot-starter works
Main Components
• Spring Boot Auto-Configuration: Represented by the RetrylibAutoConfiguration class (and related configuration classes). This component integrates the library into a Spring Boot application automatically.
• Core Retry Logic:
• RetryService: Manages and orchestrates the retry process.
• RetryProcessor: Periodically processes the in-memory queue based on a configurable interval (default 1 minute).
• Retry Handling:
• RetryAspect: Implements Spring AOP to wrap calls and trigger the retry process when external calls fail.
• RetryHandler: An interface that developers implement (often as a Spring Bean) to define how to actually perform the external call.
• Data Model and Serialization:
• RetryEntity: The object that holds the payload and metadata for each retry operation.
• RetryEntitySerializer: Handles the conversion of RetryEntity into JSON for persistence (for example, when logging pending invocations during shutdown).
• Shutdown Handling:
• ApplicationShutdownHandler: Ensures that any pending retry operations are logged on JVM termination.
• External Integration Point:
• The user-implemented ExternalServiceRetryHandler (or similar implementations visible in the tests) that uses RetryHandler‘s contract to define how external service calls are retried.
Component Relationships and Interactions
• The Spring Boot Auto-Configuration component automatically wires up beans such as the RetryService, RetryProcessor, and the RetryAspect.
• The RetryAspect intercepts calls (using AOP) that fail, and then passes the necessary data to the RetryService.
• The RetryService adds a new RetryEntity (created with the help of the RetryEntitySerializer) to an in-memory queue, limited by the configuration property retrylib.queueLimit.
• The RetryProcessor runs periodically (with the interval defined by retrylib.retryIntervalInMillis) and picks up entries from the queue to invoke the user-implemented RetryHandler.
• When the JVM is shutting down, the ApplicationShutdownHandler logs any remaining RetryEntity instances.
• External services are not part of the library per se but are the targets of the application’s calls handled through the RetryHandler implementations provided by the end user.
Architectural Patterns and Design Principles
• Inversion of Control / Dependency Injection: Enabled by Spring Boot auto-configuration and use of Spring’s component scanning.
• Aspect-Oriented Programming (AOP): Employed by RetryAspect to encapsulate retry behavior separately from business logic.
• Separation of Concerns: Dividing responsibilities between intercepting failed calls, queuing, processing retries, and handling shutdown events.
• Resilience Pattern: Implementing a retry mechanism along with a finite in-memory queue to prevent overloading the system.
Technologies and Frameworks
• Spring Boot (for auto-configuration and dependency injection).
• Spring AOP (for method interception with RetryAspect).
• Jackson (for JSON serialization of retry entities).
• Maven (for build management, as indicated by the pom.xml and GitHub workflows).
• Use clear labels for each component (e.g., “RetryAspect”, “RetryService”, etc.).
• From “Application” (Spring Boot Context) to “RetrylibAutoConfiguration” (wiring the components)
• From “RetryAspect” to “RetryService” indicating that intercepted failures are handed off.
• Annotations for configuration properties and default values where it makes sense.
This level of detail will aid any principal software engineer in understanding and potentially extending or integrating the retry mechanism into their system. Happy diagramming!