mica(云母)
mica 云母,寓意为云服务的核心,增强 Spring cloud 功能,使得 Spring cloud 服务开发更加方便快捷。
mica 核心依赖
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添加MicaRedisCacheBean,使用同redis命令. - ✨
redis序列化方式可配置化. - ✨ 提高 webflux 的日志和
ReactiveRequestContextFilter排序,方便在 spring cloud gateway 中使用. - ✨ 调整验证码 base64,加上 base64 图片前缀.
- ✨
DigestUtil对Md5、Sha、Hmac等系列签名算法添加非 hex 方法. - 🐛 bean copy Convert 注解支持问题.
- ➕ 添加新组件
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 更加简单易用的 http 工具包
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.119: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.3619:50:27.228 [main] INFO net.dreamlu.http.Slf4jLogger - --> END GET19: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: nginx19:50:27.666 [main] INFO net.dreamlu.http.Slf4jLogger - Date: Sun, 23 Jun 2019 11:50:27 GMT19:50:27.666 [main] INFO net.dreamlu.http.Slf4jLogger - Content-Type: text/html19:50:27.667 [main] INFO net.dreamlu.http.Slf4jLogger - Content-Length: 8619:50:27.667 [main] INFO net.dreamlu.http.Slf4jLogger - Connection: keep-alive19:50:27.667 [main] INFO net.dreamlu.http.Slf4jLogger - Keep-Alive: timeout=5019:50:27.668 [main] INFO net.dreamlu.http.Slf4jLogger - Cache-Control: no-cache19: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)
mica-plus-social 第三方登录组件 SDK
目前支持 gitee、开源中国、qq、微信、微博、钉钉、百度、google、Facebook、Linkedin 等十多个服务。
配置
mica:social:qq:client-id: xxxxxxclient-secret: xxxxxredirect-uri: http://www.dreamlu.net/api/qq/callback
构造授权地址
@Autowiredprivate 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);// 业务代码}
mica-plus-ribbon 自定义 ribbon 规则方便开发
功能
- 【优先级最高】ip 相同的服务(方便本地多服务联调)。
- 可设置选择的 ip 或者 ip 段,例如:
172.21.0.*、172.21.0.8*。 - 可设定 tag,为了以后版本发布(灰度)做基础,可能还需要扩展。
配置项
前缀: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.*
文档
- 文档地址(官网):https://www.dreamlu.net/#/doc/docs
- 文档地址(语雀-可关注订阅):https://www.yuque.com/dreamlu/mica
- 示例项目:https://github.com/lets-mica/mica-example
开源推荐
- Spring boot 微服务高效开发
mica工具集:https://gitee.com/596392912/mica pig宇宙最强微服务(架构师必备):https://gitee.com/log4j/pigSpringBlade完整的线上解决方案(企业开发必备):https://gitee.com/smallc/SpringBlade- 加入【如梦技术】Spring QQ群:479710041,了解更多。
关注我们

扫描上面二维码,更多精彩内容每天推荐!
