public String getName() {
return name;
}
@Override
public String toString() {
return “Person [id=” + id + “, name=” + name + “]”;
}
public void setName(String name) {
this.name = name;
}
}
UserService.java
接口中定义
package com.bobo.service;
import com.bobo.pojo.Person;
public interface UserService {
String sayHello(String name);
String testPojo(Person person);
}
2.2 provider
pom.xml
引入相关的依赖
com.bobo
dubbo-common
0.0.1-SNAPSHOT
org.springframework
spring-context
4.3.21.RELEASE
org.slf4j
slf4j-log4j12
1.7.25
com.alibaba
dubbo
2.5.3
spring
org.springframework
com.github.sgroschupf
zkclient
0.1
Spring配置文件
在spring配置文件中设置dubbo的相关信息
<?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:context=“http://www.springframework.org/schema/context”
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://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name=“dubboProvider” />
<dubbo:registry protocol=“zookeeper”
address=“192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181” />
<dubbo:protocol name=“dubbo” port=“20880” />
<dubbo:monitor protocol=“registry” />
<dubbo:service interface=“com.bobo.service.UserService” ref=“userService”
group=“dubbo” version=“1.0.0” timeout=“3000”/>
zookeeper的配置方式如下:
<dubbo:registry address=“zookeeper://192.168.88.171:2181” />
或者
<dubbo:registry protocol=“zookeeper” address=“192.168.88.171:2181” />
如果有多个ip地址
<dubbo:registry address=“zookeeper://192.168.88.171:2181?backup=192.168.88.172:2181,192.168.88.173:2181” />
或者
<dubbo:registry protocol=“zookeeper”
address=“192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181” />
另外你还可以在同一个 Zookeeper 服务器上划分多个分组
<dubbo:registry id=“registry1” protocol=“zookeeper” address=“10.20.153.10:2181” gr
oup=“registry1” />
<dubbo:registry id=“registry2” protocol=“zookeeper” address=“10.20.153.10:2181” gro
up=“registry2” />
在同一个 Zookeeper 服务器上划分了两个分组,也就是会有两颗树目录,树根分别为 registry1 和 registry2。
UserServiceImpl
接口实现类
public class UserServiceImpl implements UserService {
@Override
public String sayHello(String name) {
//让当前当前线程休眠2s
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“-------”+name);
return name+“----000”;
}
@Override
public String testPojo(Person person) {
System.out.println(person.getName()+“/t”+person.getId());
return “你好啊…”;
}
}
log4j.properties
log4j.rootLogger=INFO,A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
测试启动
package com.bobo.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
public static void main(String[] args) throws InterruptedException {
ApplicationContext ac =
new ClassPathXmlApplicationContext(“applicationContext.xml”);
//挂起当前线程,如果没有改行代码,服务提供者进程会消亡,服务消费者就发现不了提供者了
Thread.currentThread().join();
}
}
服务已经成功注册到了zookeeper中
2.3 consumer
pom.xml
引入相关的依赖
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
结尾
这不止是一份面试清单,更是一种”被期望的责任“,因为有无数个待面试者,希望从这篇文章中,找出通往期望公司的”钥匙“,所以上面每道选题都是结合我自身的经验于千万个面试题中经过艰辛的两周,一个题一个题筛选出来再次对好答案和格式做出来的,面试的答案也是再三斟酌,深怕误人子弟是小,影响他人仕途才是大过,也希望您能把这篇文章分享给更多的朋友,让他帮助更多的人,帮助他人,快乐自己,最后,感谢您的阅读。
由于细节内容实在太多啦,在这里我花了两周的时间把这些答案整理成一份文档了,在这里只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!
来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-FCaKQSrx-1711932943067)]
结尾
[外链图片转存中…(img-GWCBA0pG-1711932943068)]
这不止是一份面试清单,更是一种”被期望的责任“,因为有无数个待面试者,希望从这篇文章中,找出通往期望公司的”钥匙“,所以上面每道选题都是结合我自身的经验于千万个面试题中经过艰辛的两周,一个题一个题筛选出来再次对好答案和格式做出来的,面试的答案也是再三斟酌,深怕误人子弟是小,影响他人仕途才是大过,也希望您能把这篇文章分享给更多的朋友,让他帮助更多的人,帮助他人,快乐自己,最后,感谢您的阅读。
由于细节内容实在太多啦,在这里我花了两周的时间把这些答案整理成一份文档了,在这里只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!