use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class FutureServerMain method main.
public static void main(String[] args) {
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-server");
ServerConfig serverConfig2 = new ServerConfig().setPort(22222).setDaemon(false);
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(1000)).setServer(serverConfig2);
providerConfig.export();
ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setRef(new EchoServiceImpl()).setServer(serverConfig2);
providerConfig2.export();
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class OnewayClientMain method main.
public static void main(String[] args) throws InterruptedException {
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("oneway-client");
ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=oneway-server");
HelloService helloService = consumerConfig.refer();
ConsumerConfig<EchoService> consumerConfig2 = new ConsumerConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=oneway-server");
EchoService echoService = consumerConfig2.refer();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
while (true) {
try {
String s1 = helloService.sayHello("xxx", 22);
LOGGER.warn("must null :{}", s1);
String s2 = echoService.echoStr("yyy");
LOGGER.warn("must null :{}", s2);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
try {
Thread.sleep(2000);
} catch (Exception ignore) {
}
}
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class OnewayServerMain method main.
public static void main(String[] args) {
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("oneway-server");
ServerConfig serverConfig2 = new ServerConfig().setPort(22222).setDaemon(false);
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setApplication(applicationConfig).setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(1000)).setServer(serverConfig2);
providerConfig.export();
ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>().setApplication(applicationConfig).setInterfaceId(EchoService.class.getName()).setRef(new EchoServiceImpl()).setServer(serverConfig2);
providerConfig2.export();
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class CheckBoltClientMain method main.
public static void main(String[] args) throws InterruptedException {
ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setApplication(application).setInterfaceId(HelloService.class.getName()).setDirectUrl("bolt://127.0.0.1:22100").setRegister(false).setLazy(true).setCheck(true).setTimeout(3000);
HelloService helloService = consumerConfig.refer();
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
try {
Thread.sleep(5000);
} catch (Exception e) {
}
while (true) {
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) {
}
}
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class ZookeeperRegistryTest method testProviderObserver.
/**
* 测试Zookeeper Provider Observer
*
* @throws Exception
*/
@Test
public void testProviderObserver() throws Exception {
int timeoutPerSub = 2000;
ServerConfig serverConfig = new ServerConfig().setProtocol("bolt").setHost("0.0.0.0").setPort(12200);
ProviderConfig<?> provider = new ProviderConfig();
provider.setInterfaceId(TEST_SERVICE_NAME).setUniqueId("unique123Id").setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setRegister(true).setRegistry(registryConfig).setSerialization("hessian2").setServer(serverConfig).setWeight(222).setTimeout(3000);
// 注册
registry.register(provider);
ConsumerConfig<?> consumer = new ConsumerConfig();
consumer.setInterfaceId(TEST_SERVICE_NAME).setUniqueId("unique123Id").setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setSubscribe(true).setSerialization("java").setInvokeType("sync").setTimeout(4444);
// 订阅
CountDownLatch latch = new CountDownLatch(1);
MockProviderInfoListener providerInfoListener = new MockProviderInfoListener();
providerInfoListener.setCountDownLatch(latch);
consumer.setProviderInfoListener(providerInfoListener);
List<ProviderGroup> all = registry.subscribe(consumer);
providerInfoListener.updateAllProviders(all);
Map<String, ProviderInfo> ps = providerInfoListener.getData();
Assert.assertEquals("after register: 1", 1, ps.size());
// 订阅 错误的uniqueId
ConsumerConfig<?> consumerNoUniqueId = new ConsumerConfig();
consumerNoUniqueId.setInterfaceId(TEST_SERVICE_NAME).setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setSubscribe(true).setSerialization("java").setInvokeType("sync").setTimeout(4444);
latch = new CountDownLatch(1);
MockProviderInfoListener providerInfoListener3 = new MockProviderInfoListener();
providerInfoListener3.setCountDownLatch(latch);
consumerNoUniqueId.setProviderInfoListener(providerInfoListener3);
all = registry.subscribe(consumerNoUniqueId);
providerInfoListener3.updateAllProviders(all);
Map<String, ProviderInfo> ps3 = providerInfoListener3.getData();
Assert.assertEquals("wrong uniqueId: 0", 0, ps3.size());
// 反注册
latch = new CountDownLatch(1);
providerInfoListener.setCountDownLatch(latch);
registry.unRegister(provider);
latch.await(timeoutPerSub, TimeUnit.MILLISECONDS);
Assert.assertEquals("after unregister: 0", 0, ps.size());
// 一次发2个端口的再次注册
latch = new CountDownLatch(2);
providerInfoListener.setCountDownLatch(latch);
provider.getServer().add(new ServerConfig().setProtocol("bolt").setHost("0.0.0.0").setPort(12201));
registry.register(provider);
latch.await(timeoutPerSub * 2, TimeUnit.MILLISECONDS);
Assert.assertEquals("after register two servers: 2", 2, ps.size());
// 重复订阅
ConsumerConfig<?> consumer2 = new ConsumerConfig();
consumer2.setInterfaceId(TEST_SERVICE_NAME).setUniqueId("unique123Id").setApplication(new ApplicationConfig().setAppName("test-server")).setProxy("javassist").setSubscribe(true).setSerialization("java").setInvokeType("sync").setTimeout(4444);
CountDownLatch latch2 = new CountDownLatch(1);
MockProviderInfoListener providerInfoListener2 = new MockProviderInfoListener();
providerInfoListener2.setCountDownLatch(latch2);
consumer2.setProviderInfoListener(providerInfoListener2);
providerInfoListener2.updateAllProviders(registry.subscribe(consumer2));
latch2.await(timeoutPerSub, TimeUnit.MILLISECONDS);
Map<String, ProviderInfo> ps2 = providerInfoListener2.getData();
Assert.assertEquals("after register duplicate: 2", 2, ps2.size());
// 取消订阅者1
registry.unSubscribe(consumer);
// 批量反注册,判断订阅者2的数据
latch = new CountDownLatch(2);
providerInfoListener2.setCountDownLatch(latch);
List<ProviderConfig> providerConfigList = new ArrayList<ProviderConfig>();
providerConfigList.add(provider);
registry.batchUnRegister(providerConfigList);
latch.await(timeoutPerSub * 2, TimeUnit.MILLISECONDS);
Assert.assertEquals("after unregister: 0", 0, ps2.size());
// 批量取消订阅
List<ConsumerConfig> consumerConfigList = new ArrayList<ConsumerConfig>();
consumerConfigList.add(consumer2);
registry.batchUnSubscribe(consumerConfigList);
}
Aggregations