Search in sources :

Example 1 with RpcServer

use of com.baidu.brpc.server.RpcServer in project brpc-java by baidu.

the class RpcServerTest method main.

public static void main(String[] args) {
    int port = 8002;
    if (args.length == 1) {
        port = Integer.valueOf(args[0]);
    }
    RpcServerOptions options = new RpcServerOptions();
    options.setReceiveBufferSize(64 * 1024 * 1024);
    options.setSendBufferSize(64 * 1024 * 1024);
    options.setKeepAliveTime(20);
    // options.setNamingServiceUrl("consul://127.0.0.1:8500");
    // final RpcServer rpcServer = new RpcServer(port, options);
    final RpcServer rpcServer = new RpcServer(port, options);
    rpcServer.registerService(new EchoServiceImpl());
    rpcServer.start();
    // make server keep running
    synchronized (RpcServerTest.class) {
        try {
            RpcServerTest.class.wait();
        } catch (Throwable e) {
        }
    }
}
Also used : RpcServerOptions(com.baidu.brpc.server.RpcServerOptions) RpcServer(com.baidu.brpc.server.RpcServer)

Example 2 with RpcServer

use of com.baidu.brpc.server.RpcServer in project brpc-java by baidu.

the class RpcServerTest method main.

public static void main(String[] args) {
    int port = 8080;
    if (args.length == 1) {
        port = Integer.valueOf(args[0]);
    }
    RpcServerOptions options = new RpcServerOptions();
    options.setProtocolType(Options.ProtocolType.PROTOCOL_NSHEAD_PROTOBUF_VALUE);
    // options.setProtocolType(Options.ProtocolType.PROTOCOL_NSHEAD_JSON_VALUE);
    options.setEncoding("gbk");
    RpcServer rpcServer = new RpcServer(port, options);
    rpcServer.registerService(new EchoServiceImpl());
    rpcServer.start();
    // make server keep running
    synchronized (RpcServerTest.class) {
        try {
            RpcServerTest.class.wait();
        } catch (Throwable e) {
        // ignore
        }
    }
}
Also used : RpcServerOptions(com.baidu.brpc.server.RpcServerOptions) RpcServer(com.baidu.brpc.server.RpcServer) EchoServiceImpl(com.baidu.brpc.example.standard.EchoServiceImpl)

Example 3 with RpcServer

use of com.baidu.brpc.server.RpcServer in project brpc-java by baidu.

the class RpcServerTest method main.

public static void main(String[] args) {
    int port = 8080;
    if (args.length == 1) {
        port = Integer.valueOf(args[0]);
    }
    RpcServerOptions options = new RpcServerOptions();
    RpcServer rpcServer = new RpcServer(port, options);
    // rpcServer.registerService(new EchoServiceImpl());
    rpcServer.registerService(new EchoServiceImpl(), options);
    rpcServer.start();
    // make server keep running
    synchronized (RpcServerTest.class) {
        try {
            RpcServerTest.class.wait();
        } catch (Throwable e) {
        // ignore
        }
    }
}
Also used : RpcServerOptions(com.baidu.brpc.server.RpcServerOptions) RpcServer(com.baidu.brpc.server.RpcServer)

Example 4 with RpcServer

use of com.baidu.brpc.server.RpcServer in project brpc-java by baidu.

the class RpcServerTest method main.

public static void main(String[] args) {
    int port = 8080;
    if (args.length == 1) {
        port = Integer.valueOf(args[0]);
    }
    RpcServerOptions options = new RpcServerOptions();
    RpcServer rpcServer = new RpcServer(port, options);
    rpcServer.registerService(new EchoServiceImpl());
    rpcServer.start();
    // make server keep running
    synchronized (RpcServerTest.class) {
        try {
            RpcServerTest.class.wait();
        } catch (Throwable e) {
        // ignore
        }
    }
}
Also used : RpcServerOptions(com.baidu.brpc.server.RpcServerOptions) RpcServer(com.baidu.brpc.server.RpcServer) EchoServiceImpl(com.baidu.brpc.example.standard.EchoServiceImpl)

