use of com.weibo.api.motan.config.ProtocolConfig in project motan by weibocom.
the class MockServiceConfig method mockProtocolConfig.
protected static ProtocolConfig mockProtocolConfig(String protocolName) {
ProtocolConfig pc = createProtocol(protocolName);
pc.setEndpointFactory("mockEndpoint");
return pc;
}
use of com.weibo.api.motan.config.ProtocolConfig in project motan by weibocom.
the class MotanApiClientDemo method main.
public static void main(String[] args) {
RefererConfig<MotanDemoService> motanDemoServiceReferer = new RefererConfig<MotanDemoService>();
// 设置接口及实现类
motanDemoServiceReferer.setInterface(MotanDemoService.class);
// 配置服务的group以及版本号
motanDemoServiceReferer.setGroup("motan-demo-rpc");
motanDemoServiceReferer.setVersion("1.0");
motanDemoServiceReferer.setRequestTimeout(1000);
// 配置注册中心直连调用
RegistryConfig registry = new RegistryConfig();
// use direct registry
registry.setRegProtocol("direct");
registry.setAddress("127.0.0.1:8002");
// use ZooKeeper registry
// registry.setRegProtocol("zookeeper");
// registry.setAddress("127.0.0.1:2181");
motanDemoServiceReferer.setRegistry(registry);
// 配置RPC协议
ProtocolConfig protocol = new ProtocolConfig();
protocol.setId("motan");
protocol.setName("motan");
motanDemoServiceReferer.setProtocol(protocol);
// motanDemoServiceReferer.setDirectUrl("localhost:8002"); // 注册中心直连调用需添加此配置
// 使用服务
MotanDemoService service = motanDemoServiceReferer.getRef();
System.out.println(service.hello("motan"));
System.exit(0);
}
Aggregations