Skip to content

Commit e3bf779

Browse files
Andrés Contreras GuillénAndrés Contreras Guillén
authored andcommitted
docs: comprehensive, polished README
1 parent f2ebaa9 commit e3bf779

1 file changed

Lines changed: 189 additions & 58 deletions

File tree

README.md

Lines changed: 189 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Java](https://img.shields.io/badge/Java-21%2B-orange.svg)](https://openjdk.org)
66
[![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.x-green.svg)](https://spring.io/projects/spring-boot)
77

8-
> Unified reactive client library for REST, SOAP, gRPC, GraphQL, and WebSocket services with circuit breakers and observability.
8+
> Unified, reactive service-client library for Spring Boot — one fluent, resilient API over REST, SOAP, gRPC, GraphQL, and WebSocket with built-in circuit breakers, retries, discovery, and observability.
99
1010
---
1111

@@ -23,65 +23,76 @@
2323

2424
## Overview
2525

26-
Firefly Framework Client provides a unified, reactive communication library that supports multiple protocols through a consistent API. It includes pre-built clients for REST, SOAP, gRPC, GraphQL, and WebSocket services, each with integrated circuit breaker patterns, health monitoring, and comprehensive metrics collection.
26+
`fireflyframework-client` is the Firefly Framework's common client library: a single, consistent, fully reactive abstraction for calling other services regardless of the wire protocol. Instead of juggling `WebClient`, JAX-WS/CXF, raw gRPC stubs, and bespoke GraphQL/WebSocket plumbing, application code uses one fluent entry point — `ServiceClient` — and gets resilience, security, discovery, and observability wired in by default.
2727

28-
The library features builder-based client construction (`RestClientBuilder`, `SoapClientBuilder`, `GrpcClientBuilder`), service discovery integration (Eureka, Consul, Kubernetes, static), and advanced capabilities including HTTP response caching, request deduplication, OAuth2 authentication, API key management, and certificate pinning.
28+
The library is built on Spring WebFlux (`WebClient`) and Project Reactor, so every operation returns `Mono`/`Flux` and is non-blocking from end to end. Clients are constructed through type-safe builders (`RestClientBuilder`, `SoapClientBuilder`, `GrpcClientBuilder`) reachable from the `ServiceClient.rest(...)`, `ServiceClient.soap(...)`, and `ServiceClient.grpc(...)` static factories, and each client carries an integrated circuit breaker (Firefly's own `CircuitBreakerManager`, backed by Resilience4j), retry-with-backoff, health checks, and per-client Micrometer metrics.
2929

30-
Additional features include a chaos engineering interceptor for fault injection during testing, client-side rate limiting, interceptor chain support for request/response transformation, and pluggable error handling with protocol-specific error mappers.
30+
Where it sits in the framework: this module depends only on `fireflyframework-kernel` (shared exception hierarchy and abstractions) and `fireflyframework-observability` (metrics, tracing, health, structured logging). It is the outbound-communication backbone used by Firefly microservices to consume core/domain services, third-party REST/SOAP APIs, and generated SDKs. It auto-configures itself via Spring Boot — drop it on the classpath and `ServiceClientAutoConfiguration` provides a tuned `WebClient.Builder`, a default `CircuitBreakerManager`, a default `RestClientBuilder`, a gRPC builder factory, and `ServiceClientMetrics` (when a `MeterRegistry` is present).
31+
32+
Beyond the core REST/SOAP/gRPC clients, the module bundles a set of companion helpers and cross-cutting concerns: a `GraphQLClientHelper` (query/mutation/batch/subscribe with response caching), a `WebSocketClientHelper` (reconnection, heartbeat, message queue), a `WebhookClientHelper` (HMAC signature generation/verification, dispatch), HTTP response caching, request deduplication, service discovery (Eureka, Consul, Kubernetes, static), client-side rate limiting, certificate pinning, API-key and OAuth2 helpers, an interceptor chain, a chaos-engineering interceptor for fault injection, and a plugin SPI for extending client behavior.
3133

3234
## Features
3335

34-
- REST, SOAP, gRPC, GraphQL, and WebSocket client implementations
35-
- Builder pattern for type-safe client construction
36-
- Circuit breaker with configurable sliding window and failure thresholds
37-
- Service discovery: Eureka, Consul, Kubernetes, static endpoints
38-
- Load balancer strategy support
39-
- OAuth2 client helper with token management
40-
- API key management and certificate pinning
41-
- HTTP response caching with configurable cache policies
42-
- Request deduplication manager
43-
- Interceptor chain for logging, metrics, and custom transformations
44-
- Chaos engineering interceptor for fault injection testing
45-
- Client-side rate limiting
46-
- Health indicators and metrics per client instance
47-
- Error handling with HTTP, gRPC, and SOAP fault mappers
48-
- Multipart upload helper
49-
- Dynamic JSON response handling
50-
- Spring Boot auto-configuration with validation
36+
- Unified `ServiceClient` SPI with protocol-specific subtypes: `RestClient`, `SoapClient`, `GrpcClient`
37+
- Fluent, type-safe builders: `RestClientBuilder`, `SoapClientBuilder`, `GrpcClientBuilder` (via `ServiceClient.rest/soap/grpc`)
38+
- Reactive, non-blocking operations end to end (`Mono`/`Flux`) on Spring WebFlux + Reactor Netty
39+
- REST: HTTP verb methods (`get`/`post`/`put`/`patch`/`delete`), fluent `RequestBuilder` (path/query params, headers, body, timeout), and streaming (`stream(...)`)
40+
- SOAP: modern reactive API over JAX-WS/Apache CXF with WS-Security, MTOM, schema validation, WSDL caching, and TLS trust/key stores
41+
- gRPC: builder over `grpc-netty-shaded` with plaintext/TLS, keep-alive, deadlines, and stub factories
42+
- `GraphQLClientHelper`: queries, mutations, variables, data-path extraction, batch execution, subscriptions, and response caching
43+
- `WebSocketClientHelper`: configurable handshake timeout, automatic reconnection with backoff, heartbeat, message queue, and compression
44+
- `WebhookClientHelper`: HMAC signature generation/verification, event subscription/dispatch, and retry
45+
- Resilience: integrated `CircuitBreakerManager` (sliding window, failure-rate, slow-call, half-open transitions) and retry with exponential backoff + jitter
46+
- Service discovery: `EurekaServiceDiscoveryClient`, `ConsulServiceDiscoveryClient`, `KubernetesServiceDiscoveryClient`, `StaticServiceDiscoveryClient` behind a `ServiceDiscoveryClient` SPI, plus `LoadBalancerStrategy`
47+
- Security: `OAuth2ClientHelper`, `ApiKeyManager`, `CertificatePinningManager`, `ClientSideRateLimiter`, `JwtValidator`, `SecretsEncryptionManager`
48+
- Performance: `HttpCacheManager`/`HttpCacheInterceptor` HTTP response caching and `RequestDeduplicationManager`
49+
- Extensibility: `ServiceClientInterceptor` chain (logging, metrics, custom), `ServiceClientPlugin` SPI + `PluginManager`, and `DynamicJsonResponse` for schemaless responses
50+
- Testing aids: `ChaosEngineeringInterceptor` for fault injection, plus a rich, mapped exception hierarchy (`ServiceTimeoutException`, `ServiceNotFoundException`, `CircuitBreakerOpenException`, `SoapFaultException`, ...) with HTTP/gRPC/SOAP error mappers
51+
- Observability: per-client health indicators (`ServiceClientHealthIndicator`/`Manager`), Micrometer metrics (`ServiceClientMetrics`), and `MultipartUploadHelper`
52+
- Spring Boot auto-configuration with validated `@ConfigurationProperties` and environment-aware defaults (development / testing / production)
5153

5254
## Requirements
5355

54-
- Java 21+
56+
- Java 21+ (Java 25 recommended)
5557
- Spring Boot 3.x
5658
- Maven 3.9+
59+
- A reactive (WebFlux) application context. Optional runtime dependencies only when their feature is used: a service registry (Eureka/Consul) or Kubernetes for dynamic discovery, and a reachable WSDL endpoint for SOAP clients.
5760

5861
## Installation
5962

6063
```xml
6164
<dependency>
6265
<groupId>org.fireflyframework</groupId>
6366
<artifactId>fireflyframework-client</artifactId>
64-
<version>26.02.07</version>
67+
<!-- Version is managed by the Firefly BOM / parent; omit when inheriting it -->
6568
</dependency>
6669
```
6770

71+
If your project inherits `fireflyframework-parent` (or imports `fireflyframework-bom`), the version is managed for you and can be omitted. Otherwise pin the current release explicitly.
72+
6873
## Quick Start
6974

75+
Auto-configuration provides a default `RestClientBuilder`, `CircuitBreakerManager`, and tuned `WebClient.Builder` as soon as the dependency is on the classpath. You can use the `ServiceClient` static factories directly, or define your own client beans.
76+
77+
### REST
78+
7079
```java
7180
import org.fireflyframework.client.RestClient;
72-
import org.fireflyframework.client.builder.RestClientBuilder;
81+
import org.fireflyframework.client.ServiceClient;
82+
import reactor.core.publisher.Mono;
83+
84+
import java.time.Duration;
7385

7486
@Configuration
7587
public class ClientConfig {
7688

7789
@Bean
78-
public RestClient paymentClient() {
79-
return RestClientBuilder.create("payment-service")
90+
public RestClient paymentClient(CircuitBreakerManager circuitBreakerManager) {
91+
return ServiceClient.rest("payment-service")
8092
.baseUrl("https://api.payments.com")
81-
.connectTimeout(Duration.ofSeconds(5))
82-
.circuitBreaker(cb -> cb
83-
.failureRateThreshold(50)
84-
.waitDurationInOpenState(Duration.ofSeconds(30)))
93+
.timeout(Duration.ofSeconds(5))
94+
.defaultHeader("Accept", "application/json")
95+
.circuitBreakerManager(circuitBreakerManager)
8596
.build();
8697
}
8798
}
@@ -91,47 +102,167 @@ public class PaymentService {
91102

92103
private final RestClient paymentClient;
93104

105+
public PaymentService(RestClient paymentClient) {
106+
this.paymentClient = paymentClient;
107+
}
108+
109+
// Fluent RequestBuilder: set body/params/headers, then execute()
94110
public Mono<PaymentResponse> charge(PaymentRequest request) {
95-
return paymentClient.post("/charges", request, PaymentResponse.class);
111+
return paymentClient.post("/charges", PaymentResponse.class)
112+
.withBody(request)
113+
.execute();
114+
}
115+
116+
public Mono<Payment> get(String id) {
117+
return paymentClient.get("/charges/{id}", Payment.class)
118+
.withPathParam("id", id)
119+
.execute();
96120
}
97121
}
98122
```
99123

124+
### SOAP
125+
126+
```java
127+
SoapClient weather = ServiceClient.soap("weather-service")
128+
.wsdlUrl("https://example.com/weather?wsdl")
129+
.credentials("user", "secret") // WS-Security UsernameToken
130+
.timeout(Duration.ofSeconds(30))
131+
.build();
132+
133+
Mono<WeatherResponse> forecast = weather.invokeAsync(
134+
"GetWeatherByCity", new GetWeatherRequest("Madrid"), WeatherResponse.class);
135+
```
136+
137+
### gRPC
138+
139+
```java
140+
GrpcClient<UserServiceGrpc.UserServiceStub> users =
141+
ServiceClient.grpc("user-service", UserServiceGrpc.UserServiceStub.class)
142+
.address("localhost:9090")
143+
.usePlaintext()
144+
.stubFactory(UserServiceGrpc::newStub)
145+
.build();
146+
```
147+
100148
## Configuration
101149

150+
All settings live under the `firefly.service-client.*` prefix and are bound (and validated) by `ServiceClientProperties`. Properties are **global defaults** organized by protocol/concern; per-client overrides are expressed through the builders shown above. Environment-aware defaults are applied automatically based on `firefly.service-client.environment` (`development`, `testing`, `production`).
151+
102152
```yaml
103153
firefly:
104-
client:
105-
services:
106-
payment-service:
107-
base-url: https://api.payments.com
108-
connect-timeout: 5s
109-
read-timeout: 10s
110-
circuit-breaker:
111-
enabled: true
112-
failure-rate-threshold: 50
113-
retry:
114-
max-attempts: 3
115-
backoff: 1s
154+
service-client:
155+
enabled: true # master switch for the framework
156+
default-timeout: 30s # global default for all client operations
157+
environment: development # development | testing | production (drives smart defaults)
158+
default-headers: {} # headers applied to all REST clients
159+
160+
rest:
161+
max-connections: 100 # connection pool size
162+
max-idle-time: 5m
163+
max-life-time: 30m
164+
pending-acquire-timeout: 10s
165+
response-timeout: 30s
166+
max-in-memory-size: 1048576 # 1 MB response buffer
167+
connect-timeout: 10s
168+
read-timeout: 30s
169+
follow-redirects: true
170+
compression-enabled: true
171+
default-content-type: application/json
172+
default-accept-type: application/json
173+
logging-enabled: false
174+
max-retries: 3
175+
176+
grpc:
177+
keep-alive-time: 5m
178+
keep-alive-timeout: 30s
179+
keep-alive-without-calls: true
180+
max-inbound-message-size: 4194304 # 4 MB
181+
max-inbound-metadata-size: 8192 # 8 KB
182+
call-timeout: 30s
183+
retry-enabled: true
184+
use-plaintext-by-default: true
185+
compression-enabled: true
186+
max-concurrent-streams: 100
187+
188+
soap:
189+
default-timeout: 30s
190+
connection-timeout: 10s
191+
receive-timeout: 30s
192+
mtom-enabled: false
193+
schema-validation-enabled: true
194+
message-logging-enabled: false
195+
max-message-size: 10485760 # 10 MB
196+
ws-addressing-enabled: false
197+
ws-security-enabled: false
198+
soap-version: "1.1" # 1.1 or 1.2
199+
wsdl-cache-enabled: true
200+
wsdl-cache-expiration: 1h
201+
follow-redirects: true
202+
203+
sdk:
204+
default-timeout: 45s
205+
auto-shutdown-enabled: true
206+
max-concurrent-operations: 50
207+
logging-enabled: false
208+
209+
circuit-breaker:
210+
enabled: true
211+
failure-rate-threshold: 50.0 # percent
212+
wait-duration-in-open-state: 60s
213+
sliding-window-size: 10
214+
minimum-number-of-calls: 5
215+
slow-call-rate-threshold: 100.0 # percent
216+
slow-call-duration-threshold: 60s
217+
permitted-number-of-calls-in-half-open-state: 3
218+
call-timeout: 30s
219+
automatic-transition-from-open-to-half-open-enabled: true
220+
221+
retry:
222+
enabled: true
223+
max-attempts: 3
224+
wait-duration: 500ms
225+
exponential-backoff-multiplier: 2.0
226+
max-wait-duration: 10s
227+
jitter-enabled: true
228+
229+
metrics:
230+
enabled: true
231+
detailed-metrics: false
232+
export-interval: 1m
233+
histogram-enabled: true
234+
tags: {}
235+
236+
security:
237+
enabled: true
238+
default-auth-type: NONE # NONE | BASIC | BEARER | OAUTH2 | CUSTOM
239+
ssl-validation-enabled: true
240+
request-signing-enabled: false
116241
```
117242
243+
### Key properties
244+
245+
| Property | Default | Purpose |
246+
| --- | --- | --- |
247+
| `firefly.service-client.enabled` | `true` | Master switch; when `false`, no client beans are auto-configured. |
248+
| `firefly.service-client.environment` | `development` | Selects environment-aware defaults (e.g. relaxed SSL and verbose logging in `development`, hardened defaults in `production`). |
249+
| `firefly.service-client.default-timeout` | `30s` | Fallback timeout for all client operations. |
250+
| `firefly.service-client.rest.max-connections` | `100` | Reactor Netty connection-pool size for REST. |
251+
| `firefly.service-client.circuit-breaker.failure-rate-threshold` | `50.0` | Percentage of failures within the sliding window that opens the breaker. |
252+
| `firefly.service-client.retry.max-attempts` | `3` | Maximum retry attempts (with exponential backoff + optional jitter). |
253+
| `firefly.service-client.grpc.use-plaintext-by-default` | `true` | Whether new gRPC channels default to plaintext (forced to TLS in `production`). |
254+
| `firefly.service-client.metrics.enabled` | `true` | Enables `ServiceClientMetrics` Micrometer integration (auto-disabled in `testing`). |
255+
256+
> Note: environment-aware defaults only override values you have **not** set explicitly, so any property you configure always wins.
257+
118258
## Documentation
119259

120-
Additional documentation is available in the [docs/](docs/) directory:
121-
122-
- [Quick Start](docs/QUICK_START.md)
123-
- [Configuration](docs/CONFIGURATION.md)
124-
- [Rest Client](docs/REST_CLIENT.md)
125-
- [Soap Client](docs/SOAP_CLIENT.md)
126-
- [Grpc Client](docs/GRPC_CLIENT.md)
127-
- [Graphql Client](docs/GRAPHQL_CLIENT.md)
128-
- [Websocket Helper](docs/WEBSOCKET_HELPER.md)
129-
- [Multipart Helper](docs/MULTIPART_HELPER.md)
130-
- [Oauth2 Helper](docs/OAUTH2_HELPER.md)
131-
- [Security](docs/SECURITY.md)
132-
- [Observability](docs/OBSERVABILITY.md)
133-
- [Advanced Features](docs/ADVANCED_FEATURES.md)
134-
- [Integration Testing](docs/INTEGRATION_TESTING.md)
260+
- Firefly Framework module catalog and architecture docs: [github.com/fireflyframework/.github](https://github.com/fireflyframework/.github/blob/main/profile/MODULE_CATALOG.md)
261+
- In-repo guides under [`docs/`](docs/):
262+
- [Quick Start](docs/QUICK_START.md) · [Configuration](docs/CONFIGURATION.md)
263+
- [REST Client](docs/REST_CLIENT.md) · [SOAP Client](docs/SOAP_CLIENT.md) · [gRPC Client](docs/GRPC_CLIENT.md) · [GraphQL Client](docs/GRAPHQL_CLIENT.md) · [WebSocket Helper](docs/WEBSOCKET_HELPER.md)
264+
- [Multipart Helper](docs/MULTIPART_HELPER.md) · [OAuth2 Helper](docs/OAUTH2_HELPER.md) · [Security](docs/SECURITY.md) · [Observability](docs/OBSERVABILITY.md)
265+
- [Advanced Features](docs/ADVANCED_FEATURES.md) · [Integration Testing](docs/INTEGRATION_TESTING.md)
135266

136267
## Contributing
137268

0 commit comments

Comments
 (0)