【0.Dubbo专栏的知识在这里呦,持续更新中,敬请期待】
【1.Dubbo面试题】
【2.RPC框架、RPC框架必会的基本知识、手写一个RPC框架案例、优秀的RPC框架Dubbo、Dubbo和SpringCloud框架比较】



定义服务接口
public interface IloginService {
String login(String username,String password);
}
定义服务接口实现类
public class IloginServiceImpl implements IloginService{
@Override
public String login(String username, String password) {
if (username.equals("root")&password.equals("root")){
return "SUCCESS";
}
return "FAILED";
}
}
pom文件中导入dubbo依赖的文件
<dependency>
<groupId>org.apache.dubbogroupId>
<artifactId>dubboartifactId>
<version>2.7.8version>
dependency>
resources文件资源目录下配置application.xml文件
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="dubbo-client" />
<dubbo:registry address="N/A" timeout="10000"/>
<dubbo:reference id="loginService" interface="com.ljw.dubbo.server.IloginService"
url="dubbo://IP地址:20880/com.ljw.dubbo.server.IloginService" />
beans>
启动服务端的代码—主要是provider的容器Main方法
import org.apache.dubbo.container.Main;
public class App
{
public static void main( String[] args )
{
Main.main(args);
}
}
pom文件中引入服务端项目依赖,以及dubbo的依赖
<dependency>
<artifactId>dubbo-serverartifactId>
<groupId>com.ljw.dubbo.servergroupId>
<version>1.0-SNAPSHOTversion>
dependency>
<dependency>
<groupId>org.apache.dubbogroupId>
<artifactId>dubboartifactId>
<version>2.7.8version>
dependency>
resources文件资源目录下配置application.xml文件
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="dubbo-client" />
<dubbo:registry address="N/A" timeout="10000"/>
<dubbo:reference id="loginService" interface="com.ljw.dubbo.server.IloginService"
url="dubbo://ip地址:20880/com.ljw.dubbo.server.IloginService" />
beans>
服务端启动代码
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
IloginService iloginService =null;
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/META-INF/spring/application.xml");
iloginService = ac.getBean(IloginService.class);
System.out.println(iloginService.login("root","root"));
}
}
服务者成功启动

消费者访问成功

搞定,上面服务端和消费端并没有配置注册中心,dubbo配置很简单,而且也集成了很多的注册中心,zk,nacos,etcd,consul,redis等等,集成方式也很简单,服务启动,pom导入客户端的依赖,配置文件的设置。成功集成。
好了,到这里【Dubbo框架、Dubbo中角色以及作用、各组件启动流程执行步骤、基于Dubbo实现的远程通信的案例】就先学习到这里,后续关于Dubbo更多的内容持续创作学习中,敬请期待。