Search in sources :

Example 1 with RpcBindingParam

use of com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam in project sofa-boot by sofastack.

the class ConsumerConfigHelper method getConsumerConfig.

/**
 * 获取 ConsumerConfig
 *
 * @param contract the Contract
 * @param binding  the RpcBinding
 * @return the ConsumerConfig
 */
public ConsumerConfig getConsumerConfig(Contract contract, RpcBinding binding) {
    RpcBindingParam param = binding.getRpcBindingParam();
    String id = binding.getBeanId();
    String interfaceId = contract.getInterfaceType().getName();
    String uniqueId = contract.getUniqueId();
    Integer timeout = param.getTimeout();
    Integer retries = param.getRetries();
    String type = param.getType();
    Integer addressWaitTime = param.getAddressWaitTime();
    Object callbackHandler = param.getCallbackHandler();
    String genericInterface = param.getGenericInterface();
    String loadBalancer = param.getLoadBalancer();
    Boolean lazy = param.getLazy();
    Boolean check = param.getCheck();
    String mockMode = param.getMockMode();
    String serialization = param.getSerialization();
    List<Filter> filters = param.getFilters();
    List<MethodConfig> methodConfigs = convertToMethodConfig(param.getMethodInfos());
    String targetUrl = param.getTargetUrl();
    String referenceLimit = sofaBootRpcProperties.getConsumerRepeatedReferenceLimit();
    ConsumerConfig consumerConfig = new ConsumerConfig();
    if (StringUtils.hasText(appName)) {
        consumerConfig.setApplication(new ApplicationConfig().setAppName(appName));
    }
    if (StringUtils.hasText(id)) {
        consumerConfig.setId(id);
    }
    if (StringUtils.hasText(genericInterface)) {
        consumerConfig.setGeneric(true);
        consumerConfig.setInterfaceId(genericInterface);
    } else if (StringUtils.hasText(interfaceId)) {
        consumerConfig.setInterfaceId(interfaceId);
    }
    if (StringUtils.hasText(uniqueId)) {
        consumerConfig.setUniqueId(uniqueId);
    }
    if (timeout != null) {
        consumerConfig.setTimeout(timeout);
    }
    if (retries != null) {
        consumerConfig.setRetries(retries);
    }
    if (StringUtils.hasText(type)) {
        consumerConfig.setInvokeType(type);
    }
    if (addressWaitTime != null) {
        consumerConfig.setAddressWait(addressWaitTime);
    }
    if (StringUtils.hasText(loadBalancer)) {
        consumerConfig.setLoadBalancer(loadBalancer);
    }
    if (lazy != null) {
        consumerConfig.setLazy(lazy);
    }
    if (check != null) {
        consumerConfig.setCheck(check);
    }
    if (mockMode != null) {
        consumerConfig.setMockMode(mockMode);
    }
    if (callbackHandler != null) {
        if (callbackHandler instanceof SofaResponseCallback) {
            consumerConfig.setOnReturn((SofaResponseCallback) callbackHandler);
        } else {
            throw new SofaBootRpcRuntimeException("callback handler must implement SofaResponseCallback [" + callbackHandler + "]");
        }
    }
    if (!CollectionUtils.isEmpty(filters)) {
        consumerConfig.setFilterRef(filters);
    }
    if (!CollectionUtils.isEmpty(methodConfigs)) {
        consumerConfig.setMethods(methodConfigs);
    }
    if (StringUtils.hasText(targetUrl)) {
        consumerConfig.setDirectUrl(targetUrl);
        consumerConfig.setLazy(true);
        consumerConfig.setSubscribe(false);
        consumerConfig.setRegister(false);
    }
    if (StringUtils.hasText(referenceLimit)) {
        consumerConfig.setRepeatedReferLimit(Integer.valueOf(referenceLimit));
    }
    String protocol = binding.getBindingType().getType();
    consumerConfig.setBootstrap(protocol);
    if (protocol.equals(SofaBootRpcConfigConstants.RPC_PROTOCOL_DUBBO)) {
        consumerConfig.setInJVM(false);
    }
    if (param.getRegistrys() != null && param.getRegistrys().size() > 0) {
        List<String> registrys = param.getRegistrys();
        for (String registryAlias : registrys) {
            RegistryConfig registryConfig = registryConfigContainer.getRegistryConfig(registryAlias);
            consumerConfig.setRegistry(registryConfig);
        }
    } else if (registryConfigContainer.isMeshEnabled(protocol)) {
        RegistryConfig registryConfig = registryConfigContainer.getRegistryConfig(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_MESH);
        consumerConfig.setRegistry(registryConfig);
    } else {
        RegistryConfig registryConfig = registryConfigContainer.getRegistryConfig();
        consumerConfig.setRegistry(registryConfig);
    }
    if (StringUtils.hasText(serialization)) {
        consumerConfig.setSerialization(serialization);
    }
    if (Boolean.TRUE.toString().equals(sofaBootRpcProperties.getHystrixEnable())) {
        consumerConfig.setParameter(HystrixConstants.SOFA_HYSTRIX_ENABLED, Boolean.TRUE.toString());
    }
    // after sofaBootRpcProperties#getHystrixEnable for override global config
    if (param.getParameters() != null) {
        consumerConfig.setParameters(param.getParameters());
    }
    return consumerConfig.setProtocol(protocol);
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) RpcBindingParam(com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam) MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) Filter(com.alipay.sofa.rpc.filter.Filter) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 2 with RpcBindingParam

