Search in sources :

Example 56 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.

the class ProcessorAutoConfigTest method testProperty.

@Test
public void testProperty() {
    Assert.assertEquals("apollo", dynamicConfigProcessor.getDynamicConfig());
    Assert.assertEquals("abc", consumerMockProcessor.getMockUrl());
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setRegister(true);
    providerRegisterProcessor.processorProvider(providerConfig);
    Assert.assertFalse(providerConfig.isRegister());
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 57 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.

the class ProviderRegisterProcessorTest method test.

@Test
public void test() {
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setRegister(true);
    providerRegisterProcessor.processorProvider(providerConfig);
    Assert.assertTrue(providerConfig.isRegister());
    System.setProperty("sofa.rpc.registry.disablePub", "true");
    providerRegisterProcessor.processorProvider(providerConfig);
    Assert.assertFalse(providerConfig.isRegister());
    System.clearProperty("sofa.rpc.registry.disablePub");
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) Test(org.junit.Test)

Example 58 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.

the class ProviderConfigContainer method publishAllProviderConfig.

/**
 * 发布所有 ProviderConfig 元数据信息到注册中心
 */
public void publishAllProviderConfig() {
    for (ProviderConfig providerConfig : getAllProviderConfig()) {
        ServerConfig serverConfig = (ServerConfig) providerConfig.getServer().get(0);
        if (!serverConfig.getProtocol().equalsIgnoreCase(SofaBootRpcConfigConstants.RPC_PROTOCOL_DUBBO)) {
            providerConfig.setRegister(true);
            List<RegistryConfig> registrys = providerConfig.getRegistry();
            for (RegistryConfig registryConfig : registrys) {
                Registry registry = RegistryFactory.getRegistry(registryConfig);
                registry.init();
                registry.start();
                registry.register(providerConfig);
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("service published.  interfaceId[" + providerConfig.getInterfaceId() + "]; protocol[" + serverConfig.getProtocol() + "]");
                }
            }
        }
    }
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) Registry(com.alipay.sofa.rpc.registry.Registry)

Example 59 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.

the class ProviderConfigContainer method exportAllDubboProvideConfig.

/**
 * export所有 Dubbo 类型的 ProviderConfig
 */
public void exportAllDubboProvideConfig() {
    for (ProviderConfig providerConfig : getAllProviderConfig()) {
        ServerConfig serverConfig = (ServerConfig) providerConfig.getServer().get(0);
        if (serverConfig.getProtocol().equalsIgnoreCase(SofaBootRpcConfigConstants.RPC_PROTOCOL_DUBBO)) {
            providerConfig.setRegister(true);
            providerConfig.export();
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("service published.  interfaceId[" + providerConfig.getInterfaceId() + "]; protocol[" + serverConfig.getProtocol() + "]");
            }
        }
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig)

Example 60 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.

the class RpcBindingAdapter method preOutBinding.

/**
 * pre out binding
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param target             binding target
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public void preOutBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ProviderConfigContainer providerConfigContainer = applicationContext.getBean(ProviderConfigContainer.class);
    String uniqueName = providerConfigContainer.createUniqueName((Contract) contract, binding);
    ProviderConfigHelper providerConfigHelper = applicationContext.getBean(ProviderConfigHelper.class);
    ProviderConfig providerConfig = providerConfigHelper.getProviderConfig((Contract) contract, binding, target);
    try {
        providerConfigContainer.addProviderConfig(uniqueName, providerConfig);
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PUBLISH_FAIL), e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ProviderConfigContainer(com.alipay.sofa.rpc.boot.container.ProviderConfigContainer) ProviderConfigHelper(com.alipay.sofa.rpc.boot.runtime.adapter.helper.ProviderConfigHelper) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Aggregations

ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)121 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)88 Test (org.junit.Test)73 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)52 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)47 HelloService (com.alipay.sofa.rpc.test.HelloService)33 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)33 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)28 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)21 CountDownLatch (java.util.concurrent.CountDownLatch)19 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)17 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)10 Filter (com.alipay.sofa.rpc.filter.Filter)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 EchoService (com.alipay.sofa.rpc.test.EchoService)9 ArrayList (java.util.ArrayList)9 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)8 EchoServiceImpl (com.alipay.sofa.rpc.test.EchoServiceImpl)8 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)7 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)7