Search in sources :

Example 1 with RefererConfig

use of com.weibo.api.motan.config.RefererConfig 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 RefererConfig

use of com.weibo.api.motan.config.RefererConfig in project motan by weibocom.

the class SpringSupportTest method testRefererConfig.

@SuppressWarnings("rawtypes")
@Test
public void testRefererConfig() {
    Map<String, RefererConfig> map = cp.getBeansOfType(RefererConfig.class);
    assertEquals(3, map.size());
    RefererConfig clientTest = map.get("&clientTest");
    RefererConfig clientMethodTest = map.get("&clientMethodTest");
    assertTrue(clientTest != null && clientMethodTest != null);
}
Also used : RefererConfig(com.weibo.api.motan.config.RefererConfig) Test(org.junit.Test)

Example 3 with RefererConfig

use of com.weibo.api.motan.config.RefererConfig 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);
}
Also used : RegistryConfig(com.weibo.api.motan.config.RegistryConfig) MotanDemoService(com.weibo.motan.demo.service.MotanDemoService) ProtocolConfig(com.weibo.api.motan.config.ProtocolConfig) RefererConfig(com.weibo.api.motan.config.RefererConfig)

Aggregations

RefererConfig (com.weibo.api.motan.config.RefererConfig)3 ProtocolConfig (com.weibo.api.motan.config.ProtocolConfig)2 RegistryConfig (com.weibo.api.motan.config.RegistryConfig)2 CommonHandler (com.weibo.api.motan.proxy.CommonHandler)1 MotanDemoService (com.weibo.motan.demo.service.MotanDemoService)1 Test (org.junit.Test)1