SpringBoot之Dubbo

DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。

http://www.oschina.net/p/dubbo

1.导入依赖包(dubbo zookeeper zkclient)

 com.alibaba dubbo 2.5.3 org.apache.zookeeper zookeeper 3.4.6 com.101tec zkclient 0.7

2.写提供者(服务端)的方法

接口:

public interface Hello { public String getString(String name);}

实现类:

public class HelloImpl implements Hello { @Override public String getString(String name) { return name; }}

3.提供者的spring配置

 -->           

4.写消费者(客户端)接口

这里可以把服务端的接口复制过来就完事,如果你需要提供给其他们人使用,最好不是复制接口,而是打成jar接口包。

5.导入和服务端一样的依赖,配置spring配置

       < dubbo : reference interface = "com.example.Hello" id = "hello" />   

6.客户端test

public class DemoApplicationTests { @Autowired Hello h; @Test public void test() { String hh = h.getString("dubbo 远程调用成功"); System.out.println(hh); } }

最后说一下不用tomcat启动的方式

springboot集成dubbo

@SpringBootApplication@ImportResource("classpath:/dubbo-provider.xml")//启动加在dubbo配置文件public class ProviderApplication { public static void main(String[] args) { SpringApplication.run(ProviderApplication.class, args); try { System.out.println("启动成功,按任意键关闭"); System.in.read(); } catch (IOException e) { e.printStackTrace(); } } }
@SpringBootApplicationpublic class DemoApplication { private static final Logger log = LoggerFactory.getLogger(DemoApplication.class); public static void main(String[] args) { try { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/applicationContext*.xml"); context.start(); } catch (Exception e) { log.error("== DubboProvider context start error:", e); } synchronized (DemoApplication.class) { while (true) { try { DemoApplication.class.wait(); } catch (InterruptedException e) { log.error("== synchronized error:", e); } } } }}

tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2284732365


分享到:


相關文章: