博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dubbo的provider和consumer的demo
阅读量:6970 次
发布时间:2019-06-27

本文共 2563 字,大约阅读时间需要 8 分钟。

hot3.png

**

provider项目

** 1、需要调用的接口 package service.api;

public interface DemoService { /*** * 对外的接口 * @param name * @return */ public String sayHello(String name); }

2、调用接口的实现 package service.api.impl;

import org.springframework.stereotype.Service;

import service.api.DemoService;

@Service("demoService") public class DemoServiceImpl implements DemoService{

public String sayHello(String name) {	return "你真棒  居然成功搭建了dubbo的架构";}

}

3、dubbo-provider.xml的配置

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" default-autowire="byName">

<dubbo:protocol id="protocol" name="dubbo" port="25000"

heartbeat="0" threadpool="cached" threads="512" />

</beans>

**

consumer项目

** 1、接口 package service.api;

public interface DemoService { /*** * 对外的接口 * @param name * @return */ public String sayHello(String name); }

2、调用dubbo服务 package service.api;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ConsumerDemo {

public static void main(String[] args) {		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:dubbo-consumer.xml" });  	context.start();  	DemoService demoService = (DemoService) context.getBean("demoService"); //            String str=demoService.sayHello(""); //       System.out.println(str);        try {		Thread.sleep(10000000);	} catch (InterruptedException e) {		// TODO Auto-generated catch block		e.printStackTrace();	} //暂停,每一秒输出一次}

}

3、dubbo-consumer.xml的配置文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

</beans>

转载于:https://my.oschina.net/zhougui/blog/524725

你可能感兴趣的文章
在Windows下如何创建虚拟环境(默认情况下)
查看>>
cwiki-us-angular-app 导入后如何添加到自己的项目
查看>>
DataPipeline |Apache Kafka实战作者胡夕:Apache Kafka监控与调优
查看>>
多线程设计模式:第五篇 - Future模式和两阶段终止模式
查看>>
linux下如何关闭已登录用户
查看>>
我的友情链接
查看>>
unix基础教程9 标准I/O
查看>>
zabbix中通过shell脚本进行微信监控告警
查看>>
sed运用实例一——基于变量的动态替换
查看>>
Html 常见问题
查看>>
GitHub十周岁HanLP自然语言处理包用户量超越CoreNLP
查看>>
Pycharm上Django的使用 Day2
查看>>
5.22-zabbix监控Nginx
查看>>
OSChina 周三乱弹 ——纪念Bob Taylor
查看>>
OSChina 周一乱弹 ——爱丽三个小时没吃鱼罐头了
查看>>
OSChina 周六乱弹 ——程序员还是大学生的时候 带啥去上学
查看>>
nginx在linux环境下安装
查看>>
14_02_Linux系统启动流程详解之二 内核及init
查看>>
Android Material风格的应用(一)--AppBar TabLayout
查看>>
EasyUI的渣性能
查看>>