use of com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService in project Sentinel by alibaba.
the class DemoConsumer method main.
public static void main(String[] args) throws Exception {
ApplicationConfig application = new ApplicationConfig().setAppName("DemoConsumer");
ConsumerConfig<DemoService> consumerConfig = new ConsumerConfig<DemoService>().setApplication(application).setInterfaceId(DemoService.class.getName()).setProtocol("bolt").setDirectUrl("bolt://127.0.0.1:12001").setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
// 设置是否启用Sentinel,默认启用
// 也可在rpc-config.json全局设置
// consumerConfig.setParameter("sofa.rpc.sentinel.enabled", "false");
DemoService helloService = consumerConfig.refer();
System.out.println("DemoConsumer started!");
long sleepMs = 5;
int total = 5000;
int index = 0;
System.out.println("Total call " + total + " times and sleep " + sleepMs + "ms after each call.");
while (true) {
try {
index++;
String result = helloService.sayHello(index, "SOFARPC", 2020);
System.out.println("[" + index + "][Consumer]receive response: " + result);
} catch (Exception e) {
System.out.println("[" + index + "][Consumer]receive exception: " + e.getMessage());
}
TimeUnit.MILLISECONDS.sleep(sleepMs);
if (index == total) {
break;
}
}
System.out.println("DemoConsumer exit!");
System.exit(0);
}
use of com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService in project Sentinel by alibaba.
the class DemoProvider method main.
public static void main(String[] args) {
ServerConfig serverConfig = new ServerConfig().setProtocol("bolt").setPort(12001).setDaemon(false);
ProviderConfig<DemoService> providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setServer(serverConfig);
// 设置是否启用Sentinel,默认启用
// 也可在rpc-config.json全局设置
// providerConfig.setParameter("sofa.rpc.sentinel.enabled", "false");
providerConfig.export();
System.out.println("DemoProvider started!");
}
Aggregations