-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Mushrooms is an easy setup failover and stub framework. To ensure high levels of efficiency for remote service integration.
Remote service integration, especially based on HTTP protocol, e.g. web service, REST etc, highly unstable when developing.
- RestTemplate Request Cache.
- Okhttp Request Cache with @FeignClient.
- Stub REST API via @FeignClient.
- Stub Soap API via @FeignClient.
repositories {
jcenter()
}
dependencies {
compile 'com.github.wenhao:mushrooms:2.1.7'
}
<dependency>
<groupId>com.github.wenhao</groupId>
<artifactId>mushrooms</artifactId>
<version>2.1.7</version>
</dependency>
./gradlew clean build
Enabled mushrooms failover and set included headers, don't inlcude any frequent changeable header.
mushrooms:
failover:
okhttp:
enabled: true
resttemplate:
enabled: true
headers:
- application-specific
- content-type
Enabled mushrooms stub and set stub request and response.
Stub REST API
mushrooms:
stub:
okhttp:
enabled: true
stubs:
- uri: "${READL_HOST:http://localhost:8080}/stub/book"
method: POST
body: /stubs/stub_rest_request.json
response: /stubs/stub_rest_response.json
Stub Soap API
mushrooms:
stub:
okhttp:
enabled: true
stubs:
- uri: "${READL_HOST:http://localhost:8080}/stub/get_book"
method: POST
body: /stubs/stub_soap_request.xml
response: /stubs/stub_soap_response.xml
If enabled okhttp failover or stub, enabling feign okhttp client.
feign:
okhttp:
enabled: true
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
loggerLevel: full
Failover will use redis, if RedisTemplate bean is not configured, add follow configuration:
spring:
redis:
host: localhost
port: 6379
password:
lettuce:
pool:
max-active: 8
max-idle: 8
max-wait: -1ms
min-idle: 1
Logging
logging:
level:
com.github.wenhao: DEBUG
As default, failover only applys if httpstatus not equals to 200.
As default, HttpStatusRestTemplateHealthCheck.java added, customize health checks if need:
@Component
public class CustomRestTemplateHealthCheck implements RestTemplateHealthCheck {
@Override
public boolean health(final ClientHttpResponseWrapper response) {
try {
final JSONObject jsonObject = new JSONObject(response.getBodyAsString());
return jsonObject.getBoolean("success");
} catch (JSONException e) {
return false;
}
}
}
As default, HttpStatusOkHttpClientHealthCheck.java added, customize health checks if need:
@Component
public class CustomOkHttpClientHealthCheck implements OkHttpClientHealthCheck {
@Override
public boolean health(final Response response) {
final String body = getResponseBody(response);
try {
final JSONObject jsonObject = new JSONObject(body);
return jsonObject.getBoolean("success");
} catch (Exception e) {
return false;
}
}
}
- Stub okhttp interceptor prior to failover okhttp interceptor.
- Exclude from failover okhttp configuration if don't need it when stub.
Copyright © 2018 Wen Hao
Licensed under Apache License