Demo project for the tutorial Hands-On Redis Pub/Sub with Spring Boot for Fast and Lightweight Messaging.
- Java 21
- Spring Boot 3.5.x
- Spring Data Redis (Lettuce)
- Docker Compose
src/main/java/com/boottechnologies/ci/redispubsub/
├── RedisPubSubApplication.java
├── config/
│ ├── RedisChannels.java # Channel name constants
│ └── RedisConfig.java # Container, listeners, ObjectMapper
├── controller/
│ └── EventController.java # REST endpoints
├── dto/
│ ├── OrderRequest.java
│ ├── PublishResponse.java
│ └── StatusUpdateRequest.java
├── exception/
│ └── GlobalExceptionHandler.java
├── model/
│ └── EventMessage.java # Envelope for all published events
├── publisher/
│ └── EventPublisher.java # Publishes events via StringRedisTemplate
└── subscriber/
├── AuditEventSubscriber.java # Pattern subscriber (orders.events.*)
└── OrderEventSubscriber.java # Channel subscriber (orders.events.created / .status)
docker compose up -d./mvnw spring-boot:runcurl -s -X POST http://localhost:8080/api/orders/created \
-H "Content-Type: application/json" \
-d '{
"orderId": "ORD-001",
"customerId": "CUST-42",
"amount": 149.99,
"notes": "Express shipping requested"
}' | jqcurl -s -X POST http://localhost:8080/api/orders/status \
-H "Content-Type: application/json" \
-d '{
"orderId": "ORD-001",
"status": "SHIPPED",
"reason": "Express courier dispatched"
}' | jqdocker exec -it redis-pubsub redis-cli
# List active channels
PUBSUB CHANNELS
# Subscriber count per channel
PUBSUB NUMSUB orders.events.created orders.events.status
# Count active pattern subscriptions
PUBSUB NUMPAT
# Subscribe and watch messages manually
SUBSCRIBE orders.events.createdTests use Testcontainers — Docker must be running.
./mvnw test