Search in sources :

Example 1 with ConsumerConfigHelper

use of com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper in project sofa-boot by alipay.

the class RpcBindingAdapter method inBinding.

/**
 * in binding, in binding means reference service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public Object inBinding(Object contract, RpcBinding binding, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ConsumerConfigHelper consumerConfigHelper = applicationContext.getBean(ConsumerConfigHelper.class);
    ConsumerConfigContainer consumerConfigContainer = applicationContext.getBean(ConsumerConfigContainer.class);
    ProcessorContainer processorContainer = applicationContext.getBean(ProcessorContainer.class);
    ConsumerConfig consumerConfig = consumerConfigHelper.getConsumerConfig((Contract) contract, binding);
    processorContainer.processorConsumer(consumerConfig);
    if (MockMode.LOCAL.equalsIgnoreCase(binding.getRpcBindingParam().getMockMode())) {
        consumerConfig.setMockRef(consumerConfigHelper.getMockRef(binding, applicationContext));
    }
    consumerConfigContainer.addConsumerConfig(binding, consumerConfig);
    try {
        Object result = consumerConfig.refer();
        binding.setConsumerConfig(consumerConfig);
        return result;
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_CONSUME_FAIL), e);
    }
}
Also used : ProcessorContainer(com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer) ApplicationContext(org.springframework.context.ApplicationContext) ConsumerConfigHelper(com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ConsumerConfigContainer(com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 2 with ConsumerConfigHelper

use of com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper in project sofa-boot by sofastack.

the class RpcBindingAdapter method inBinding.

/**
 * in binding, in binding means reference service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public Object inBinding(Object contract, RpcBinding binding, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ConsumerConfigHelper consumerConfigHelper = applicationContext.getBean(ConsumerConfigHelper.class);
    ConsumerConfigContainer consumerConfigContainer = applicationContext.getBean(ConsumerConfigContainer.class);
    ProcessorContainer processorContainer = applicationContext.getBean(ProcessorContainer.class);
    ConsumerConfig consumerConfig = consumerConfigHelper.getConsumerConfig((Contract) contract, binding);
    processorContainer.processorConsumer(consumerConfig);
    if (MockMode.LOCAL.equalsIgnoreCase(binding.getRpcBindingParam().getMockMode())) {
        consumerConfig.setMockRef(consumerConfigHelper.getMockRef(binding, applicationContext));
    }
    consumerConfigContainer.addConsumerConfig(binding, consumerConfig);
    try {
        Object result = consumerConfig.refer();
        binding.setConsumerConfig(consumerConfig);
        return result;
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_CONSUME_FAIL), e);
    }
}
Also used : ProcessorContainer(com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer) ApplicationContext(org.springframework.context.ApplicationContext) ConsumerConfigHelper(com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ConsumerConfigContainer(com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Aggregations

ConsumerConfigContainer (com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer)2 ConsumerConfigHelper (com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper)2 ProcessorContainer (com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer)2 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)2 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)2 ApplicationContext (org.springframework.context.ApplicationContext)2