最后的话
无论是哪家公司,都很重视Spring框架技术,重视基础,所以千万别小看任何知识。面试是一个双向选择的过程,不要抱着畏惧的心态去面试,不利于自己的发挥。
同时看中的应该不止薪资,还要看你是不是真的喜欢这家公司,好了希望这篇文章对大家有帮助!
部分截图:
这里下载zip压缩包和tar.gz压缩包均可,下载到本地后解压,将其导入到IDEA中即可。
导入完成后,我们看到的项目结构如下所示。
接下来,我们就对Dubbo源码中的核心模块进行简单的介绍。
dubbo-common模块
Dubbo的公共模块,提供了Dubbo SPI的实现、时间轮的实现、动态编译等通用的功能。
dubbo-remoting模块
Dubbo的远程通信模块,其中,dubbo-remoting-api是对整个模块的核心抽象,其他子模块基于其他开源框架对dubbo-remoting-api进行实现。
dubbo-rpc模块
Dubbo的RPC模块,依赖dubbo-remoting模块。其中,dubbo-remoting-api是整个dubbo-rpc模块的核心抽象,其他模块是对dubbo-remoting-api的实现。
dubbo-registry模块
Dubbo中与注册中心交互的模块。其中dubbo-registry-api是整个dubbo-registry的核心抽象,其他模块是对dubbo-registry-api的具体实现。
dubbo-config模块
Dubbo中解析对外暴露的配置的模块。其中,dubbo-config-api 子模块负责处理以API 方式使用Dubbo时的相关配置,dubbo-config-spring 子模块负责处理与 Spring 集成使用时的相关配置方式。
dubbo-metadata模块
Dubbo中的元数据模块。其中,dubbo-metadata-api是对整个dubbo-metadata的抽象,其他模块是对dubbo-metadata-api的实现。
dubbo-configcenter模块
Dubbo的配置中心模块,其中,提供了多种服务发现的方式并接入了多种服务发现组件。
dubbo-monitor模块
Dubbo 的监控模块,主要用于统计服务调用次数、调用时间以及实现调用链跟踪的服务。
dubbo-cluster模块
Dubbo的集群管理模块,主要提供负载均衡、容错、路由等功能。
在Dubbo源码中,有一个示例程序模块dubbo-demo,在运行dubbo-demo模块中的示例前,我们先在本地启动一个Zookeeper作为注册中心。
注:小伙伴们可以自行到Apache官网下载Zookeeper。
Dubbo示例程序结构
Dubbo提供的示例程序的总体结构如下所示。
我们来看看dubbo-demo下有哪些模块。
-
dubbo-demo-interface:Dubbo示例定义的业务接口。
-
dubbo-demo-xml:提供了基于Spring XML的使用示例。
-
dubbo-demo-annotation:提供了基于Spring注解方式的使用示例。
-
dubbo-demo-api:提供了以API方式使用Dubbo的示例。
其中,dubbo-demo-xml、dubbo-demo-annotation和dubbo-demo-api模块都是依赖dubbo-demo-interface模块的。
接下来,我们就对dubbo-demo-interface模块和dubbo-demo-annotation模块的核心代码进行简单的介绍,并运行相关的示例程序。小伙伴们可自行分析和运行dubbo-demo-xml和dubbo-demo-api中的示例程序并运行相关的代码。
(1)dubbo-demo-interface:定义了业务接口。
其中,DemoService接口的核心代码如下所示。
package org.apache.dubbo.demo;
import java.util.concurrent.CompletableFuture;
public interface DemoService {
//同步调用
String sayHello(String name);
//异步调用
default CompletableFuture sayHelloAsync(String name) {
return CompletableFuture.completedFuture(sayHello(name));
}
}
(2)dubbo-demo-annotation:提供了基于Spring注解的示例程序。
Provider代码
我们先来看dubbo-demo-annotation-provider模块,也就是服务的提供者。其DemoServiceImpl的代码如下所示。
@DubboService
public class DemoServiceImpl implements DemoService {
private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);
@Override
public String sayHello(String name) {
logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
@Override
public CompletableFuture sayHelloAsync(String name) {
return null;
}
}
Application类的代码如下所示。
public class Application {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
context.start();
System.in.read();
}
@Configuration
@EnableDubbo(scanBasePackages = “org.apache.dubbo.demo.provider”)
@PropertySource(“classpath:/spring/dubbo-provider.properties”)
static class ProviderConfiguration {
@Bean
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress(“zookeeper://127.0.0.1:2181”);
return registryConfig;
}
}
}
Consumer代码
接下来,我们来看看dubbo-demo-annotation-consumer模块的代码,也就是服务消费者的示例代码。其中,DemoServiceComponent类的代码如下所示。
@Component(“demoServiceComponent”)
public class DemoServiceComponent implements DemoService {
@DubboReference
private DemoService demoService;
@Override
public String sayHello(String name) {
return demoService.sayHello(name);
最后总结
搞定算法,面试字节再不怕,有需要文章中分享的这些二叉树、链表、字符串、栈和队列等等各大面试高频知识点及解析
最后再分享一份终极手撕架构的大礼包(学习笔记):分布式+微服务+开源框架+性能优化
moService.sayHello(name);
最后总结
搞定算法,面试字节再不怕,有需要文章中分享的这些二叉树、链表、字符串、栈和队列等等各大面试高频知识点及解析
最后再分享一份终极手撕架构的大礼包(学习笔记):分布式+微服务+开源框架+性能优化
[外链图片转存中…(img-tBJn1sud-1714881585877)]