com.baidu.brpc.server.RpcServer Java Examples
The following examples show how to use
com.baidu.brpc.server.RpcServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoadBalanceTest.java From brpc-java with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() { List<Interceptor> interceptors = new ArrayList<Interceptor>(); interceptors.add(new TestInterceptor(1)); rpcServer1 = new RpcServer(8000, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer1.registerService(new TestEchoService(100)); rpcServer1.start(); interceptors = new ArrayList<Interceptor>(); interceptors.add(new TestInterceptor(2)); rpcServer2 = new RpcServer(8001, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer2.registerService(new TestEchoService(200)); rpcServer2.start(); interceptors = new ArrayList<Interceptor>(); interceptors.add(new TestInterceptor(3)); rpcServer3 = new RpcServer(8002, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer3.registerService(new TestEchoService(300)); rpcServer3.start(); }
Example #2
Source File: Server.java From rpc-benchmark with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { int port = 8002; RpcServerOptions options = new RpcServerOptions(); options.setReceiveBufferSize(64 * 1024 * 1024); options.setSendBufferSize(64 * 1024 * 1024); options.setKeepAliveTime(20); options.setProtocolType(Options.ProtocolType.PROTOCOL_HTTP_JSON_VALUE); final RpcServer rpcServer = new RpcServer(port, options); rpcServer.registerService(new UserServiceServerImpl()); rpcServer.start(); System.out.println("START"); Thread.sleep(Long.MAX_VALUE); }
Example #3
Source File: StargateDemoServer.java From brpc-java with Apache License 2.0 | 6 votes |
public static void main(String[] args) { RpcServerOptions serverOptions = new RpcServerOptions(); serverOptions.setProtocolType(Options.ProtocolType.PROTOCOL_STARGATE_VALUE); serverOptions.setNamingServiceUrl(StargateDemoConstant.namingUrl); RpcServer rpcServer = new RpcServer(8898, serverOptions); StargateDemoService demoService = new StargateDemoServiceImpl(); NamingOptions namingOptions = new NamingOptions(); namingOptions.setGroup(StargateDemoConstant.group); namingOptions.setVersion(StargateDemoConstant.version); rpcServer.registerService(demoService, namingOptions); rpcServer.start(); // make server keep running synchronized (StargateDemoServer.class) { try { StargateDemoServer.class.wait(); } catch (Throwable e) { } } }
Example #4
Source File: RpcServerTest.java From brpc-java with Apache License 2.0 | 6 votes |
public static void main(String[] args) { int port = 8002; if (args.length == 1) { port = Integer.valueOf(args[0]); } RpcServerOptions options = new RpcServerOptions(); // options.setAcceptorThreadNum(8); // options.setIoThreadNum(32); // options.setWorkThreadNum(80); options.setReceiveBufferSize(64 * 1024 * 1024); options.setSendBufferSize(64 * 1024 * 1024); 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 } } }
Example #5
Source File: RpcServerTest.java From brpc-java with Apache License 2.0 | 6 votes |
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 } } }
Example #6
Source File: RpcServerTest.java From brpc-java with Apache License 2.0 | 6 votes |
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 } } }
Example #7
Source File: RpcServerTest.java From brpc-java with Apache License 2.0 | 6 votes |
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) { } } }
Example #8
Source File: RpcServerTest.java From brpc-java with Apache License 2.0 | 6 votes |
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 } } }
Example #9
Source File: DubboServer.java From brpc-java with Apache License 2.0 | 6 votes |
public static void main(String[] args) { RpcServerOptions serverOptions = new RpcServerOptions(); serverOptions.setProtocolType(Options.ProtocolType.PROTOCOL_DUBBO_VALUE); serverOptions.setNamingServiceUrl("dubbo://127.0.0.1:2181"); serverOptions.setReceiveBufferSize(64 * 1024 * 1024); serverOptions.setSendBufferSize(64 * 1024 * 1024); serverOptions.setWorkThreadNum(12); RpcServer rpcServer = new RpcServer(8898, serverOptions); EchoService service = new EchoServiceImpl(); NamingOptions namingOptions = new NamingOptions(); namingOptions.setGroup(""); namingOptions.setVersion(""); rpcServer.registerService(service, namingOptions); rpcServer.start(); // make server keep running synchronized (DubboServer.class) { try { DubboServer.class.wait(); } catch (Throwable e) { } } }
Example #10
Source File: RateLimitTest.java From brpc-java with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() { List<Interceptor> interceptors = new ArrayList<Interceptor>(); interceptors.add(new CurrentLimitInterceptor(new TokenBucketRateLimiter(500, 500))); rpcServer1 = new RpcServer(8000, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer1.registerService(new EchoServiceImpl()); interceptors = new ArrayList<Interceptor>(); interceptors.add(new CurrentLimitInterceptor(new CounterRateLimiter(500))); rpcServer2 = new RpcServer(8001, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer2.registerService(new EchoServiceImpl()); rpcServer1.start(); rpcServer2.start(); }
Example #11
Source File: RpcShortConnectionClientTest.java From brpc-java with Apache License 2.0 | 6 votes |
@Test public void testNsheadProto() { RpcServerOptions serverOptions = RpcOptionsUtils.getRpcServerOptions(); serverOptions.setProtocolType(Options.ProtocolType.PROTOCOL_NSHEAD_PROTOBUF_VALUE); RpcServer rpcServer = new RpcServer(8001, serverOptions); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); RpcClientOptions clientOptions = RpcOptionsUtils.getRpcClientOptions(); clientOptions.setProtocolType(Options.ProtocolType.PROTOCOL_NSHEAD_PROTOBUF_VALUE); clientOptions.setLoadBalanceType(LoadBalanceStrategy.LOAD_BALANCE_RANDOM); clientOptions.setChannelType(ChannelType.SHORT_CONNECTION); Endpoint endPoint = new Endpoint("127.0.0.1", 8001); RpcClient rpcClient = new RpcClient(endPoint, clientOptions); EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); Echo.EchoResponse response = echoService.echo(request); assertEquals("hello", response.getMessage()); rpcClient.stop(); rpcServer.shutdown(); }
Example #12
Source File: RpcShortConnectionClientTest.java From brpc-java with Apache License 2.0 | 6 votes |
@Test public void testHttpProto() { RpcServerOptions serverOptions = RpcOptionsUtils.getRpcServerOptions(); serverOptions.setProtocolType(Options.ProtocolType.PROTOCOL_HTTP_PROTOBUF_VALUE); RpcServer rpcServer = new RpcServer(8001, serverOptions); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); RpcClientOptions clientOptions = RpcOptionsUtils.getRpcClientOptions(); clientOptions.setProtocolType(Options.ProtocolType.PROTOCOL_HTTP_PROTOBUF_VALUE); clientOptions.setLoadBalanceType(LoadBalanceStrategy.LOAD_BALANCE_RANDOM); clientOptions.setChannelType(ChannelType.SHORT_CONNECTION); Endpoint endPoint = new Endpoint("127.0.0.1", 8001); RpcClient rpcClient = new RpcClient(endPoint, clientOptions); EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); Echo.EchoResponse response = echoService.echo(request); assertEquals("hello", response.getMessage()); rpcClient.stop(); rpcServer.shutdown(); }
Example #13
Source File: RpcShortConnectionClientTest.java From brpc-java with Apache License 2.0 | 6 votes |
@Test public void testBasic() { RpcServer rpcServer = new RpcServer(8001, RpcOptionsUtils.getRpcServerOptions()); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); Endpoint endPoint = new Endpoint("127.0.0.1", 8001); RpcClientOptions rpcClientOptions = RpcOptionsUtils.getRpcClientOptions(); rpcClientOptions.setLoadBalanceType(LoadBalanceStrategy.LOAD_BALANCE_RANDOM); rpcClientOptions.setChannelType(ChannelType.SHORT_CONNECTION); RpcClient rpcClient = new RpcClient(endPoint, rpcClientOptions); EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); Echo.EchoResponse response = echoService.echo(request); assertEquals("hello", response.getMessage()); rpcClient.stop(); rpcServer.shutdown(); }
Example #14
Source File: RpcLongConnectionClientTest.java From brpc-java with Apache License 2.0 | 6 votes |
@Test public void testNsheadProto() { RpcServerOptions serverOptions = RpcOptionsUtils.getRpcServerOptions(); serverOptions.setProtocolType(Options.ProtocolType.PROTOCOL_NSHEAD_PROTOBUF_VALUE); RpcServer rpcServer = new RpcServer(8000, serverOptions); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); RpcClientOptions clientOptions = RpcOptionsUtils.getRpcClientOptions(); clientOptions.setProtocolType(Options.ProtocolType.PROTOCOL_NSHEAD_PROTOBUF_VALUE); RpcClient rpcClient = new RpcClient("list://127.0.0.1:8000", clientOptions); EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); Echo.EchoResponse response = echoService.echo(request); assertEquals("hello", response.getMessage()); rpcClient.stop(); rpcServer.shutdown(); }
Example #15
Source File: RpcLongConnectionClientTest.java From brpc-java with Apache License 2.0 | 6 votes |
@Test public void testBasic() { RpcServer rpcServer = new RpcServer(8000, RpcOptionsUtils.getRpcServerOptions()); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); RpcClient rpcClient = new RpcClient("list://127.0.0.1:8000", RpcOptionsUtils.getRpcClientOptions()); EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); Echo.EchoResponse response = echoService.echo(request); assertEquals("hello", response.getMessage()); rpcClient.stop(); rpcServer.shutdown(); }
Example #16
Source File: BrpcChannelTest.java From brpc-java with Apache License 2.0 | 5 votes |
@Before public void before() { rpcServer = new RpcServer(8000, RpcOptionsUtils.getRpcServerOptions()); rpcServer.start(); options = RpcOptionsUtils.getRpcClientOptions(); options.setLatencyWindowSizeOfFairLoadBalance(2); rpcClient = new RpcClient("list://127.0.0.1:8000", options); ServiceInstance serviceInstance = new ServiceInstance("127.0.0.1", 8000); serviceInstance.setServiceName("EchoService2"); channelGroup = new BrpcPooledChannel(serviceInstance, RpcOptionsUtils.getCommunicationOptions()); }
Example #17
Source File: RandomStrategyTest.java From brpc-java with Apache License 2.0 | 5 votes |
@Before public void before() { List<Interceptor> interceptors = new ArrayList<Interceptor>(); interceptors.add(new LoadBalanceTest.TestInterceptor(1)); rpcServer1 = new RpcServer(8000, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer1.registerService(new LoadBalanceTest.TestEchoService(100)); rpcServer1.start(); interceptors = new ArrayList<Interceptor>(); interceptors.add(new LoadBalanceTest.TestInterceptor(2)); rpcServer2 = new RpcServer(8001, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer2.registerService(new LoadBalanceTest.TestEchoService(200)); rpcServer2.start(); interceptors = new ArrayList<Interceptor>(); interceptors.add(new LoadBalanceTest.TestInterceptor(3)); rpcServer3 = new RpcServer(8002, RpcOptionsUtils.getRpcServerOptions(), interceptors); rpcServer3.registerService(new LoadBalanceTest.TestEchoService(300)); rpcServer3.start(); ServiceInstance serviceInstance1 = new ServiceInstance("127.0.0.1", 8000); serviceInstance1.setServiceName("EchoService"); instance1 = new CommunicationClient(serviceInstance1, RpcOptionsUtils.getCommunicationOptions(), null); ServiceInstance serviceInstance2 = new ServiceInstance("127.0.0.1", 8001); serviceInstance2.setServiceName("EchoService"); instance2 = new CommunicationClient(serviceInstance2, RpcOptionsUtils.getCommunicationOptions(), null); ServiceInstance serviceInstance3 = new ServiceInstance("127.0.0.1", 8002); serviceInstance3.setServiceName("EchoService"); instance3 = new CommunicationClient(serviceInstance3, RpcOptionsUtils.getCommunicationOptions(), null); }
Example #18
Source File: ServerPushTest.java From brpc-java with Apache License 2.0 | 5 votes |
@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(); }
Example #19
Source File: BaiduBrpcApplication.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void afterPropertiesSet() throws Exception { int port = 1118; RpcServerOptions options = new RpcServerOptions(); options.setReceiveBufferSize(64 * 1024 * 1024); options.setSendBufferSize(64 * 1024 * 1024); options.setKeepAliveTime(20); final RpcServer rpcServer = new RpcServer(port, options); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); }
Example #20
Source File: GlobalThreadPoolSharingTest.java From brpc-java with Apache License 2.0 | 4 votes |
@Test @Ignore public void testShareGlobalThreadPool() { RpcServerOptions rpcServerOptions = RpcOptionsUtils.getRpcServerOptions(); rpcServerOptions.setProtocolType(Options.ProtocolType.PROTOCOL_SERVER_PUSH_VALUE); rpcServerOptions.setGlobalThreadPoolSharing(true); RpcServer rpcServer1 = new RpcServer(8000, rpcServerOptions); rpcServer1.registerService(new EchoServiceImpl()); rpcServer1.start(); RpcServer rpcServer2 = new RpcServer(8001, rpcServerOptions); rpcServer2.registerService(new EchoServiceImpl()); rpcServer2.start(); Assert.assertTrue(rpcServer1.getBossGroup() == rpcServer2.getBossGroup()); Assert.assertTrue(rpcServer1.getWorkerGroup() == rpcServer2.getWorkerGroup()); Assert.assertTrue(rpcServer1.getThreadPool() == rpcServer2.getThreadPool()); RpcClientOptions rpcClientOptions = RpcOptionsUtils.getRpcClientOptions(); rpcClientOptions.setProtocolType(Options.ProtocolType.PROTOCOL_SERVER_PUSH_VALUE); rpcClientOptions.setClientName("c1"); rpcClientOptions.setGlobalThreadPoolSharing(true); RpcClient rpcClient1 = new RpcClient("list://127.0.0.1:8000", rpcClientOptions); EchoService echoService1 = BrpcProxy.getProxy(rpcClient1, EchoService.class); rpcClient1.registerPushService(new UserPushApiImpl()); RpcClient rpcClient2 = new RpcClient("list://127.0.0.1:8001", rpcClientOptions); EchoService echoService2 = BrpcProxy.getProxy(rpcClient2, EchoService.class); rpcClient2.registerPushService(new UserPushApiImpl()); RpcClient rpcClient3 = new RpcClient("list://127.0.0.1:8001", rpcClientOptions); EchoService echoService3 = BrpcProxy.getProxy(rpcClient3, EchoService.class); rpcClient3.registerPushService(new UserPushApiImpl()); BrpcThreadPoolManager threadPoolManager = BrpcThreadPoolManager.getInstance(); Assert.assertTrue(threadPoolManager.getIoThreadPoolMap().size() == 1); Assert.assertTrue(threadPoolManager.getWorkThreadPoolMap().size() == 1); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); for (int i = 0; i < 1000; i++) { Echo.EchoResponse response = echoService1.echo(request); Echo.EchoResponse response2 = echoService2.echo(request); Echo.EchoResponse response3 = echoService3.echo(request); assertEquals("hello", response.getMessage()); assertEquals("hello", response2.getMessage()); assertEquals("hello", response3.getMessage()); } // test shutndown and stop rpcClient1.stop(); rpcClient2.stop(); rpcClient3.stop(); rpcServer1.shutdown(); rpcServer2.shutdown(); // client Assert.assertTrue(threadPoolManager.getIoThreadPoolMap().size() == 1); Assert.assertTrue(threadPoolManager.getWorkThreadPoolMap().size() == 1); // server EventLoopGroup r1BossGroup = rpcServer1.getBossGroup(); EventLoopGroup r1WorkerGroup = rpcServer1.getWorkerGroup(); ThreadPool r1ThreadPool = rpcServer1.getThreadPool(); Assert.assertFalse(r1BossGroup.isShutdown()); Assert.assertFalse(r1WorkerGroup.isShutdown()); Assert.assertFalse(r1ThreadPool.isStopped()); ShutDownManager.shutdownGlobalThreadPools(); try { Thread.sleep(5 * 1000L); } catch (InterruptedException e) { // do nothing } Assert.assertTrue(threadPoolManager.getIoThreadPoolMap().size() == 0); Assert.assertTrue(threadPoolManager.getWorkThreadPoolMap().size() == 0); Assert.assertTrue(r1BossGroup.isShutdown()); Assert.assertTrue(r1WorkerGroup.isShutdown()); Assert.assertTrue(r1ThreadPool.isStopped()); }
Example #21
Source File: ClientInitTest.java From brpc-java with Apache License 2.0 | 4 votes |
@Test @Ignore public void testClientInit() { RpcServer rpcServer = new RpcServer(8000, RpcOptionsUtils.getRpcServerOptions()); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); // new first rpc client long firstStartTime = System.currentTimeMillis(); RpcClient firstRpcClient = new RpcClient("list://127.0.0.1:8000", RpcOptionsUtils.getRpcClientOptions()); long firstEndTime = System.currentTimeMillis(); EchoService echoService = BrpcProxy.getProxy(firstRpcClient, EchoService.class); Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); Echo.EchoResponse response = echoService.echo(request); assertEquals("hello", response.getMessage()); log.info("first new rpcClient cost : {}", firstEndTime - firstStartTime); // new second rpc client long secondStartTime = System.currentTimeMillis(); RpcClient secondRpcClient = new RpcClient("list://127.0.0.1:8000", RpcOptionsUtils.getRpcClientOptions()); long secondEndTime = System.currentTimeMillis(); log.info("second new rpcClient cost : {}", secondEndTime - secondStartTime); echoService = BrpcProxy.getProxy(secondRpcClient, EchoService.class); request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); response = echoService.echo(request); assertEquals("hello", response.getMessage()); // new third rpc client for short connection Endpoint endPoint = new Endpoint("127.0.0.1", 8000); long thirdStartTime = System.currentTimeMillis(); RpcClient thirdConnectionRpcClient = new RpcClient(endPoint, RpcOptionsUtils.getRpcClientOptions()); long thirdEndTime = System.currentTimeMillis(); log.info("third new rpcClient cost : {}", thirdEndTime - thirdStartTime); ThreadNumStat stat = calThreadNum(); Assert.assertEquals(1, stat.workThreadNum); Assert.assertEquals(1, stat.timoutThreadNum); firstRpcClient.stop(); secondRpcClient.stop(); thirdConnectionRpcClient.stop(); rpcServer.shutdown(); }
Example #22
Source File: RpcLongConnectionClientTest.java From brpc-java with Apache License 2.0 | 4 votes |
@Test public void testHttpProto() { RpcServerOptions serverOptions = RpcOptionsUtils.getRpcServerOptions(); serverOptions.setProtocolType(Options.ProtocolType.PROTOCOL_HTTP_PROTOBUF_VALUE); RpcServer rpcServer = new RpcServer(8000, serverOptions); rpcServer.registerService(new EchoServiceImpl()); rpcServer.start(); RpcClientOptions clientOptions = RpcOptionsUtils.getRpcClientOptions(); clientOptions.setProtocolType(Options.ProtocolType.PROTOCOL_HTTP_PROTOBUF_VALUE); clientOptions.setMaxTryTimes(1); clientOptions.setReadTimeoutMillis(1000000); clientOptions.setWriteTimeoutMillis(1000000); RpcClient rpcClient = new RpcClient("list://127.0.0.1:8000", clientOptions); EchoService echoService = BrpcProxy.getProxy(rpcClient, EchoService.class); // test big message String message = "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" + "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello"; Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage(message).build(); Echo.EchoResponse response = echoService.echo(request); assertEquals(message, response.getMessage()); // test small message message = "hello"; request = Echo.EchoRequest.newBuilder().setMessage(message).build(); response = echoService.echo(request); assertEquals(message, response.getMessage()); rpcClient.stop(); rpcServer.shutdown(); }