com.alipay.sofa.rpc.config.ProviderConfig Java Examples
The following examples show how to use
com.alipay.sofa.rpc.config.ProviderConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsulRegistry.java From sofa-rpc with Apache License 2.0 | 7 votes |
private List<NewService> buildNewServices(ProviderConfig<?> config) { List<ServerConfig> servers = config.getServer(); if (CommonUtils.isEmpty(servers)) { return Collections.emptyList(); } return servers.stream().map(server -> { NewService service = new NewService(); service.setId(buildServiceId(config, server)); service.setName(buildServiceName(config)); String host = getServerHost(server); int port = server.getPort(); service.setAddress(host); service.setPort(port); Map<String, String> metaData = RegistryUtils.convertProviderToMap(config, server).entrySet().stream() .filter(e -> ConsulUtils.isValidMetaKey(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); service.setMeta(metaData); service.setTags(Collections.singletonList(buildUniqueName(config, server.getProtocol()))); service.setCheck(buildCheck(host, port)); return service; }).collect(Collectors.toList()); }
Example #2
Source File: CustomFilterServerMain.java From sofa-rpc with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Filter customEchoFilter2 = new CustomEchoFilter2(); ApplicationConfig application = new ApplicationConfig().setAppName("test-server"); ServerConfig serverConfig = new ServerConfig() .setPort(22000) .setDaemon(false); ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setApplication(application) .setRef(new HelloServiceImpl()) .setServer(serverConfig) .setFilter(Arrays.asList("customEcho")) .setFilterRef(Arrays.asList(customEchoFilter2)) .setRegister(false); providerConfig.export(); LOGGER.error("started at pid {}", RpcRuntimeContext.PID); }
Example #3
Source File: CallbackServerMain.java From sofa-rpc with Apache License 2.0 | 6 votes |
public static void main(String[] args) { ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-server"); ServerConfig serverConfig2 = new ServerConfig() .setPort(22222) .setDaemon(false); // C服务的服务端 ProviderConfig<HelloService> CProvider = new ProviderConfig<HelloService>() .setApplication(applicationConfig) .setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl(1000)) .setServer(serverConfig2); CProvider.export(); }
Example #4
Source File: LazyConnectTest.java From sofa-rpc with Apache License 2.0 | 6 votes |
@BeforeClass public static void startServer() { RpcRunningState.setUnitTestMode(true); // 只有2个线程 执行 serverConfig = new ServerConfig() .setStopTimeout(0) .setPort(22222) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setQueues(100).setCoreThreads(5).setMaxThreads(5); // 发布一个服务,每个请求要执行1秒 ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl()) .setServer(serverConfig) .setRegister(false); providerConfig.export(); }
Example #5
Source File: AbstractSofaRpcFilterTest.java From Sentinel with Apache License 2.0 | 6 votes |
@Test public void testNeedToLoadProvider() { SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter(); ProviderConfig providerConfig = new ProviderConfig(); providerConfig.setInterfaceId(Serializer.class.getName()); providerConfig.setId("AAA"); FilterInvoker invoker = new FilterInvoker(null, null, providerConfig); assertTrue(providerFilter.needToLoad(invoker)); providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(providerFilter.needToLoad(invoker)); providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, ""); assertTrue(providerFilter.needToLoad(invoker)); RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(providerFilter.needToLoad(invoker)); }
Example #6
Source File: ZookeeperRegistryHelperTest.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Test public void testCustomParams() { ProviderConfig providerConfig = new ProviderConfig(); Map<String, String> map = new HashMap<String, String>(); map.put("x", "y"); map.put("a", "b"); providerConfig.setParameters(map); ServerConfig server = new ServerConfig(); providerConfig.setServer(server); List<String> urls = ZookeeperRegistryHelper.convertProviderToUrls(providerConfig); LOGGER.info(urls.toString()); Assert.assertNotNull(urls); Assert.assertEquals(1, urls.size()); String url = urls.get(0); ProviderInfo providerInfo = ProviderHelper.toProviderInfo(url); LOGGER.info(providerInfo.toString()); Assert.assertEquals("b", providerInfo.getStaticAttr("a")); Assert.assertEquals("y", providerInfo.getStaticAttr("x")); }
Example #7
Source File: SofaBootRpcStartListener.java From sofa-rpc-boot-projects with Apache License 2.0 | 6 votes |
@Override public void onApplicationEvent(SofaBootRpcStartEvent event) { //choose disable metrics lookout disableLookout(); //start fault tolerance faultToleranceConfigurator.startFaultTolerance(); Collection<ProviderConfig> allProviderConfig = providerConfigContainer.getAllProviderConfig(); if (!CollectionUtils.isEmpty(allProviderConfig)) { //start server serverConfigContainer.startServers(); } //set allow all publish providerConfigContainer.setAllowPublish(true); //register registry providerConfigContainer.publishAllProviderConfig(); //export dubbo providerConfigContainer.exportAllDubboProvideConfig(); }
Example #8
Source File: ConsulRegistryTest.java From sofa-rpc with Apache License 2.0 | 6 votes |
private ProviderConfig<?> providerConfig(String uniqueId, int... ports) { ProviderConfig<?> provider = new ProviderConfig(); provider.setInterfaceId(INTERFACE_ID) .setUniqueId(uniqueId) .setApplication(new ApplicationConfig().setAppName("consul-registry-test")) .setProxy("javassist") .setRegister(true) .setRegistry(registryConfig) .setSerialization("hessian2") .setWeight(222) .setTimeout(3000); IntStream.of(ports) .mapToObj(port -> new ServerConfig() .setProtocol("bolt") .setHost("localhost") .setPort(port) ).forEach(provider::setServer); return provider; }
Example #9
Source File: MeshRegistryHelper.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * 转为服务端提供者对象 * * @param config 服务提供者配置 * @param server 服务端 * @return 本地服务提供者对象 */ public static ProviderInfo convertProviderToProviderInfo(ProviderConfig config, ServerConfig server) { ProviderInfo providerInfo = new ProviderInfo() .setPort(server.getPort()) .setWeight(config.getWeight()) .setSerializationType(config.getSerialization()) .setProtocolType(server.getProtocol()) .setPath(server.getContextPath()) .setStaticAttrs(config.getParameters()); String host = server.getHost(); if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) { host = SystemInfo.getLocalHost(); } providerInfo.setHost(host); return providerInfo; }
Example #10
Source File: RpcBindingAdapter.java From sofa-rpc-boot-projects with Apache License 2.0 | 6 votes |
/** * post unout binding * * @param contract binding contract * @param binding binding object * @param target binding target * @param sofaRuntimeContext sofa runtime context */ @Override public void postUnoutBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) { ProviderConfig metadata = SpringBridge.getProviderConfigHelper().getProviderConfig((Contract) contract, binding, target); try { String key = SpringBridge.getProviderConfigContainer().createUniqueName((Contract) contract, binding); List<ServerConfig> servers = SpringBridge.getProviderConfigContainer().getProviderConfig(key).getServer(); for (ServerConfig server : servers) { server.getServer().unRegisterProcessor(metadata, false); } SpringBridge.getProviderConfigContainer().removeProviderConfig(key); } catch (Exception e) { throw new ServiceRuntimeException( LogCodes.getLog(LogCodes.ERROR_PROXY_POST_UNPUBLISH_FAIL), e); } }
Example #11
Source File: ServerB.java From sofa-rpc with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // B服务里的C服务客户端 ConsumerConfig<ServiceC> consumerConfig = new ConsumerConfig<ServiceC>() .setApplication(new ApplicationConfig().setAppName("BBB")) .setInterfaceId(ServiceC.class.getName()) .setDirectUrl("bolt://127.0.0.1:12299?appName=CCC") .setRegister(false) .setInvokeType("callback") // 不设置,调用级别可设置 .setTimeout(2000); ServiceC serviceC = consumerConfig.refer(); ServerConfig serverConfig = new ServerConfig() .setPort(12298) .setDaemon(false); ProviderConfig<ServiceB> providerConfig = new ProviderConfig<ServiceB>() .setInterfaceId(ServiceB.class.getName()) .setApplication(new ApplicationConfig().setAppName("BBB")) .setRef(new ServiceBImpl(serviceC)) .setServer(serverConfig) .setRegister(false); providerConfig.export(); }
Example #12
Source File: MulticastRegistryHelper.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * 转为服务端提供者对象 * * @param config 服务提供者配置 * @param server 服务端 * @return 本地服务提供者对象 */ public static ProviderInfo convertProviderToProviderInfo(ProviderConfig config, ServerConfig server) { ProviderInfo providerInfo = new ProviderInfo() .setPort(server.getPort()) .setWeight(config.getWeight()) .setSerializationType(config.getSerialization()) .setProtocolType(server.getProtocol()) .setPath(server.getContextPath()) .setStaticAttrs(config.getParameters()); String host = server.getHost(); if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) { host = SystemInfo.getLocalHost(); } providerInfo.setHost(host); return providerInfo; }
Example #13
Source File: BoltServerMain.java From sofa-rpc with Apache License 2.0 | 6 votes |
public static void main(String[] args) { ApplicationConfig application = new ApplicationConfig().setAppName("test-server"); ServerConfig serverConfig = new ServerConfig() .setPort(22000) .setDaemon(false); ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setApplication(application) .setRef(new HelloServiceImpl()) .setServer(serverConfig) .setRegister(false); ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>() .setInterfaceId(EchoService.class.getName()) .setApplication(application) .setRef(new EchoServiceImpl()) .setServer(serverConfig) .setRegister(false); providerConfig.export(); providerConfig2.export(); LOGGER.warn("started at pid {}", RpcRuntimeContext.PID); }
Example #14
Source File: BaseRestTest.java From sofa-rpc with Apache License 2.0 | 6 votes |
@BeforeClass public static void before() { ServerConfig serverConfig = new ServerConfig() .setStopTimeout(60000) .setPort(8803) .setProtocol(RpcConstants.PROTOCOL_TYPE_REST); ProviderConfig<RestService> providerConfig = new ProviderConfig<RestService>() .setInterfaceId(RestService.class.getName()) .setRef(new RestServiceImpl()) .setServer(serverConfig) .setBootstrap("rest") .setRegister(false); providerConfig.export(); ConsumerConfig<RestService> consumerConfig = new ConsumerConfig<RestService>() .setInterfaceId(RestService.class.getName()) .setDirectUrl("rest://127.0.0.1:8803") .setProtocol("rest") .setBootstrap("rest") .setTimeout(30000) .setRegister(false); restService = consumerConfig.refer(); }
Example #15
Source File: LocalRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void unRegister(ProviderConfig config) { String appName = config.getAppName(); if (!registryConfig.isRegister()) { // 注册中心不注册 if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE)); } return; } if (!config.isRegister()) { // 服务不注册 return; } List<ServerConfig> serverConfigs = config.getServer(); if (CommonUtils.isNotEmpty(serverConfigs)) { for (ServerConfig server : serverConfigs) { String serviceName = LocalRegistryHelper.buildListDataId(config, server.getProtocol()); ProviderInfo providerInfo = LocalRegistryHelper.convertProviderToProviderInfo(config, server); try { doUnRegister(serviceName, providerInfo); if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "1")); } } catch (Exception e) { LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "0"), e); } } } }
Example #16
Source File: DubooServerTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test //同步调用,直连 public void testSync() { try { // 只有1个线程 执行 ServerConfig serverConfig = new ServerConfig() .setStopTimeout(60000) .setPort(20880) .setProtocol("dubbo") .setQueues(100).setCoreThreads(1).setMaxThreads(2); // 发布一个服务,每个请求要执行1秒 ApplicationConfig serverApplacation = new ApplicationConfig(); serverApplacation.setAppName("server"); providerConfig = new ProviderConfig<DemoService>() .setInterfaceId(DemoService.class.getName()) .setRef(new DemoServiceImpl()) .setBootstrap("dubbo") .setServer(serverConfig) // .setParameter(RpcConstants.CONFIG_HIDDEN_KEY_WARNING, "false") .setRegister(false).setApplication(serverApplacation); providerConfig.export(); ApplicationConfig clientApplication = new ApplicationConfig(); clientApplication.setAppName("client"); consumerConfig = new ConsumerConfig<DemoService>() .setInterfaceId(DemoService.class.getName()) .setDirectUrl("dubbo://127.0.0.1:20880") .setBootstrap("dubbo") .setTimeout(30000) .setRegister(false).setProtocol("dubbo").setApplication(clientApplication); final DemoService demoService = consumerConfig.refer(); String result = demoService.sayHello("xxx"); Assert.assertTrue(result.equalsIgnoreCase("hello xxx")); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(false); } }
Example #17
Source File: SofaRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void unRegister(ProviderConfig config) { String appName = config.getAppName(); if (!registryConfig.isRegister()) { // 注册中心不注册 if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE)); } return; } if (!config.isRegister()) { // 服务不注册 return; } List<ServerConfig> serverConfigs = config.getServer(); if (CommonUtils.isNotEmpty(serverConfigs)) { for (ServerConfig server : serverConfigs) { String serviceName = SofaRegistryHelper.buildListDataId(config, server.getProtocol()); try { String groupId = config.getParameter(SofaRegistryConstants.SOFA_GROUP_KEY); groupId = groupId == null ? SofaRegistryHelper.SUBSCRIBER_LIST_GROUP_ID : groupId; doUnRegister(appName, serviceName, groupId); if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "1")); } } catch (Exception e) { LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "0"), e); } } } }
Example #18
Source File: Curator4ZookeeperRegistry.java From spring-cloud-sofastack-samples with Apache License 2.0 | 5 votes |
protected void recoverRegistryData() { for (ProviderConfig providerConfig : providerUrls.keySet()) { registerProviderUrls(providerConfig); } for (ConsumerConfig consumerConfig : consumerUrls.keySet()) { subscribeConsumerUrls(consumerConfig); } }
Example #19
Source File: ConsulRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void unRegister(ProviderConfig config) { String appName = config.getAppName(); if (!registryConfig.isRegister()) { // 注册中心不注册 if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE)); } return; } // 反注册服务端节点 if (!config.isRegister()) { return; } try { List<String> ids = buildServiceIds(config); if (CommonUtils.isNotEmpty(ids)) { ids.forEach(this::deregisterConsulService); if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, config.getInterfaceId(), ids.size())); } } } catch (Exception e) { if (!RpcRunningState.isShuttingDown()) { if ( e instanceof SofaRpcRuntimeException){ throw e; }else{ throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNREG_PROVIDER ,EXT_NAME), e); }} } }
Example #20
Source File: RestLookoutTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * invoke */ @Before public void beforeMethod() { // 发布一个服务,每个请求要执行1秒 ApplicationConfig serverApplication = new ApplicationConfig(); serverApplication.setAppName("TestLookOutServer"); providerConfig = new ProviderConfig<RestService>() .setInterfaceId(RestService.class.getName()) .setRef(new RestServiceImpl()) .setServer(serverConfig) .setBootstrap("rest") //.setParameter(RpcConstants.CONFIG_HIDDEN_KEY_WARNING, "false") .setRegister(false) .setApplication(serverApplication); providerConfig.export(); ApplicationConfig clientApplication = new ApplicationConfig(); clientApplication.setAppName("TestLookOutClient"); consumerConfig = new ConsumerConfig<RestService>() .setInterfaceId(RestService.class.getName()) .setDirectUrl( "rest://127.0.0.1:8802/xyz?uniqueId=&version=1.0&timeout=0&delay=-1&id=rpc-cfg-0&dynamic=true&weight=100&accepts=100000&startTime=1523240755024&appName=" + serverApplication.getAppName() + "&pid=22385&language=java&rpcVer=50300") .setProtocol("rest") .setBootstrap("rest") .setTimeout(30000) .setConnectionNum(5) .setRegister(false) .setApplication(clientApplication); final RestService helloService = consumerConfig.refer(); Assert.assertEquals(helloService.query(11), "hello world !null"); }
Example #21
Source File: FailoverClusterTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void testRpcDirectInvokeFromContextWithAvailableProviders() { ServerConfig serverConfig = new ServerConfig() .setProtocol("bolt") .setHost("0.0.0.0") .setPort(13900); ProviderConfig<HelloService> provider = new ProviderConfig(); provider.setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl("x-demo-invoke")) .setApplication(new ApplicationConfig().setAppName("x-test-server")) .setProxy("javassist") .setSerialization("hessian2") .setServer(serverConfig) .setTimeout(3000); provider.export(); ConsumerConfig<HelloService> consumer = new ConsumerConfig(); consumer.setInterfaceId(HelloService.class.getName()) .setApplication(new ApplicationConfig().setAppName("x-test-client")) // 模拟有可用服务 .setDirectUrl("bolt://127.0.0.1:65534") .setProxy("javassist"); HelloService proxy = consumer.refer(); for (int i = 0; i < 3; i++) { RpcInvokeContext.getContext().setTargetURL("127.0.0.1:13900"); Assert.assertEquals("x-demo-invoke", proxy.sayHello("x-demo-invoke", 1)); } provider.unExport(); consumer.unRefer(); }
Example #22
Source File: ZookeeperAuthBoltServerTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void testUseCorrentAuth() { parameters.put("scheme", "digest"); //如果存在多个认证信息,则在参数形式为为user1:passwd1,user2:passwd2 parameters.put("addAuth", "sofazk:rpc1"); registryConfig = new RegistryConfig() .setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK) .setAddress("127.0.0.1:2181/authtest") .setParameters(parameters); serverConfig = new ServerConfig() .setProtocol("bolt") // 设置一个协议,默认bolt .setPort(12200) // 设置一个端口,默认12200 .setDaemon(false); // 非守护线程 ProviderConfig<EchoService> providerConfig = new ProviderConfig<EchoService>() .setRegistry(registryConfig) .setInterfaceId(EchoService.class.getName()) // 指定接口 .setRef(new EchoServiceImpl()) // 指定实现 .setServer(serverConfig); // 指定服务端 providerConfig.export(); // 发布服务 ConsumerConfig<EchoService> consumerConfig = new ConsumerConfig<EchoService>() .setRegistry(registryConfig) .setInterfaceId(EchoService.class.getName()) // 指定接口 .setProtocol("bolt") // 指定协议 .setTimeout(3000) .setConnectTimeout(10 * 1000); EchoService echoService = consumerConfig.refer(); String result = echoService.echoStr("auth test"); Assert.assertEquals("auth test", result); }
Example #23
Source File: NacosRegistryHelper.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Convert provider to instances list. * * @param providerConfig the provider config * @return the list */ static List<Instance> convertProviderToInstances(ProviderConfig providerConfig) { @SuppressWarnings("unchecked") List<ServerConfig> servers = providerConfig.getServer(); if (servers != null && !servers.isEmpty()) { List<Instance> instances = new ArrayList<Instance>(); for (ServerConfig server : servers) { String serviceName = buildServiceName(providerConfig, server.getProtocol()); Instance instance = new Instance(); instance.setClusterName(DEFAULT_CLUSTER); instance.setServiceName(serviceName); // set host port String host = server.getVirtualHost(); if (host == null) { host = server.getHost(); if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) { host = SystemInfo.getLocalHost(); } } instance.setIp(host); instance.setPort(server.getPort()); // set meta data Map<String, String> metaData = RegistryUtils.convertProviderToMap(providerConfig, server); instance.setMetadata(metaData); instances.add(instance); } return instances; } return null; }
Example #24
Source File: MulticastRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void batchUnRegister(List<ProviderConfig> configs) { for (ProviderConfig config : configs) { String appName = config.getAppName(); try { unRegister(config); } catch (Exception e) { LOGGER.errorWithApp(appName, "Error when batch unregistry", e); } } }
Example #25
Source File: NacosRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void destroy() { for (ProviderConfig providerConfig : providerInstances.keySet()) { unRegister(providerConfig); } for (ConsumerConfig consumerConfig : consumerListeners.keySet()) { unSubscribe(consumerConfig); } namingService = null; providerObserver = null; }
Example #26
Source File: MeshRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void unRegister(ProviderConfig config) { String appName = config.getAppName(); if (!registryConfig.isRegister()) { // 注册中心不注册 if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE)); } return; } if (!config.isRegister()) { // 服务不注册 return; } List<ServerConfig> serverConfigs = config.getServer(); if (CommonUtils.isNotEmpty(serverConfigs)) { for (ServerConfig server : serverConfigs) { String serviceName = MeshRegistryHelper.buildMeshKey(config, server.getProtocol()); ProviderInfo providerInfo = MeshRegistryHelper.convertProviderToProviderInfo(config, server); try { doUnRegister(serviceName, providerInfo); if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "1")); } } catch (Exception e) { LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "0"), e); } } } }
Example #27
Source File: TripleServer.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void unRegisterProcessor(ProviderConfig providerConfig, boolean closeIfNoEntry) { try { ServerServiceDefinition serverServiceDefinition = serviceInfo.get(providerConfig); handlerRegistry.removeService(serverServiceDefinition); invokerCnt.decrementAndGet(); } catch (Exception e) { LOGGER.error("Unregister triple service error", e); } if (closeIfNoEntry && invokerCnt.get() == 0) { stop(); } }
Example #28
Source File: BeanIdMatchFilterTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void testIsMatch() { TestCustomizeFilter testCustomizeFilter = new TestCustomizeFilter(); Assert.assertTrue(testCustomizeFilter.isMatch("")); testCustomizeFilter = new TestCustomizeFilter(); testCustomizeFilter.setIdRule("AAA,BBB"); AbstractInterfaceConfig configA = new ProviderConfig(); configA.setInterfaceId(Serializer.class.getName()); configA.setId("AAA"); FilterInvoker filterInvokerA = new FilterInvoker(null, null, configA); Assert.assertEquals(true, testCustomizeFilter.needToLoad(filterInvokerA)); }
Example #29
Source File: FailoverClusterTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void testRpcDirectInvokeFromContext() { ServerConfig serverConfig = new ServerConfig() .setProtocol("bolt") .setHost("0.0.0.0") .setPort(13900); ProviderConfig<HelloService> provider = new ProviderConfig(); provider.setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl("x-demo-invoke")) .setApplication(new ApplicationConfig().setAppName("x-test-server")) .setProxy("javassist") .setSerialization("hessian2") .setServer(serverConfig) .setTimeout(3000); provider.export(); ConsumerConfig<HelloService> consumer = new ConsumerConfig(); consumer.setInterfaceId(HelloService.class.getName()) .setApplication(new ApplicationConfig().setAppName("x-test-client")) .setProxy("javassist"); HelloService proxy = consumer.refer(); for (int i = 0; i < 3; i++) { RpcInvokeContext.getContext().setTargetURL("127.0.0.1:13900"); Assert.assertEquals("x-demo-invoke", proxy.sayHello("x-demo-invoke", 1)); } provider.unExport(); consumer.unRefer(); }
Example #30
Source File: TripleServerRegistryApplication.java From sofa-rpc with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("triple-server"); int port = 50051; if (args.length != 0) { LOGGER.debug("first arg is {}", args[0]); port = Integer.valueOf(args[0]); } /* RegistryConfig registryConfig = new RegistryConfig() .setProtocol("zookeeper") .setAddress("127.0.0.1:2181");*/ ServerConfig serverConfig = new ServerConfig() .setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE) .setPort(port); ProviderConfig<SofaGreeterTriple.IGreeter> providerConfig = new ProviderConfig<SofaGreeterTriple.IGreeter>() .setApplication(applicationConfig) .setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE) .setInterfaceId(SofaGreeterTriple.IGreeter.class.getName()) .setRef(new TripleGreeterImpl()) .setServer(serverConfig) .setRegister(false); // .setRegistry(registryConfig); providerConfig.export(); synchronized (TripleServerRegistryApplication.class) { try { while (true) { TripleServerRegistryApplication.class.wait(); } } catch (InterruptedException e) { LOGGER.error("Exit by Interrupted"); } } }