Search in sources :

Example 1 with RestyService

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初始化成功!");
}
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 RestyService

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;
}
Also used : RestyService(com.github.df.restypass.annotation.RestyService)

Aggregations

RestyService (com.github.df.restypass.annotation.RestyService)2 RestyMethod (com.github.df.restypass.annotation.RestyMethod)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