Search in sources :

Example 1 with RestyMethod

use of com.github.df.restypass.annotation.RestyMethod 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初始化成功!");
}
Also used : HttpClientWrapper(com.github.df.restypass.http.client.HttpClientWrapper) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) RestyMethod(com.github.df.restypass.annotation.RestyMethod) Method(java.lang.reflect.Method) RestyMethod(com.github.df.restypass.annotation.RestyMethod) RestyService(com.github.df.restypass.annotation.RestyService) SpringAnnotationWrapper(com.github.df.restypass.spring.wrapper.SpringAnnotationWrapper)

Example 2 with RestyMethod

use of com.github.df.restypass.annotation.RestyMethod in project RestyPass by darren-fu.

the class RestyMethodProcessor method processor.

@Override
public RestyCommandConfig processor(Annotation annotation, RestyCommandConfig properties) {
    if (annotation != null && annotation.annotationType().equals(RestyMethod.class)) {
        RestyMethod restyMethod = (RestyMethod) annotation;
        // 设置重试次数
        setRetry(restyMethod, properties);
        // 设置是否打开降级
        setFallbackEnabled(restyMethod, properties);
        // 设置是否打开断路器
        setCircuitBreakEnabled(restyMethod, properties);
        // 设置流量
        setLimit(restyMethod, properties);
        // 设置路由版本
        serVersion(restyMethod, properties);
    }
    return properties;
}
Also used : RestyMethod(com.github.df.restypass.annotation.RestyMethod)

Aggregations

RestyMethod (com.github.df.restypass.annotation.RestyMethod)2 RestyService (com.github.df.restypass.annotation.RestyService)1 HttpClientWrapper (com.github.df.restypass.http.client.HttpClientWrapper)1 SpringAnnotationWrapper (com.github.df.restypass.spring.wrapper.SpringAnnotationWrapper)1 Method (java.lang.reflect.Method)1 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)1