use of com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam in project sofa-boot by sofastack.

the class ConsumerConfigHelper method getMockRef.

public Object getMockRef(RpcBinding binding, ApplicationContext applicationContext) {
    RpcBindingParam rpcBindingParam = binding.getRpcBindingParam();
    String mockBean = rpcBindingParam.getMockBean();
    if (StringUtils.hasText(mockBean)) {
        return applicationContext.getBean(mockBean);
    } else {
        throw new IllegalArgumentException("Mock mode is open, mock bean can't be empty.");
    }
}
Also used : RpcBindingParam(com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam)

Example 3 with RpcBindingParam

use of com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam in project sofa-boot by sofastack.

the class RpcBindingConverter method convert.

/**
 * convert xml Element to concrete {@link RpcBinding}
 *
 * @param element                 xml Element
 * @param bindingConverterContext binding converter context
 * @return RpcBinding Object
 */
@Override
public RpcBinding convert(Element element, BindingConverterContext bindingConverterContext) {
    RpcBindingParam param = createRpcBindingParam();
    // global-attrs,filter,method,route
    Element globalAttrsElement = DomUtils.getChildElementByTagName(element, RpcBindingXmlConstants.TAG_GLOBAL_ATTRS);
    Element routeElement = DomUtils.getChildElementByTagName(element, RpcBindingXmlConstants.TAG_ROUTE);
    List<Element> methodElements = DomUtils.getChildElementsByTagName(element, RpcBindingXmlConstants.TAG_METHOD);
    List<Element> parameterElements = DomUtils.getChildElementsByTagName(element, RpcBindingXmlConstants.TAG_PARAMETER);
    parseGlobalAttrs(globalAttrsElement, param, bindingConverterContext);
    parseFilter(globalAttrsElement, param, bindingConverterContext);
    parseMethod(methodElements, param);
    parseRoute(routeElement, param);
    parseParameter(parameterElements, param);
    return convert(param, bindingConverterContext);
}
Also used : Element(org.w3c.dom.Element) RpcBindingParam(com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam)

Example 4 with RpcBindingParam

use of com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam in project sofa-boot by sofastack.

the class BoltBindingConverter method convert.

@Override
public RpcBinding convert(SofaReference sofaReferenceAnnotation, SofaReferenceBinding sofaReferenceBindingAnnotation, BindingConverterContext bindingConverterContext) {
    RpcBindingParam bindingParam = new BoltBindingParam();
    convertReferenceAnnotation(bindingParam, sofaReferenceBindingAnnotation, bindingConverterContext);
    return new BoltBinding(bindingParam, bindingConverterContext.getApplicationContext(), bindingConverterContext.isInBinding());
}
Also used : BoltBinding(com.alipay.sofa.rpc.boot.runtime.binding.BoltBinding) RpcBindingParam(com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam) BoltBindingParam(com.alipay.sofa.rpc.boot.runtime.param.BoltBindingParam)

Example 5 with RpcBindingParam

use of com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam in project sofa-boot by sofastack.

the class HttpBindingConverter method convert.

@Override
public RpcBinding convert(SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation, BindingConverterContext bindingConverterContext) {
    RpcBindingParam bindingParam = new HttpBindingParam();
    convertServiceAnnotation(bindingParam, sofaServiceAnnotation, sofaServiceBindingAnnotation, bindingConverterContext);
    return new HttpBinding(bindingParam, bindingConverterContext.getApplicationContext(), bindingConverterContext.isInBinding());
}
Also used : HttpBindingParam(com.alipay.sofa.rpc.boot.runtime.param.HttpBindingParam) HttpBinding(com.alipay.sofa.rpc.boot.runtime.binding.HttpBinding) RpcBindingParam(com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam)

Aggregations

RpcBindingParam (com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam)34 BoltBinding (com.alipay.sofa.rpc.boot.runtime.binding.BoltBinding)6 BoltBindingParam (com.alipay.sofa.rpc.boot.runtime.param.BoltBindingParam)6 DubboBinding (com.alipay.sofa.rpc.boot.runtime.binding.DubboBinding)4 H2cBinding (com.alipay.sofa.rpc.boot.runtime.binding.H2cBinding)4 HttpBinding (com.alipay.sofa.rpc.boot.runtime.binding.HttpBinding)4 RestBinding (com.alipay.sofa.rpc.boot.runtime.binding.RestBinding)4 TripleBinding (com.alipay.sofa.rpc.boot.runtime.binding.TripleBinding)4 DubboBindingParam (com.alipay.sofa.rpc.boot.runtime.param.DubboBindingParam)4 H2cBindingParam (com.alipay.sofa.rpc.boot.runtime.param.H2cBindingParam)4 HttpBindingParam (com.alipay.sofa.rpc.boot.runtime.param.HttpBindingParam)4 RestBindingParam (com.alipay.sofa.rpc.boot.runtime.param.RestBindingParam)4 TripleBindingParam (com.alipay.sofa.rpc.boot.runtime.param.TripleBindingParam)4 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)4 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)4 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)4 Filter (com.alipay.sofa.rpc.filter.Filter)4 SofaBootRpcRuntimeException (com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException)2 RpcBinding (com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding)2 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)2