mica 云母,寓意为云服务的核心,增强 Spring cloud 功能,使得 Spring cloud 服务开发更加方便快捷。
mica 基于 java 8,没有历史包袱,支持传统 Servlet 和 Reactive(webflux)。采用 mica-auto 自动生成 spring.factories 和 spring-devtools.properties 配置,仅依赖 Spring boot、Spring cloud 全家桶,无第三方依赖。市面上鲜有的微服务核心组件。
| 依赖 | 版本 |
| Spring | 5.x |
| Spring Boot | 2.1.x |
| Spring Cloud | Greenwich 版 |
mica-plus-redis
添加 MicaRedisCache
Bean,使用同 redis
命令. redis
序列化方式可配置化. ReactiveRequestContextFilter
排序,方便在 spring cloud gateway 中使用. DigestUtil
对 Md5
、 Sha
、 Hmac
等系列签名算法添加非 hex 方法. mica-http
. mica-social
. mica-plus-social
. mica-plus-ribbon
. Spring boot
版本到 2.1.6.RELEASE
. Spring cloud
版本到 Greenwich.SR1
. swagger-bootstrap-ui
到 1.9.4
. mica-http 是 okhttp 的封装,Fluent 语法的 http 工具包,语法参考 HttpClient Fluent API。
private String getUserEmail(String accessToken) {
return HttpRequest.get("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))")
.addHeader("Host", "api.linkedin.com")
.addHeader("Connection", "Keep-Alive")
.addHeader("Authorization", "Bearer " + accessToken)
.log()
.execute()
.asJsonNode()
.at("/elements/0/handle~0/emailAddress")
.asText();
}
public static void logBasic() {
HttpRequest.post("https://www.baidu.com/do-stuff")
.log(HttpLoggingInterceptor.Level.BASIC)
.formBuilder()
.add("a", "b")
.execute()
.asBytes();
}
可以使用 .log()
方法输出请求详情。
19:50:27.223 [main] INFO net.dreamlu.http.Slf4jLogger - --> GET https://graph.qq.com/oauth2.0/token?code=code&client_id=clientId&client_secret=clientSecret&grant_type=authorization_code&redirect_uri=redirectUri http/1.1
19:50:27.228 [main] INFO net.dreamlu.http.Slf4jLogger - User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
19:50:27.228 [main] INFO net.dreamlu.http.Slf4jLogger - --> END GET
19:50:27.663 [main] INFO net.dreamlu.http.Slf4jLogger - <-- 200 OK https://graph.qq.com/oauth2.0/token?code=code&client_id=clientId&client_secret=clientSecret&grant_type=authorization_code&redirect_uri=redirectUri (434ms)
19:50:27.664 [main] INFO net.dreamlu.http.Slf4jLogger - Server: nginx
19:50:27.666 [main] INFO net.dreamlu.http.Slf4jLogger - Date: Sun, 23 Jun 2019 11:50:27 GMT
19:50:27.666 [main] INFO net.dreamlu.http.Slf4jLogger - Content-Type: text/html
19:50:27.667 [main] INFO net.dreamlu.http.Slf4jLogger - Content-Length: 86
19:50:27.667 [main] INFO net.dreamlu.http.Slf4jLogger - Connection: keep-alive
19:50:27.667 [main] INFO net.dreamlu.http.Slf4jLogger - Keep-Alive: timeout=50
19:50:27.668 [main] INFO net.dreamlu.http.Slf4jLogger - Cache-Control: no-cache
19:50:27.670 [main] INFO net.dreamlu.http.Slf4jLogger -
19:50:27.671 [main] INFO net.dreamlu.http.Slf4jLogger - callback( {"error":100001,"error_description":"param client_id is wrong or lost "} );
19:50:27.671 [main] INFO net.dreamlu.http.Slf4jLogger - <-- END HTTP (86-byte body)
目前支持 gitee、开源中国、qq、微信、微博、钉钉、百度、google、Facebook、Linkedin 等十多个服务。
mica:
social:
qq:
client-id: xxxxxx
client-secret: xxxxx
redirect-uri: http://www.dreamlu.net/api/qq/callback
@Autowired
private AuthQqRequest authRequest;
@GetMapping("auth/qq")
public String auth() {
return "redirect:" + authRequest.authorize();
}
@GetMapping("callback/qq")
public String callback(String code) {
AuthResponse authResponse = authRequest.login(code);
// 业务代码
}
172.21.0.*
、 172.21.0.8*
。
前缀: mica.ribbon.rule
| 配置项 | 默认值 | 说明 |
| enabled | true | 是否启用 |
| prior-ip-pattern | 空 | 优先的 ip 列表,支持通配符,例如:172.21.0.81、172.21.0.8 、172.21.0. |
| tag | 无 | 服务的 tag,用于灰度,匹配:nacos.discovery.metadata.tag |
例如: dev
mica:
ribbon:
rule:
prior-ip-pattern:
- 172.21.0.*