V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
noble4cc
V2EX  ›  Java

okhttp 在后端项目中用的多吗?

  •  
  •   noble4cc · 2020-06-03 09:02:16 +08:00 · 6172 次点击
    这是一个创建于 1415 天前的主题,其中的信息可能已经有所发展或是发生改变。

    还是只有安卓在用呢?

    26 条回复    2021-04-22 20:11:15 +08:00
    jorneyr
        1
    jorneyr  
       2020-06-03 09:14:22 +08:00
    我用了基于 OKHttp 封装的 EasyOKHttp,挺好用的
    PhpBestRubbish
        2
    PhpBestRubbish  
       2020-06-03 09:21:22 +08:00
    EasyOKHttp+1
    Kyle18Tang
        3
    Kyle18Tang  
       2020-06-03 09:23:48 +08:00
    Spring Cloud 里 Zull 和 OpenFeign 都可以使用 OkHttp.
    sagaxu
        4
    sagaxu  
       2020-06-03 09:31:29 +08:00 via Android
    okhttp 性能不高,不适合高流量业务
    yinzhili
        5
    yinzhili  
       2020-06-03 09:50:24 +08:00
    用啊,zuul 和 openfeign 都选了它
    RedSpark
        6
    RedSpark  
       2020-06-03 10:02:15 +08:00
    okhttp 至少比 httpclient4 高
    wujieyuan
        7
    wujieyuan  
       2020-06-03 10:23:06 +08:00
    我一般用 Hutool 工具封装的 HttpUtils, 够用了
    qwerthhusn
        8
    qwerthhusn  
       2020-06-03 10:25:19 +08:00
    感觉用起来比 Apache 的 HttpClient 简单一些,API 啥的比较清晰
    BBCCBB
        9
    BBCCBB  
       2020-06-03 10:25:34 +08:00
    retrofit 后端也可以用, feign 也可以用 okhttp 做 backend,

    想用 feign 的异步 http 功能就不能用 okhttp 了. 一般用 jdk11 自带的 httpclient 或者 apache client 实现真异步 http 请求.
    chendy
        10
    chendy  
       2020-06-03 10:26:19 +08:00
    RestTemplate 已封装,okhttp 和 httpClient 爱用哪个用哪个
    yty2012g
        11
    yty2012g  
       2020-06-03 10:40:15 +08:00
    目前后端有使用的挺多,okHttp3,httpClient4.5,Unirest 都有使用。现在使用的比较多的是 unirest,可能 api 相对简单吧
    kanepan19
        12
    kanepan19  
       2020-06-03 11:03:49 +08:00
    httpclient4.5.2 我们业务很依赖 http 请求,配置复杂,性能要求高
    感觉新项目,或者并不是很依赖 httpclient 的项目可以是用 okHttp
    cjh1095358798
        13
    cjh1095358798  
       2020-06-03 11:43:16 +08:00
    看到朋友用过
    noble4cc
        14
    noble4cc  
    OP
       2020-06-03 11:47:28 +08:00
    @yty2012g 这个 unirest 的 api 支持设置连接池吗?
    zoharSoul
        15
    zoharSoul  
       2020-06-03 12:05:08 +08:00
    多,
    毕竟没啥好的选择, 横竖比被废弃的 httpclient 强啊.
    hantsy
        16
    hantsy  
       2020-06-03 12:09:54 +08:00
    这种客户工具在 Java 中太多了。

    Java 11 中全新的 HttpClient(基于 Java 9 引入的 Flow API)

    Spring 中有 RestTemplate,WebClient ( WebFlux 版本,一样可以用当成工具类用在 WebMvc 中),用于测试目的的 MockMvc,TestRestTemplate,WebTestClient 等。

    一般 Jakarta EE 项目,有 Jaxrs Client,Microprofile Typesafe Rest Client 。Quarkus 还另外提供了 Vertx 的 WebClient.

    https://github.com/hantsy/quarkus-sample

    Holidon 也提供自己的 WebClient 。

    https://github.com/hantsy/helidon-sample/tree/master/se-webclient
    hantsy
        17
    hantsy  
       2020-06-03 12:11:03 +08:00
    至于 Okhttp, Apache HttpClient, unirest 这种底层的工具类在开发过程中,我很少用到。
    MoHen9
        18
    MoHen9  
       2020-06-03 12:33:55 +08:00 via Android
    okhttp+retrofit+rxjava 用起来真的特别爽,反正我一直这么用,但后台调用远程接口的场景其实并不多,我调用算法接口用的是 okhttp 。
    zzl22100048
        19
    zzl22100048  
       2020-06-03 13:01:46 +08:00 via iPhone
    非微服务,我就用 resteasyclient
    微服务用 feign
    hantsy
        20
    hantsy  
       2020-06-03 13:20:13 +08:00
    @zzl22100048 Resteasy 现在支持现在的 Jaxrs Client (是 Jaxrs 2.0 后规范的一部分),也支持类似 Microprofile RestClient 接口方式调用。

    https://github.com/hantsy/signup-app/blob/master/src/test/java/org/company/test/rest/RESTTest.java

    很多年前写测试经常用,在使用 Resteasy 的项目中,现在我用 Jaxrs Client 更多一些。feign 和 Microprofile RestClient 的灵感可能与 Resteasy 有关(没有查证),Resteasy 这种方式出现很早了,差不多 10 年了。
    AJQA
        22
    AJQA  
       2020-06-03 13:25:59 +08:00 via Android
    @hantsy 你还有没有在 upwork 接活 还是固定客户?
    hantsy
        23
    hantsy  
       2020-06-03 13:33:44 +08:00
    @virtuemartx 好久没接 Upwork 了。这两年被家里事情搞得一踏糊涂,现在重新开始。
    hantsy
        24
    hantsy  
       2020-06-03 13:35:08 +08:00
    https://github.com/hantsy/signup-app

    @virtuemartx 上面这个链接提到的项目是以前一个 Freelance 项目,客户公开代码的。1500USD 。
    emacsistyzy
        25
    emacsistyzy  
       2021-04-22 15:47:17 +08:00
    @sagaxu 高流量业务一般用什么?
    sagaxu
        26
    sagaxu  
       2021-04-22 20:11:15 +08:00 via Android
    @emacsistyzy vertx-web-client 或者其它支持异步的 http 库
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3752 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 909ms · UTC 04:35 · PVG 12:35 · LAX 21:35 · JFK 00:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.