use of com.github.df.restypass.annotation.RestyService in project RestyPass by darren-fu.
the class RestyCommandContext method initContextForService.
/**
* 为service创建Resty配置
*
* @param serviceClz the service clz
*/
public void initContextForService(Class serviceClz) {
RestyService restyService = (RestyService) serviceClz.getDeclaredAnnotation(RestyService.class);
if (restyService == null) {
return;
}
String serviceName = restyService.serviceName();
// class->@RestyService
this.storeRestyService(serviceClz, restyService);
AsyncHttpClientConfig httpClientConfig = AsyncHttpConfigFactory.createConfig(restyService.connectTimeout(), restyService.requestTimeout());
HttpClientWrapper clientHolder = new HttpClientWrapper(httpClientConfig);
httpClientPool.putIfAbsent(serviceName, clientHolder);
SpringAnnotationWrapper wrapper = new SpringAnnotationWrapper();
RestyCommandConfig commandProperties = new RestyCommandConfig.DefaultRestyCommandConfig();
processRestyServiceAnnotation(restyService, commandProperties);
for (Method method : serviceClz.getMethods()) {
// 存储 httpMethod 和 restyCommandConfig
RestyMethod restyMethod = method.getDeclaredAnnotation(RestyMethod.class);
if (restyMethod != null) {
storeRestyMethod(method, restyMethod);
processRestyMethodAnnotation(restyMethod, commandProperties);
}
commandPropertiesMap.putIfAbsent(method, commandProperties);
// 存储 httpMethod 和 requestTemplate
RestyRequestTemplate restyRequestTemplate = wrapper.processAnnotation(serviceClz, method);
requestTemplateMap.putIfAbsent(method, restyRequestTemplate);
serviceMethodTable.put(serviceName, restyRequestTemplate.getPath(), method);
}
log.info("RestyCommandContext初始化成功!");
}
use of com.github.df.restypass.annotation.RestyService in project RestyPass by darren-fu.
the class RestyServiceProcessor method processor.
@Override
public RestyCommandConfig processor(Annotation annotation, RestyCommandConfig properties) {
if (annotation != null && annotation.annotationType().equals(RestyService.class)) {
RestyService restyService = (RestyService) annotation;
// 设置服务名称
setServiceName(restyService, properties);
// 设置URL
setUrl(restyService, properties);
// 设置重试次数
setRetry(restyService, properties);
// 设置降级服务
setFallback(restyService, properties);
// 设置是否打开断路器
setCircuitBreak(restyService, properties);
// 设置负载均衡器
setLoadBalancer(restyService, properties);
// 设置工厂类
setFactory(restyService, properties);
// 设置流量
setLimit(restyService, properties);
// 设置路由版本
setVersion(restyService, properties);
}
return properties;
}
Aggregations