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) {
}
}
}
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
}
}
}
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
}
}
}
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
}
}
}
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();
}
Aggregations