Example 5 with RpcServer

use of com.baidu.brpc.server.RpcServer in project brpc-java by baidu.

the class ServerPushTest method testBasic.

@Test
public void testBasic() {
    RpcServerOptions rpcServerOptions = RpcOptionsUtils.getRpcServerOptions();
    rpcServerOptions.setProtocolType(Options.ProtocolType.PROTOCOL_SERVER_PUSH_VALUE);
    RpcServer rpcServer = new RpcServer(8000, rpcServerOptions);
    rpcServer.registerService(new EchoServiceImpl());
    rpcServer.start();
    RpcClientOptions rpcClientOptions = RpcOptionsUtils.getRpcClientOptions();
    rpcClientOptions.setProtocolType(Options.ProtocolType.PROTOCOL_SERVER_PUSH_VALUE);
    rpcClientOptions.setClientName("c1");
    RpcClient rpcClient = new RpcClient("list://127.0.0.1:8000", rpcClientOptions);
    EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class);
    rpcClient.registerPushService(new UserPushApiImpl());
    Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build();
    Echo.EchoResponse response = echoService.echo(request);
    assertEquals("hello", response.getMessage());
    ServerSideUserPushApi pushApi = (ServerSideUserPushApi) BrpcPushProxy.getProxy(rpcServer, ServerSideUserPushApi.class);
    PushData p = new PushData();
    p.setData("abc");
    PushResult pushResult = pushApi.clientReceive("c1", p);
    assertEquals("got data:abc", pushResult.getResult());
    rpcClient.stop();
    rpcServer.shutdown();
}
Also used : RpcClientOptions(com.baidu.brpc.client.RpcClientOptions) ServerSideUserPushApi(com.baidu.brpc.push.userservice.ServerSideUserPushApi) Echo(com.baidu.brpc.protocol.standard.Echo) EchoService(com.baidu.brpc.protocol.standard.EchoService) PushData(com.baidu.brpc.push.userservice.PushData) PushResult(com.baidu.brpc.push.userservice.PushResult) EchoServiceImpl(com.baidu.brpc.protocol.standard.EchoServiceImpl) RpcServerOptions(com.baidu.brpc.server.RpcServerOptions) RpcServer(com.baidu.brpc.server.RpcServer) UserPushApiImpl(com.baidu.brpc.push.userservice.UserPushApiImpl) RpcClient(com.baidu.brpc.client.RpcClient) Test(org.junit.Test)

Aggregations

RpcServer (com.baidu.brpc.server.RpcServer)27 RpcServerOptions (com.baidu.brpc.server.RpcServerOptions)19 EchoServiceImpl (com.baidu.brpc.protocol.standard.EchoServiceImpl)11 Echo (com.baidu.brpc.protocol.standard.Echo)9 EchoService (com.baidu.brpc.protocol.standard.EchoService)9 Test (org.junit.Test)9 Endpoint (com.baidu.brpc.client.channel.Endpoint)4 ArrayList (java.util.ArrayList)4 Interceptor (com.baidu.brpc.interceptor.Interceptor)3 NamingOptions (com.baidu.brpc.protocol.NamingOptions)3 BeforeClass (org.junit.BeforeClass)3 RpcClient (com.baidu.brpc.client.RpcClient)2 RpcClientOptions (com.baidu.brpc.client.RpcClientOptions)2 ServiceInstance (com.baidu.brpc.client.channel.ServiceInstance)2 EchoServiceImpl (com.baidu.brpc.example.push.normal.EchoServiceImpl)2 ServerSideUserPushApi (com.baidu.brpc.example.push.push.ServerSideUserPushApi)2 EchoServiceImpl (com.baidu.brpc.example.standard.EchoServiceImpl)2 UserPushApiImpl (com.baidu.brpc.push.userservice.UserPushApiImpl)2 Ignore (org.junit.Ignore)2 CommunicationClient (com.baidu.brpc.client.CommunicationClient)1