spring-boot-student Documentation

repository·master·Indexed 21 days ago

https://github.com/wyh-spring-ecosystem-student/spring-boot-student

A pedagogical repository of modular Spring Boot implementations and configuration examples. It covers enterprise technologies including databases (JPA, MyBatis, MongoDB, Redis), caching strategies (Caffeine, Redis, Ehcache), messaging (RabbitMQ), security, and distributed systems patterns. The collection includes specific modules for external configuration, logging, distributed locks, retry mechanisms via Guava or Spring Retry, and the deployment and configuration of the Sentinel Dashboard.

Tokens
3.3K
Snippets
10
Records
24
Agent score
75%

What's inside spring-boot-student

  1. Overview of spring-boot-student

    master
    The spring-boot-student repository is a comprehensive collection of educational modules and implementation examples for various Spring Boot ecosystem components. It covers topics ranging from basic configuration and logging to advanced integration with databases (JPA, MyBatis, MongoDB, Redis), caching strategies (Caffeine, Redis, Ehcache), and distributed systems patterns (Distributed Locks, RabbitMQ, Retry mechanisms).
  2. Implement Multi-level Caching with Redis and Caffeine

    master

    The spring-boot-student-cache-redis-caffeine module demonstrates a high-performance multi-level caching strategy:

    • L1 Cache (Local): Uses Caffeine for extremely fast, in-memory local caching.
    • L2 Cache (Distributed): Uses Redis as a centralized cache shared across multiple application instances.
    • Consistency: Ensures data consistency between L1 and L2 using a combination of 'Push' (via Redis Pub/Sub) and 'Pull' (via message queues and offset tracking) mechanisms.

    This pattern is ideal for reducing network latency while maintaining distributed data integrity.

  3. Configure Spring Boot External Configuration

    master

    The spring-boot-student-config module demonstrates how to manage application settings using standard Spring Boot patterns:

    • @ConfigurationProperties: Used for type-safe binding of external properties to Java objects.
    • @PropertySource: Used to introduce custom .properties or .yml files into the Spring environment.
    • @Value: Used to inject specific property values directly into fields.
    • @ImportResource: Used to import legacy XML-based configurations into a Spring Boot application.
  4. Compile and start the Sentinel Dashboard

    master

    The Sentinel Dashboard provides a centralized interface for managing flow control and circuit breaking rules. It supports machine self-discovery, cluster point link self-discovery, monitoring, and rule configuration.

    Compilation

    Use Maven to package the code into a fat jar:

    mvn clean package

    Startup

    Start the compiled dashboard using the following command. Note that this specific build includes CommonFilter to allow the dashboard itself to be protected by Sentinel flow control.

    java -Dserver.port=8080 \
    -Dcsp.sentinel.dashboard.server=localhost:8080 \
    -Dproject.name=sentinel-dashboard \
    -jar target/sentinel-dashboard.jar

    Once started, access the dashboard via a browser at localhost:8080.

  5. Implement Retry Mechanisms with Guava or Spring Retry

    master

    The repository provides two distinct approaches to handling transient failures through retry logic:

    • Guava Retrying: Using the guava-retrying library for flexible retry policies.
    • Spring Retry: Using the native spring-retry framework, which includes support for advanced patterns like circuit breaking (retry and circuit breaker integration).
  6. Integrate Sentinel clients with the Dashboard

    master

    To connect a client application to the Sentinel Dashboard, follow these steps:

    1. Choose an integration method: Select the appropriate way to integrate Sentinel into your application (refer to the official Sentinel Wiki for detailed steps).
    2. Configure the Dashboard address: When starting your client application, add the following JVM parameter to specify the dashboard's IP and port: -Dcsp.sentinel.dashboard.server=consoleIp:port
    3. Trigger Initialization: Sentinel initializes the client and begins sending heartbeat packets to the dashboard only upon the first actual call/request to the client application.

    Verifying Integration

    To confirm the client is successfully connected:

    1. Perform an initial call to your client application.
    2. Check the Sentinel Dashboard's left navigation bar. If the client's machine information is visible, the integration was successful.