All Projects → syhily → spring-boot-retrofit-support

syhily / spring-boot-retrofit-support

Licence: other
A auto configuration springboot starter for retrofit

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to spring-boot-retrofit-support

HotSalesPOS
No description or website provided.
Stars: ✭ 14 (-69.57%)
Mutual labels:  retrofit2, okhttp3
codeKK-Android
http://p.codekk.com/
Stars: ✭ 29 (-36.96%)
Mutual labels:  retrofit2, okhttp3
Palette
Android application to get the #hexcode and rgb() values for any image
Stars: ✭ 31 (-32.61%)
Mutual labels:  retrofit2, okhttp3
RxJavaKotlinSample
RxJava2 and Kotlin sample project
Stars: ✭ 13 (-71.74%)
Mutual labels:  retrofit2, okhttp3
LifeHelper
我的毕业设计,功能还是比较完善的
Stars: ✭ 40 (-13.04%)
Mutual labels:  retrofit2, okhttp3
AndroidStarterAlt
A sample View-based Android app using the MVP architecture. It uses Mosby, Dagger2, RxJava, retrofit, LoganSquare, requery, EventBus, Conductor.
Stars: ✭ 27 (-41.3%)
Mutual labels:  retrofit2, okhttp3
Atoms-mvp
A component architecture for android applications based on MVP
Stars: ✭ 63 (+36.96%)
Mutual labels:  retrofit2, okhttp3
Mockinizer
An okhttp / retrofit api call mocking library
Stars: ✭ 176 (+282.61%)
Mutual labels:  retrofit2, okhttp3
Assume
Easy Response Mocking for Retrofit using annotations
Stars: ✭ 25 (-45.65%)
Mutual labels:  retrofit2, okhttp3
eyepetizer kotlin
一款仿开眼短视频App,分别采用MVP、MVVM两种模式实现。一、组件化 + Kotlin + MVP + RxJava + Retrofit + OkHttp 二、组件化 + Kotlin + MVVM + LiveData + DataBinding + Coroutines + RxJava + Retrofit + OkHttp
Stars: ✭ 83 (+80.43%)
Mutual labels:  retrofit2, okhttp3
Wanandroid
WanAndroid客户端,项目基于 Material Design + MVP +dagger2 + RxJava + Retrofit + Glide + greendao 等架构进行设计实现,极力打造一款 优秀的玩Android https://www.wanandroid.com 客户端,是一个不错的Android应用开发学习参考项目
Stars: ✭ 223 (+384.78%)
Mutual labels:  retrofit2, okhttp3
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-45.65%)
Mutual labels:  retrofit2, okhttp3
Awesome Wanandroid
⚡致力于打造一款极致体验的 http://www.wanandroid.com/ 客户端,知识和美是可以并存的哦QAQn(*≧▽≦*)n
Stars: ✭ 2,525 (+5389.13%)
Mutual labels:  retrofit2, okhttp3
OkhttpCacheInterceptor
The OkHttpCacheInterceptor 一个OkHttp的网络缓存拦截器,可自定义场景对请求的数据进行缓存
Stars: ✭ 32 (-30.43%)
Mutual labels:  retrofit2, okhttp3
Httprequest
基于Retrofit2+RxJava2+OkHttp3的网络请求框架,可以完美的应用到组件化、MVP模式等项目中
Stars: ✭ 181 (+293.48%)
Mutual labels:  retrofit2, okhttp3
RxJava2Demo
RxJava 2.X Retrofit OkHttp demo
Stars: ✭ 29 (-36.96%)
Mutual labels:  retrofit2, okhttp3
Jbusdriver
这是去幼儿园的班车(滑稽
Stars: ✭ 2,056 (+4369.57%)
Mutual labels:  retrofit2, okhttp3
Androidbaseframemvvm
Android 组件化 MVVM 框架 基于 Jetpack + Kotlin
Stars: ✭ 169 (+267.39%)
Mutual labels:  retrofit2, okhttp3
WanAndroid
wanandroid的Kotlin版,采用Android X
Stars: ✭ 20 (-56.52%)
Mutual labels:  retrofit2, okhttp3
iMoney
iMoney 金融项目
Stars: ✭ 55 (+19.57%)
Mutual labels:  retrofit2, okhttp3

Retrofit Springboot Auto Configuration

This project is mainly for integration with other business system. We use springboot to get better configuration and dependence inversion.

Retrofit 2 is just a simple abstraction for http request. The backend of its to perform http request is mainly depends on okhttp3. We also support async http request out of the box.

Architecture

com.oneapm.touch.retrofit
 ├── autoconfigure: Retrofit configuration module and its configuration properties definition
 └── boot: the bean registry factory for building retrofit endpoint interface instance

Dependency

Find the latest version and grad it via Maven:

<dependency>
  <groupId>com.oneapm.touch.retrofit</groupId>
  <artifactId>retrofit-spring-boot-starter</artifactId>
  <version>${latest.starter.version}</version>
</dependency>

or Gradle:

compile "com.oneapm.touch.retrofit:retrofit-spring-boot-starter:latest.version"

Detailed Usage in Springboot Application

In your main Spring Boot application, you need to add the annotation @RetrofitServiceScan on the configuration class (aka. the class which has spring annotation @Configuration) or spring boot's bootstrap class (the class annotated with @SpringBootApplication) to enable the auto bean generation for all the customized retrofit interface. e.g.:

@SpringBootApplication
@RetrofitServiceScan
public class MainApplication  {

    public static void main(final String ... args) {
        SpringApplication.run(MainApplication.class, args);
    }
}

All the customize retrofit interface should be annotated with @RetrofitService annotation, that would make these interface could be registed our own bean creation process. e.g.:

@RetrofitService("ai")
public interface AiAgentEndpoint {

    @GET("ai/v5/apps/{appId}/tiers/{tierId}/agents")
    Call<List<AiAgentRes>> getAgents(@Path("appId") long appId, @Path("tierId") long tierId);
}

@RetrofitService have three properties, the value or retrofit stand for the identity of the retrofit configuration that your would like to use (It would be clarify in configuration file part). name attribute means the spring's bean name. If no attributes provided, we would pick the interface's class name as the bean name and the default retrofit configuration.

In you application.yml set the configuration needed to send http request.

YAML

# The http configuration part for integration with other system
retrofit:
  connection:
    readTimeout: 10000
    writeTimeout: 10000
    connectTimeout: 10000
    maxIdleConnections: 5 # The maximum number of idle connections for each address.
    keepAliveDuration: 5 # The time (minutes) to live for each idle connections.
    retryTimes: 5

  # identity: current available
  # baseUrl: the base part of business system url, would be changed by nginx location, "/" is not required to be the end of url
  endpoints:
    - identity: default
      baseUrl: http://127.0.0.1:${random.int(10000,15000)}
    - identity: ai
      baseUrl: http://127.0.0.1:${random.int(10000,15000)}
    - identity: mi
      baseUrl: http://127.0.0.1:${random.int(10000,15000)}
    - identity: cep
      baseUrl: http://127.0.0.1:${random.int(10000,15000)}

Java Properties

retrofit.timeout=5000
retrofit.connection.read-timeout=10000
retrofit.connection.write-timeout=10000
retrofit.connection.connect-timeout=10000
retrofit.connection.max-idle-connections=5
retrofit.connection.keep-alive-duration=5
retrofit.connection.retry-times=5
# The list of outer system to communicate with should have a index form like 
# retrofit.endpoints[index], starts from 0
retrofit.endpoints[0].identity=ai # The system id
retrofit.endpoints[0].baseUrl: http://127.0.0.1:10010 # The system prefix url

You can now @Autowired the retrofit interface to send real http request. e.g.:

@Autowired
private final AiAgentEndpoint agentEndpoint;

agentEndpoint.getAgents(1L, 1L);

TODO List

  • Support multiply retrofit instance.
  • Jackson deserializer should omit the properties's informal case format.
  • Improve async http request support.
  • Remove the Retrofit.Builder, using a single bean to hold the real retrofit factory.
  • Retry in limit times if request failed.
  • Drop @RetrofitServiceScan annotation or auto-configure it.

Last modified on: 2017-06-14 07:37

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].