spring-retrofit
Usage
maven
<dependency>
<groupId>com.github.blackshadowwalker.spring</groupId>
<artifactId>spring-retrofit2</artifactId>
<version>2.1.0</version>
</dependency>
Config
@Configuration
@EnableRetrofit
public class RetrofitConfig {
@Bean
public RetrofitServiceScannerConfigurer config(Retrofit retrofit) {
RetrofitServiceScannerConfigurer configurer = new RetrofitServiceScannerConfigurer();
configurer.setBasePackage(com.github.blackshadowwalker.spring.retrofit.serviceg.retrofit.service");
configurer.setRetrofit(retrofit);
return configurer;
}
}
Define annotations at retrofit service
@RetrofitService
public interface MyRpcService {
...
}
Multi RPC Server
S1: Define Multi Retrofit
@Bean
public Retrofit retrofitDefault(OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.baseUrl("http://127.0.0.1:8081")
.addConverterFactory(FastJsonConverterFactory.create())
.client(okHttpClient)
.build();
}
@Bean
public Retrofit retrofit8082(OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.baseUrl("http://127.0.0.1:8082")
.addConverterFactory(FastJsonConverterFactory.create())
.client(okHttpClient)
.build();
}
S2: Define annotations at retrofit service
@RetrofitService(retrofit = "retrofit8082")
public interface MyRpcService {
...
}
More
More Detail see the testCase.