Search in sources :

Example 16 with ApplicationConfig

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

the class TripleHessianInvokeTest method testExposeTwice.

@Test
public void testExposeTwice() {
    String uniqueId = "uniqueId";
    RpcRunningState.setDebugMode(true);
    ApplicationConfig clientApp = new ApplicationConfig().setAppName("triple-client");
    ApplicationConfig serverApp = new ApplicationConfig().setAppName("triple-server");
    int port = getPort();
    ServerConfig serverConfig = new ServerConfig().setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE).setPort(port);
    TripleHessianInterfaceImpl ref = new TripleHessianInterfaceImpl();
    ProviderConfig<TripleHessianInterface> providerConfig = getProviderConfig().setApplication(serverApp).setUniqueId(uniqueId).setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE).setInterfaceId(TripleHessianInterface.class.getName()).setRef(ref).setServer(serverConfig).setRegister(false);
    providerConfig.export();
    uniqueId = "uniqueId2";
    RpcRunningState.setDebugMode(true);
    clientApp = new ApplicationConfig().setAppName("triple-client");
    serverApp = new ApplicationConfig().setAppName("triple-server");
    port = 50062;
    serverConfig = new ServerConfig().setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE).setPort(port);
    ref = new TripleHessianInterfaceImpl();
    ProviderConfig<TripleHessianInterface> providerConfig2 = getProviderConfig().setApplication(serverApp).setUniqueId(uniqueId).setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE).setInterfaceId(TripleHessianInterface.class.getName()).setRef(ref).setServer(serverConfig).setRegister(false);
    providerConfig2.export();
    providerConfig2.unExport();
    providerConfig.unExport();
    serverConfig.destroy();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) Test(org.junit.Test)

Example 17 with ApplicationConfig

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

the class Http2ClientMultipleMain method main.

public static void main(String[] args) {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2c").setDirectUrl("h2c://127.0.0.1:12300").setSerialization("protobuf").setTimeout(3000);
    final ProtoService protoService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    final int threads = 50;
    final AtomicLong cnt = new AtomicLong(0);
    final ThreadPoolExecutor service1 = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), // 无队列
    new NamedThreadFactory("client-"));
    for (int i = 0; i < threads; i++) {
        service1.execute(new Runnable() {

            @Override
            public void run() {
                while (true) {
                    try {
                        EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("12345678").build();
                        EchoResponse s = protoService.echoObj(request);
                        cnt.incrementAndGet();
                    } catch (Throwable e) {
                        LOGGER.error("", e);
                    }
                }
            }
        });
    }
    Thread thread = new Thread(new Runnable() {

        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 1s invoke: {}, queue: {}", tps, service1.getQueue().size());
                last = count;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : EchoResponse(com.alipay.sofa.rpc.protobuf.EchoResponse) NamedThreadFactory(com.alipay.sofa.rpc.common.struct.NamedThreadFactory) EchoRequest(com.alipay.sofa.rpc.protobuf.EchoRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 18 with ApplicationConfig

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

the class Http2WithSSLClientMain method main.

public static void main(String[] args) {
    System.setProperty("ssl", "true");
    System.setProperty("io.netty.handler.ssl.noOpenSsl", "false");
    String codebase = ReflectUtils.getCodeBase(Http2WithSSLClientMain.class);
    System.setProperty(RpcConfigKeys.CERTIFICATE_PATH.getAlias()[0], codebase + "selfSigned.crt");
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2").setDirectUrl("h2://127.0.0.1:12300").setSerialization("protobuf").setRegister(false).setTimeout(1000);
    ProtoService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    while (true) {
        try {
            EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("lee").build();
            EchoResponse s = helloService.echoObj(request);
            LOGGER.warn("{}", s);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
    }
}
Also used : EchoResponse(com.alipay.sofa.rpc.protobuf.EchoResponse) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) EchoRequest(com.alipay.sofa.rpc.protobuf.EchoRequest) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService)

Example 19 with ApplicationConfig

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

the class CallbackClientMain method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-server");
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_CALLBACK).setTimeout(5000).setOnReturn(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
            LOGGER.info("Interface get result: {}", appResponse);
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
            LOGGER.info("Interface get app exception: {}", throwable);
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
            LOGGER.info("Interface get sofa exception: {}", sofaException);
        }
    }).setDirectUrl("bolt://127.0.0.1:22222?appName=future-server");
    HelloService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    try {
        for (int i = 0; i < 100; i++) {
            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) {
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    synchronized (CallbackClientMain.class) {
        while (true) {
            CallbackClientMain.class.wait();
        }
    }
}
Also used : HelloService(com.alipay.sofa.rpc.test.HelloService) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 20 with ApplicationConfig

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

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