use of com.alipay.sofa.rpc.rest.RestService in project sofa-rpc by sofastack.
the class RestClientMultipleMain method main.
public static void main(String[] args) {
ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
ConsumerConfig<RestService> consumerConfig = new ConsumerConfig<RestService>().setApplication(application).setInterfaceId(RestService.class.getName()).setProtocol("rest").setBootstrap("rest").setDirectUrl("rest://127.0.0.1:8888").setTimeout(3000);
final RestService helloService = 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 {
String s = helloService.get("1234567890");
cnt.incrementAndGet();
} catch (Exception 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();
}
use of com.alipay.sofa.rpc.rest.RestService in project sofa-rpc by sofastack.
the class RestClientMain method main.
public static void main(String[] args) throws InterruptedException {
ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
ConsumerConfig<RestService> consumerConfig = new ConsumerConfig<RestService>().setApplication(application).setInterfaceId(RestService.class.getName()).setProtocol("rest").setBootstrap("rest").setDirectUrl("rest://127.0.0.1:8888").setTimeout(3000);
RestService helloService = consumerConfig.refer();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
while (true) {
try {
String s = helloService.add(22, "xxx");
LOGGER.warn("add {}", s);
s = helloService.query(22);
LOGGER.warn("get {}", s);
List<ExampleObj> es = new ArrayList<ExampleObj>();
es.add(new ExampleObj().setName("xxx").setId(1));
es.add(new ExampleObj().setName("yyy").setId(2));
List<ExampleObj> rs = helloService.objects(es);
LOGGER.warn("rs {}", rs.size());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
try {
Thread.sleep(2000);
} catch (Exception e) {
}
}
}
use of com.alipay.sofa.rpc.rest.RestService in project sofa-rpc by sofastack.
the class RestServerMain method main.
public static void main(String[] args) {
ApplicationConfig application = new ApplicationConfig().setAppName("test-server");
/*
访问地址:
POST http://127.0.0.1:8888/rest/hello/code/name
GET http://127.0.0.1:8888/rest/hello/code
PUT http://127.0.0.1:8888/rest/hello/code/name
DELETE http://127.0.0.1:8888/rest/hello/code
GET http://127.0.0.1:8888/rest/get/1234567890
POST http://127.0.0.1:8888/rest/post/1234567890 bodydddddd
*/
ServerConfig serverConfig = new ServerConfig().setProtocol("rest").setPort(8888).setDaemon(false);
ProviderConfig<RestService> providerConfig = new ProviderConfig<RestService>().setInterfaceId(RestService.class.getName()).setApplication(application).setRef(new RestServiceImpl()).setBootstrap("rest").setServer(serverConfig).setRegister(false);
providerConfig.export();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
}
Aggregations