Add openfeign-demo: OpenFeign vs @HttpExchange on Spring Boot 4.2.0 + Spring Cloud 2026.0.0

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b3W3uHbHAmM3orhn7b
This commit is contained in:
Ankur
2026-11-26 00:46:05 +05:30
co-authored by Claude Sonnet 5.5
parent def73fa1c4
commit 7211b0fb80
43 changed files with 927 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
# openfeign-demo
Declarative REST clients on **Spring Boot 4.2.0 + Spring Cloud 2026.0.0 (OpenFeign 5.1.0, Feign 13.17)**, written for
[Spring Cloud OpenFeign on Spring Boot 4: Declarative REST Clients](https://ankurm.com/spring-cloud-creating-rest-client-using-feign/).
Standalone module with its own parent; the rest of this repository stays on Boot 4.1.1 / Cloud 2025.1.3.
A fake "student service" runs in the same JVM (`remote/RemoteStudentController`); every client reaches it over real HTTP on `localhost:18367`.
| Package / file | What it shows |
|---|---|
| `client/StudentClient` | OpenFeign client addressed by service ID (`student-service`) |
| `client/DecodedStudentClient` + `DomainErrorConfig` | custom `ErrorDecoder`, fixed `url` |
| `client/RetryingStudentClient` + `RetryConfig` / `NoRetryStudentClient` | `Retryer` bean on and off |
| `client/ResilientStudentClient` + `StudentClientFallback` | fallbacks through Spring Cloud CircuitBreaker |
| `client/UnnamedPathVariableClient` | the `@PathVariable` without a name trap |
| `client/HttpStudentClient` | the same contract as a Spring `@HttpExchange` interface |
| `application-*.yml` | `newprefix` / `oldprefix` (timeouts), `fallback` (circuit breaker on) |
## Run
Needs JDK 25 (set `java.version` in `pom.xml` to 21 for older JDKs) and Maven 3.9+.
```bash
./scripts/run-all.sh # tests (they write output/01..08) + scripts/no-parameters.sh (writes output/09)
```
## Captured output
Written by the tests themselves; the assertions fail the build if a number stops being true. Timings in the Feign log lines drift between runs.
| File | Shows |
|---|---|
| `01-happy-path.txt` | calls through a service ID, plus Feign's own log lines |
| `02-error-handling.txt` | default `FeignException.NotFound` vs a custom `ErrorDecoder` |
| `03-timeout-newprefix.txt` / `04-timeout-oldprefix.txt` | `spring.cloud.openfeign.client.config.*` vs the 2020-era `feign.client.config.*` |
| `05-retries.txt` | which calls are retried, and the POST that was sent three times |
| `06-fallback.txt` | fallbacks, and the one-second time limit that appears with `circuitbreaker.enabled=true` |
| `07-http-interface.txt` / `08-http-interface-plain-errors.txt` | `@HttpExchange`, with and without Spring Cloud's circuit-breaker wrapper |
| `09-no-parameters.txt` | `PathVariable annotation was empty on param 0` when compiled without `-parameters` |