Search in sources :

Example 1 with EchoService

use of com.alipay.sofa.rpc.test.EchoService in project sofa-rpc by sofastack.

the class BoltServerMain method main.

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);
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) 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 2 with EchoService

use of com.alipay.sofa.rpc.test.EchoService in project sofa-rpc by sofastack.

the class DubboClientMain method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("dubbo-client");
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setBootstrap("dubbo").setProtocol("dubbo").setUniqueId("xxx").setDirectUrl("dubbo://127.0.0.1:20080").setRegister(false).setTimeout(3000);
    HelloService helloService = consumerConfig.refer();
    ConsumerConfig<EchoService> consumerConfig2 = new ConsumerConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setBootstrap("dubbo").setUniqueId("xxx").setDirectUrl("dubbo://127.0.0.1:20080").setRegister(false).setTimeout(3000);
    EchoService echoService = consumerConfig2.refer();
    LOGGER.error("started at pid {}", RpcRuntimeContext.PID);
    try {
        for (int i = 0; i < 100; i++) {
            try {
                String s = helloService.sayHello("xxx", 22);
                LOGGER.info("{}", s);
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
            try {
                Thread.sleep(2000);
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    synchronized (DubboClientMain.class) {
        while (true) {
            DubboClientMain.class.wait();
        }
    }
}
Also used : ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) EchoService(com.alipay.sofa.rpc.test.EchoService) HelloService(com.alipay.sofa.rpc.test.HelloService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 3 with EchoService

use of com.alipay.sofa.rpc.test.EchoService in project sofa-rpc by sofastack.

the class DubboServerMain method main.

public static void main(String[] args) {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("dubbo-server");
    ServerConfig serverConfig = new ServerConfig().setProtocol("dubbo").setHost("127.0.0.1").setPort(20080).setSerialization("hessian2").setDaemon(false);
    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setBootstrap("dubbo").setApplication(applicationConfig).setRef(new HelloServiceImpl()).setUniqueId("xxx").setServer(serverConfig).setRegister(false);
    ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>().setInterfaceId(EchoService.class.getName()).setRef(new EchoServiceImpl()).setApplication(applicationConfig).setBootstrap("dubbo").setUniqueId("xxx").setServer(serverConfig).setRegister(false);
    providerConfig.export();
    providerConfig2.export();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    synchronized (DubboServerMain.class) {
        while (true) {
            try {
                DubboServerMain.class.wait();
            } catch (InterruptedException e) {
            }
        }
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) 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 4 with EchoService

use of com.alipay.sofa.rpc.test.EchoService in project sofa-rpc by sofastack.

the class FutureClientMain method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-client");
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=future-server");
    HelloService helloService = consumerConfig.refer();
    ConsumerConfig<EchoService> consumerConfig2 = new ConsumerConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=future-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);
            BoltResponseFuture future1 = (BoltResponseFuture) SofaResponseFuture.getFuture();
            String s2 = echoService.echoStr("yyy");
            LOGGER.warn("must null :{}", s2);
            BoltResponseFuture future2 = (BoltResponseFuture) SofaResponseFuture.getFuture();
            s1 = (String) future1.get();
            LOGGER.warn("get future1: {}, elapse: {}", s1, future1.getElapsedTime());
            s2 = (String) future2.get();
            LOGGER.warn("get future2: {}, elapse: {}", s2, future2.getElapsedTime());
        } 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) BoltResponseFuture(com.alipay.sofa.rpc.message.bolt.BoltResponseFuture)

Example 5 with EchoService

use of com.alipay.sofa.rpc.test.EchoService 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)

Aggregations

EchoService (com.alipay.sofa.rpc.test.EchoService)20 HelloService (com.alipay.sofa.rpc.test.HelloService)19 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)11 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)10 EchoServiceImpl (com.alipay.sofa.rpc.test.EchoServiceImpl)10 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)10 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)9 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)7 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2 NamedThreadFactory (com.alipay.sofa.rpc.common.struct.NamedThreadFactory)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1 SwaggerRestService (com.alipay.sofa.rpc.doc.swagger.rest.SwaggerRestService)1 SwaggerRestServiceImpl (com.alipay.sofa.rpc.doc.swagger.rest.SwaggerRestServiceImpl)1 Filter (com.alipay.sofa.rpc.filter.Filter)1 FilterInvoker (com.alipay.sofa.rpc.filter.FilterInvoker)1