Are Retrofit and OkHttp suitable for Java EE/Server-side use?
Asked Answered
B

3

7

I like the APIs of the Retrofit and OkHttp rest/http libraries from Square. I am evaluating options for writing a server-side rest client. For each request to my SOAP-based web service, I have to consume another, restful web service, thus my need for a rest client.

My question is, are Retrofit and OkHttp suitable for server-side use in a highly concurrent web app, or are there likely to be issues, known or otherwise, stemming from these APIs having been designed for use primarily outside of the server-side?

Reading the documentation and perusing the code, nothing jumped out at me to indicate that these libraries would not be suitable. But I don't want to be a guinea pig either. Has anyone experienced any issues with server-side use under high load/concurrency? Had success? Anyone from the dev teams for those libraries care to comment? ;)

Blackbird answered 7/3, 2015 at 16:49 Comment(0)
S
13

We use OkHttp on the Square Cash server and we haven't had problems.

Suiting answered 7/3, 2015 at 17:11 Comment(0)
A
2

Some of the default settings are not suitable for server side usage, for example, the maximum number of concurrent requests per host defaults to 5.

There is some discussion on this at https://github.com/square/okhttp/issues/4354.

Adelina answered 24/6, 2019 at 21:18 Comment(0)
B
1

In the microservices architecture world (using Spring Framework), Retrofit/Okhttp may not be a good fit as a REST client for inter-service communication. Using WebClient/RestTemplate will have at least the below advantages over using retrofit for the same purpose:

  1. RestTemplate/WebClient can be easily configured to make use of client-side load balancing (Ribbon), thereby requests can be rotated among various instances or another microservice.
  2. Hystrix can be easily configured with RestTemplate, thereby increasing the fault tolerance (circuit breaker pattern) of the overall system w.r.t inter-service communication.
  3. Service discovery can be easily configured using Eureka or Consul, thereby the client need not know the host/port/protocol of the target web service. All we need is to enable the discovery client.

Alternatively, you can also explore Feign, which is a declarative web service client similar to retrofit, but with all the advantages of RestTemplate.

You can also have a loot at the following article:

https://www.javacodemonk.com/retrofit-vs-feignclient-on-server-side-with-spring-cloud-d7f199c4

Brahmanism answered 16/10, 2019 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.