Search in sources :

Example 1 with MotanDemoService

use of com.weibo.motan.demo.service.MotanDemoService in project motan by weibocom.

the class MotanApiExportDemo method main.

public static void main(String[] args) throws InterruptedException {
    ServiceConfig<MotanDemoService> motanDemoService = new ServiceConfig<MotanDemoService>();
    // 设置接口及实现类
    motanDemoService.setInterface(MotanDemoService.class);
    motanDemoService.setRef(new MotanDemoServiceImpl());
    // 配置服务的group以及版本号
    motanDemoService.setGroup("motan-demo-rpc");
    motanDemoService.setVersion("1.0");
    // 配置注册中心直连调用
    // RegistryConfig directRegistry = new RegistryConfig();
    // directRegistry.setRegProtocol("local");
    // directRegistry.setCheck("false"); //不检查是否注册成功
    // motanDemoService.setRegistry(directRegistry);
    // 配置ZooKeeper注册中心
    RegistryConfig zookeeperRegistry = new RegistryConfig();
    zookeeperRegistry.setRegProtocol("zookeeper");
    zookeeperRegistry.setAddress("127.0.0.1:2181");
    motanDemoService.setRegistry(zookeeperRegistry);
    // 配置RPC协议
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setId("motan");
    protocol.setName("motan");
    motanDemoService.setProtocol(protocol);
    motanDemoService.setExport("motan:8002");
    motanDemoService.export();
    MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
    System.out.println("server start...");
}
Also used : RegistryConfig(com.weibo.api.motan.config.RegistryConfig) MotanDemoService(com.weibo.motan.demo.service.MotanDemoService) ServiceConfig(com.weibo.api.motan.config.ServiceConfig) ProtocolConfig(com.weibo.api.motan.config.ProtocolConfig)

Example 2 with MotanDemoService

use of com.weibo.motan.demo.service.MotanDemoService in project motan by weibocom.

the class DemoRpcClient method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "classpath:motan_demo_client.xml" });
    MotanDemoService service = (MotanDemoService) ctx.getBean("motanDemoReferer");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        System.out.println(service.hello("motan" + i));
        Thread.sleep(1000);
    }
    System.out.println("motan demo is finish.");
    System.exit(0);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MotanDemoService(com.weibo.motan.demo.service.MotanDemoService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 3 with MotanDemoService

use of com.weibo.motan.demo.service.MotanDemoService 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(300);
    // 配置注册中心直连调用
    // RegistryConfig directRegistry = new RegistryConfig();
    // directRegistry.setRegProtocol("local");
    // motanDemoServiceReferer.setRegistry(directRegistry);
    // 配置ZooKeeper注册中心
    RegistryConfig zookeeperRegistry = new RegistryConfig();
    zookeeperRegistry.setRegProtocol("zookeeper");
    zookeeperRegistry.setAddress("127.0.0.1:2181");
    motanDemoServiceReferer.setRegistry(zookeeperRegistry);
    // 配置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

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