Search in sources :

Example 26 with ApplicationConfig

use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.

the class FutureServerMain method main.

public static void main(String[] args) {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-server");
    ServerConfig serverConfig2 = new ServerConfig().setPort(22222).setDaemon(false);
    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(1000)).setServer(serverConfig2);
    providerConfig.export();
    ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setRef(new EchoServiceImpl()).setServer(serverConfig2);
    providerConfig2.export();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) EchoService(com.alipay.sofa.rpc.test.EchoService) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) EchoServiceImpl(com.alipay.sofa.rpc.test.EchoServiceImpl)

Example 27 with ApplicationConfig

use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.

the class OnewayClientMain method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("oneway-client");
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=oneway-server");
    HelloService helloService = consumerConfig.refer();
    ConsumerConfig<EchoService> consumerConfig2 = new ConsumerConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=oneway-server");
    EchoService echoService = consumerConfig2.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    while (true) {
        try {
            String s1 = helloService.sayHello("xxx", 22);
            LOGGER.warn("must null :{}", s1);
            String s2 = echoService.echoStr("yyy");
            LOGGER.warn("must null :{}", s2);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception ignore) {
        }
    }
}
Also used : ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) EchoService(com.alipay.sofa.rpc.test.EchoService) HelloService(com.alipay.sofa.rpc.test.HelloService)

Example 28 with ApplicationConfig

use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.

the class OnewayServerMain method main.

public static void main(String[] args) {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("oneway-server");
    ServerConfig serverConfig2 = new ServerConfig().setPort(22222).setDaemon(false);
    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(1000)).setServer(serverConfig2);
    providerConfig.export();
    ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setRef(new EchoServiceImpl()).setServer(serverConfig2);
    providerConfig2.export();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) EchoService(com.alipay.sofa.rpc.test.EchoService) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) EchoServiceImpl(com.alipay.sofa.rpc.test.EchoServiceImpl)

Example 29 with ApplicationConfig

use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.

the class CheckBoltClientMain method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(application).setInterfaceId(HelloService.class.getName()).setDirectUrl("bolt://127.0.0.1:22100").setRegister(false).setLazy(true).setCheck(true).setTimeout(3000);
    HelloService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    try {
        Thread.sleep(5000);
    } catch (Exception e) {
    }
    while (true) {
        try {
            String s = helloService.sayHello("xxx", 22);
            LOGGER.warn("{}", s);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
    }
}
Also used : ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) HelloService(com.alipay.sofa.rpc.test.HelloService)

Example 30 with ApplicationConfig

use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.

the class ZookeeperRegistryTest method testProviderObserver.

/**
 * 测试Zookeeper Provider Observer
 *
 * @throws Exception
 */
