Java Code Examples for com.alipay.sofa.rpc.config.ApplicationConfig#setAppName()
The following examples show how to use
com.alipay.sofa.rpc.config.ApplicationConfig#setAppName() .
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: 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 2
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 3
Source File: DubooServerTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test //同步泛化调用,直连 public void testGenericSync() { // 只有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) .setGeneric(true); final GenericService demoService = (GenericService) consumerConfig.refer(); String result = (String) demoService.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "xxx" }); Assert.assertEquals(result, "Hello xxx"); }
Example 4
Source File: FaultBaseTest.java From sofa-rpc with Apache License 2.0 | 4 votes |
@Before public void init() { // 只有1个线程 执行 serverConfig = new ServerConfig() .setStopTimeout(60000) .setPort(12299) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setQueues(100).setCoreThreads(10).setMaxThreads(20); ApplicationConfig providerAconfig = new ApplicationConfig(); providerAconfig.setAppName("testApp"); // 发布一个服务,每个请求要执行1秒 providerConfig = new ProviderConfig<FaultHelloService>() .setInterfaceId(FaultHelloService.class.getName()) .setRef(new HelloServiceTimeOutImpl()) .setServer(serverConfig) .setRegister(false) .setApplication(providerAconfig); // just for test consumerConfigNotUse = new ConsumerConfig<FaultHelloService>() .setInterfaceId(FaultHelloService.class.getName()) .setTimeout(500) .setDirectUrl("127.0.0.1:12299") .setRegister(false) .setUniqueId("xxx") .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setAppName(APP_NAME1); consumerConfig = new ConsumerConfig<FaultHelloService>() .setInterfaceId(FaultHelloService.class.getName()) .setTimeout(500) .setDirectUrl("127.0.0.1:12299") .setRegister(false) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setApplication(applicationConfig); consumerConfig2 = new ConsumerConfig<FaultHelloService2>() .setInterfaceId(FaultHelloService2.class.getName()) .setTimeout(500) .setDirectUrl("127.0.0.1:12299") .setRegister(false) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setApplication(applicationConfig); consumerConfigAnotherApp = new ConsumerConfig<FaultHelloService>() .setInterfaceId(FaultHelloService.class.getName()) .setDirectUrl("127.0.0.1:12299") .setTimeout(500) .setRegister(true) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setApplication(new ApplicationConfig().setAppName(APP_NAME2)); FaultToleranceModule module = (FaultToleranceModule) ExtensionLoaderFactory.getExtensionLoader(Module.class) .getExtension("fault-tolerance"); module.getRegulator().init(); }
Example 5
Source File: DubooServerTest.java From sofa-rpc with Apache License 2.0 | 4 votes |
@Test //单向调用 public void testOneWay() { // 只有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()) .setServer(serverConfig) .setBootstrap("dubbo") // .setParameter(RpcConstants.CONFIG_HIDDEN_KEY_WARNING, "false") .setRegister(false).setApplication(serverApplacation); providerConfig.export(); ApplicationConfig clientApplication = new ApplicationConfig(); clientApplication.setAppName("client"); List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>(); MethodConfig methodConfig = new MethodConfig(); methodConfig.setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY); methodConfig.setName("sayHello"); methodConfigs.add(methodConfig); consumerConfig = new ConsumerConfig<DemoService>() .setInterfaceId(DemoService.class.getName()) .setDirectUrl("dubbo://127.0.0.1:20880") .setTimeout(30000) .setRegister(false) .setProtocol("dubbo") .setBootstrap("dubbo") .setApplication(clientApplication) .setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY) .setMethods(methodConfigs); final DemoService demoService = consumerConfig.refer(); String tmp = demoService.sayHello("xxx"); Assert.assertEquals(null, tmp); }