Search in sources :

Example 1 with CommonHandler

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));
}
Also used : RegistryConfig(com.weibo.api.motan.config.RegistryConfig) CommonHandler(com.weibo.api.motan.proxy.CommonHandler) ProtocolConfig(com.weibo.api.motan.config.ProtocolConfig) RefererConfig(com.weibo.api.motan.config.RefererConfig)

Example 2 with CommonHandler

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);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MotanDemoService(com.weibo.motan.demo.service.MotanDemoService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) CommonHandler(com.weibo.api.motan.proxy.CommonHandler) PbParamService(com.weibo.motan.demo.service.PbParamService)

Aggregations

CommonHandler (com.weibo.api.motan.proxy.CommonHandler)2 ProtocolConfig (com.weibo.api.motan.config.ProtocolConfig)1 RefererConfig (com.weibo.api.motan.config.RefererConfig)1 RegistryConfig (com.weibo.api.motan.config.RegistryConfig)1 MotanDemoService (com.weibo.motan.demo.service.MotanDemoService)1 PbParamService (com.weibo.motan.demo.service.PbParamService)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1