@Test
public void testProviderObserver() throws Exception {
    int timeoutPerSub = 2000;
    ServerConfig serverConfig = new ServerConfig().setProtocol("bolt").setHost("0.0.0.0").setPort(12200);
    ProviderConfig<?> provider = new ProviderConfig();
    provider.setInterfaceId(TEST_SERVICE_NAME).setUniqueId("unique123Id").setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setRegister(true).setRegistry(registryConfig).setSerialization("hessian2").setServer(serverConfig).setWeight(222).setTimeout(3000);
    // 注册
    registry.register(provider);
    ConsumerConfig<?> consumer = new ConsumerConfig();
    consumer.setInterfaceId(TEST_SERVICE_NAME).setUniqueId("unique123Id").setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setSubscribe(true).setSerialization("java").setInvokeType("sync").setTimeout(4444);
    // 订阅
    CountDownLatch latch = new CountDownLatch(1);
    MockProviderInfoListener providerInfoListener = new MockProviderInfoListener();
    providerInfoListener.setCountDownLatch(latch);
    consumer.setProviderInfoListener(providerInfoListener);
    List<ProviderGroup> all = registry.subscribe(consumer);
    providerInfoListener.updateAllProviders(all);
    Map<String, ProviderInfo> ps = providerInfoListener.getData();
    Assert.assertEquals("after register: 1", 1, ps.size());
    // 订阅 错误的uniqueId
    ConsumerConfig<?> consumerNoUniqueId = new ConsumerConfig();
    consumerNoUniqueId.setInterfaceId(TEST_SERVICE_NAME).setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setSubscribe(true).setSerialization("java").setInvokeType("sync").setTimeout(4444);
    latch = new CountDownLatch(1);
    MockProviderInfoListener providerInfoListener3 = new MockProviderInfoListener();
    providerInfoListener3.setCountDownLatch(latch);
    consumerNoUniqueId.setProviderInfoListener(providerInfoListener3);
    all = registry.subscribe(consumerNoUniqueId);
    providerInfoListener3.updateAllProviders(all);
    Map<String, ProviderInfo> ps3 = providerInfoListener3.getData();
    Assert.assertEquals("wrong uniqueId: 0", 0, ps3.size());
    // 反注册
    latch = new CountDownLatch(1);
    providerInfoListener.setCountDownLatch(latch);
    registry.unRegister(provider);
    latch.await(timeoutPerSub, TimeUnit.MILLISECONDS);
    Assert.assertEquals("after unregister: 0", 0, ps.size());
    // 一次发2个端口的再次注册
    latch = new CountDownLatch(2);
    providerInfoListener.setCountDownLatch(latch);
    provider.getServer().add(new ServerConfig().setProtocol("bolt").setHost("0.0.0.0").setPort(12201));
    registry.register(provider);
    latch.await(timeoutPerSub * 2, TimeUnit.MILLISECONDS);
    Assert.assertEquals("after register two servers: 2", 2, ps.size());
    // 重复订阅
    ConsumerConfig<?> consumer2 = new ConsumerConfig();
    consumer2.setInterfaceId(TEST_SERVICE_NAME).setUniqueId("unique123Id").setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setSubscribe(true).setSerialization("java").setInvokeType("sync").setTimeout(4444);
    CountDownLatch latch2 = new CountDownLatch(1);
    MockProviderInfoListener providerInfoListener2 = new MockProviderInfoListener();
    providerInfoListener2.setCountDownLatch(latch2);
    consumer2.setProviderInfoListener(providerInfoListener2);
    providerInfoListener2.updateAllProviders(registry.subscribe(consumer2));
    latch2.await(timeoutPerSub, TimeUnit.MILLISECONDS);
    Map<String, ProviderInfo> ps2 = providerInfoListener2.getData();
    Assert.assertEquals("after register duplicate: 2", 2, ps2.size());
    // 取消订阅者1
    registry.unSubscribe(consumer);
    // 批量反注册,判断订阅者2的数据
    latch = new CountDownLatch(2);
    providerInfoListener2.setCountDownLatch(latch);
    List<ProviderConfig> providerConfigList = new ArrayList<ProviderConfig>();
    providerConfigList.add(provider);
    registry.batchUnRegister(providerConfigList);
    latch.await(timeoutPerSub * 2, TimeUnit.MILLISECONDS);
    Assert.assertEquals("after unregister: 0", 0, ps2.size());
    // 批量取消订阅
    List<ConsumerConfig> consumerConfigList = new ArrayList<ConsumerConfig>();
    consumerConfigList.add(consumer2);
    registry.batchUnSubscribe(consumerConfigList);
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) BaseZkTest(com.alipay.sofa.rpc.registry.zk.base.BaseZkTest) Test(org.junit.Test)

Aggregations

ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)113 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)77 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)64 Test (org.junit.Test)53 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)52 HelloService (com.alipay.sofa.rpc.test.HelloService)30 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)15 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)14 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)14 SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)13 ArrayList (java.util.ArrayList)12 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)11 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)11 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)10 EchoService (com.alipay.sofa.rpc.test.EchoService)10 EchoRequest (com.alipay.sofa.rpc.server.bolt.pb.EchoRequest)8 DemoServiceImpl (com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl)7 Filter (com.alipay.sofa.rpc.filter.Filter)7