use of rpc.turbo.server.TurboServer in project turbo-rpc by hank-whu.
the class RpcServerBenchmark method main.
public static void main(String[] args) throws Exception {
ResourceLeakDetector.setLevel(Level.DISABLED);
try (TurboServer server = new TurboServer("shop", "auth")) {
Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
server.registerService(services);
/*
* server.addFirst(new RpcServerFilter() {
*
* @Override public void onSend(Request request, Response response) { try {
* Tracer tracer = request.getTracer();
*
* if (tracer != null) { response.setTracer(tracer); }
*
* } catch (Exception e) { e.printStackTrace(); } }
*
* @Override public boolean onRecive(Request request) { try { Tracer tracer =
* request.getTracer();
*
* if (tracer != null) { RemoteContext.getClientAddress().toString();
* RemoteContext.getServerAddress().toString();
* RemoteContext.getServiceMethodName();
*
* TracerContext.setTracer(tracer); } } catch (Exception e) {
* e.printStackTrace(); }
*
* return true; }
*
* @Override public void onError(Request request, Response response, Throwable
* throwable) { } });
*/
server.startRpcServer(new HostPort("127.0.0.1", 8080));
server.waitUntilShutdown();
}
}
use of rpc.turbo.server.TurboServer in project turbo-rpc by hank-whu.
the class TurboServerStarter method startTuroboServer.
@PostConstruct
public void startTuroboServer() {
ServerConfig serverConfig;
try {
serverConfig = ServerConfig.parse("turbo-server.conf");
} catch (com.typesafe.config.ConfigException configException) {
if (logger.isErrorEnabled()) {
logger.error("turbo-server.conf 格式错误,无法开启TurboServer!", configException);
}
return;
} catch (Throwable e) {
if (logger.isErrorEnabled()) {
logger.error("类路径中找不到 turbo-server.conf,无法开启TurboServer!", e);
}
return;
}
@SuppressWarnings("rawtypes") Collection<Tuple3<TurboService, Class, Object>> turboServiceList = getTurboServiceList();
if (turboServiceList.isEmpty()) {
if (logger.isErrorEnabled()) {
logger.error("找不到有效的 TurboService,无法开启TurboServer!");
}
return;
}
ServerInvokerFactory invokerFactory = new ServerInvokerFactory(serverConfig.getGroup(), serverConfig.getApp());
turboServiceList.forEach(t3 -> {
invokerFactory.register(t3._2, t3._3);
});
try {
turboServer = new TurboServer(serverConfig, invokerFactory);
turboServer.startAndRegisterServer();
//
Map<String, TurboServerAware> turboServerAwareMap = applicationContext.getBeansOfType(TurboServerAware.class);
turboServerAwareMap.forEach((key, value) -> value.setTurboServer(turboServer));
} catch (Throwable e) {
if (logger.isErrorEnabled()) {
logger.error("TurboServer启动失败!", e);
}
}
}
use of rpc.turbo.server.TurboServer in project turbo-rpc by hank-whu.
the class RestServerBenchmark method main.
public static void main(String[] args) throws Exception {
ResourceLeakDetector.setLevel(Level.DISABLED);
try (TurboServer server = new TurboServer("shop", "auth")) {
Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
server.registerService(services);
server.startRestServer(new HostPort("0.0.0.0", 8080));
server.waitUntilShutdown();
}
}
Aggregations