use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class TripleHessianInvokeTest method testExposeTwice.
@Test
public void testExposeTwice() {
String uniqueId = "uniqueId";
RpcRunningState.setDebugMode(true);
ApplicationConfig clientApp = new ApplicationConfig().setAppName("triple-client");
ApplicationConfig serverApp = new ApplicationConfig().setAppName("triple-server");
int port = getPort();
ServerConfig serverConfig = new ServerConfig().setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE).setPort(port);
TripleHessianInterfaceImpl ref = new TripleHessianInterfaceImpl();
ProviderConfig<TripleHessianInterface> providerConfig = getProviderConfig().setApplication(serverApp).setUniqueId(uniqueId).setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE).setInterfaceId(TripleHessianInterface.class.getName()).setRef(ref).setServer(serverConfig).setRegister(false);
providerConfig.export();
uniqueId = "uniqueId2";
RpcRunningState.setDebugMode(true);
clientApp = new ApplicationConfig().setAppName("triple-client");
serverApp = new ApplicationConfig().setAppName("triple-server");
port = 50062;
serverConfig = new ServerConfig().setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE).setPort(port);
ref = new TripleHessianInterfaceImpl();
ProviderConfig<TripleHessianInterface> providerConfig2 = getProviderConfig().setApplication(serverApp).setUniqueId(uniqueId).setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE).setInterfaceId(TripleHessianInterface.class.getName()).setRef(ref).setServer(serverConfig).setRegister(false);
providerConfig2.export();
providerConfig2.unExport();
providerConfig.unExport();
serverConfig.destroy();
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class Http2ClientMultipleMain method main.
public static void main(String[] args) {
ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2c").setDirectUrl("h2c://127.0.0.1:12300").setSerialization("protobuf").setTimeout(3000);
final ProtoService protoService = 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 {
EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("12345678").build();
EchoResponse s = protoService.echoObj(request);
cnt.incrementAndGet();
} catch (Throwable 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.config.ApplicationConfig in project sofa-rpc by sofastack.
the class Http2WithSSLClientMain method main.
public static void main(String[] args) {
System.setProperty("ssl", "true");
System.setProperty("io.netty.handler.ssl.noOpenSsl", "false");
String codebase = ReflectUtils.getCodeBase(Http2WithSSLClientMain.class);
System.setProperty(RpcConfigKeys.CERTIFICATE_PATH.getAlias()[0], codebase + "selfSigned.crt");
ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2").setDirectUrl("h2://127.0.0.1:12300").setSerialization("protobuf").setRegister(false).setTimeout(1000);
ProtoService helloService = consumerConfig.refer();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
while (true) {
try {
EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("lee").build();
EchoResponse s = helloService.echoObj(request);
LOGGER.warn("{}", s);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
try {
Thread.sleep(2000);
} catch (Exception e) {
}
}
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class CallbackClientMain method main.
public static void main(String[] args) throws InterruptedException {
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-server");
ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_CALLBACK).setTimeout(5000).setOnReturn(new SofaResponseCallback() {
@Override
public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
LOGGER.info("Interface get result: {}", appResponse);
}
@Override
public void onAppException(Throwable throwable, String methodName, RequestBase request) {
LOGGER.info("Interface get app exception: {}", throwable);
}
@Override
public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
LOGGER.info("Interface get sofa exception: {}", sofaException);
}
}).setDirectUrl("bolt://127.0.0.1:22222?appName=future-server");
HelloService helloService = consumerConfig.refer();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
try {
for (int i = 0; i < 100; i++) {
try {
String s = helloService.sayHello("xxx", 22);
LOGGER.warn("{}", s);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
try {
Thread.sleep(2000);
} catch (Exception e) {
}
}
} catch (Exception e) {
LOGGER.error("", e);
}
synchronized (CallbackClientMain.class) {
while (true) {
CallbackClientMain.class.wait();
}
}
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class BoltServerMain method main.
public static void main(String[] args) {
ApplicationConfig application = new ApplicationConfig().setAppName("test-server");
ServerConfig serverConfig = new ServerConfig().setPort(22000).setDaemon(false);
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setApplication(application).setRef(new HelloServiceImpl()).setServer(serverConfig).setRegister(false);
ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>().setInterfaceId(EchoService.class.getName()).setApplication(application).setRef(new EchoServiceImpl()).setServer(serverConfig).setRegister(false);
providerConfig.export();
providerConfig2.export();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
}
Aggregations