Spring Cloud 微服务组件 mica v1.1.3 发布,新增 http和第三方登录组件

栏目: 软件资讯 · 发布时间: 6年前

内容简介:mica(云母) mica 云母,寓意为云服务的核心,增强 Spring cloud 功能,使得 Spring cloud 服务开发更加方便快捷。 mica 核心依赖 mica 基于 java 8,没有历史包袱,支持传统 Servlet 和 Reactive(webflux)。采...

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 添加 MicaRedisCache Bean,使用同 redis 命令.
  • ✨ redis 序列化方式可配置化.
  • ✨ 提高 webflux 的日志和 ReactiveRequestContextFilter 排序,方便在 spring cloud gateway 中使用.
  • ✨ 调整验证码 base64,加上 base64 图片前缀.
  • ✨ DigestUtil 对 Md5ShaHmac 等系列签名算法添加非 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.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 规则方便开发

功能

  1. 【优先级最高】ip 相同的服务(方便本地多服务联调)。
  2. 可设置选择的 ip 或者 ip 段,例如:172.21.0.*172.21.0.8*
  3. 可设定 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.*

文档


以上所述就是小编给大家介绍的《Spring Cloud 微服务组件 mica v1.1.3 发布,新增 http和第三方登录组件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

High Performance Python

High Performance Python

Micha Gorelick、Ian Ozsvald / O'Reilly Media / 2014-9-10 / USD 39.99

If you're an experienced Python programmer, High Performance Python will guide you through the various routes of code optimization. You'll learn how to use smarter algorithms and leverage peripheral t......一起来看看 《High Performance Python》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具