内容简介:mica 云母,寓意为云服务的核心,增强 Spring cloud 功能,使得 Spring cloud 服务开发更加方便快捷。mica 基于 java 8,没有历史包袱,支持传统 Servlet 和 Reactive(webflux)。采用 mica-auto 自动生成 spring.factories 和 spring-devtools.properties 配置,仅依赖 Spring boot、Spring cloud 全家桶,无第三方依赖。市面上鲜有的微服务核心组件。mica-http 是 okht
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 版 |
更新说明
-
:sparkles: 完善
mica-plus-redis
添加MicaRedisCache
Bean,使用同redis
命令. -
:sparkles:
redis
序列化方式可配置化. -
:sparkles: 提高 webflux 的日志和
ReactiveRequestContextFilter
排序,方便在 spring cloud gateway 中使用. - :sparkles: 调整验证码 base64,加上 base64 图片前缀.
-
:sparkles:
DigestUtil
对Md5
、Sha
、Hmac
等系列签名算法添加非 hex 方法. - :bug: bean copy Convert 注解支持问题.
-
:heavy_plus_sign: 添加新组件
mica-http
. -
:heavy_plus_sign: 添加新组件
mica-social
. -
:heavy_plus_sign: 添加新组件
mica-plus-social
. -
:heavy_plus_sign: 添加新组件
mica-plus-ribbon
. -
:arrow_up: 升级
Spring boot
版本到2.1.6.RELEASE
. -
:arrow_up: 升级
Spring cloud
版本到Greenwich.SR1
. -
:arrow_up: 升级
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.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)
mica-plus-social 第三方登录组件 SDK
目前支持 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); // 业务代码 }
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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 第三方组件上线的最佳实践
- JustAuth 关注破 10k,第三方登录开源组件
- Spring Cloud 微服务组件 mica v1.1.3 发布,新增 http和第三方登录组件
- vue移动端引用第三方组件-lytab(学习笔记)
- Angular中修改第三方组件的样式 - zorro日期选择器右端不对齐的BUG
- ybg-spring-fast 添加码云第三方登录,微信第三方登录
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Python Algorithms
Magnus Lie Hetland / Apress / 2010-11-24 / USD 49.99
Python Algorithms explains the Python approach to algorithm analysis and design. Written by Magnus Lie Hetland, author of Beginning Python, this book is sharply focused on classical algorithms, but it......一起来看看 《Python Algorithms》 这本书的介绍吧!