use of com.weibo.api.motan.proxy.CommonHandler in project motan by weibocom.
the class Motan2RpcClient method motan2ApiCommonClientDemo.
public static void motan2ApiCommonClientDemo() throws Throwable {
RefererConfig<CommonHandler> referer = new RefererConfig<>();
// 设置服务端接口
referer.setInterface(CommonHandler.class);
referer.setServiceInterface("com.weibo.motan.demo.service.MotanDemoService");
// 配置服务的group以及版本号
referer.setGroup("motan-demo-rpc");
referer.setVersion("1.0");
referer.setRequestTimeout(1000);
// 配置注册中心直连调用
RegistryConfig registry = new RegistryConfig();
registry.setRegProtocol("direct");
registry.setAddress("127.0.0.1:8001");
referer.setRegistry(registry);
// 配置RPC协议
ProtocolConfig protocol = new ProtocolConfig();
protocol.setId("motan2");
protocol.setName("motan2");
referer.setProtocol(protocol);
// 使用服务
CommonHandler client = referer.getRef();
System.out.println(client.call("hello", new Object[] { "a" }, String.class));
}
use of com.weibo.api.motan.proxy.CommonHandler in project motan by weibocom.
the class Motan2RpcClient method main.
public static void main(String[] args) throws Throwable {
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "classpath:motan2_demo_client.xml" });
MotanDemoService service;
// hessian
service = (MotanDemoService) ctx.getBean("motanDemoReferer");
print(service);
// simple serialization
service = (MotanDemoService) ctx.getBean("motanDemoReferer-simple");
print(service);
// breeze serialization
service = (MotanDemoService) ctx.getBean("motanDemoReferer-breeze");
print(service);
// pb serialization
PbParamService pbService = (PbParamService) ctx.getBean("motanDemoReferer-pb");
System.out.println(pbService.getFeature(Point.newBuilder().setLatitude(123).setLongitude(456).build()));
// common client
CommonHandler xmlClient = (CommonHandler) ctx.getBean("motanDemoReferer-common-client");
motan2XmlCommonClientDemo(xmlClient);
motan2ApiCommonClientDemo();
System.out.println("motan demo is finish.");
System.exit(0);
}
Aggregations