门户网站建设公开情况自查,常用来做网站的首页,兰州网站制作公司怎么样,上海企业网络专线生成过程视频#xff1a; 如何使用ChatGPT快速生成代码 (qq.com) 如何使用ChatGPT快速生成SpringBoot集成Dubbo的完整案例 1、Dubbo最新版本有哪些新特性
Dubbo最新版本是2.7.9#xff0c;于2021年6月发布。以下是该版本的一些新特性#xff1a; 1#xff09;增加Dubbo-go…生成过程视频 如何使用ChatGPT快速生成代码 (qq.com) 如何使用ChatGPT快速生成SpringBoot集成Dubbo的完整案例 1、Dubbo最新版本有哪些新特性
Dubbo最新版本是2.7.9于2021年6月发布。以下是该版本的一些新特性 1增加Dubbo-go和Dubbo-rust两个新的实现提供更多语言的支持。 2引入Dubbo Mesh可以基于Istio、Kubernetes等服务网格框架自动实现服务的流量管理、熔断降级等功能。 3增加Generic JSON协议支持基于HTTP/JSON的调用。 4支持Dubbo IDL可通过定义IDL文件生成服务接口的Java和Go代码方便服务端和客户端的开发。 5增加GenericService通用服务接口可以跨语言调用且不需要提前定义接口。 6增加Spring Cloud集成可以通过Spring Cloud的Service Registry实现服务的注册与发现。 7提升性能优化了序列化和反序列化过程同时优化了服务端和客户端的线程模型。 8 改进了部分文档和示例。 总的来说Dubbo 2.7.9 在多语言支持、服务网格、协议支持、IDL、性能优化等方面都有不少新特性。 2、Dubbo执行流程图 ┌───────────────┐ │ Dubbo 服务消费者 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 代理类 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 过滤器链 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 集群路由 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 负载均衡选择器 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 传输层 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 协议层 │ └───────────────┘ │ │ ▼ ┌───────────────┐ │ 服务提供者 │ └───────────────┘具体的流程如下
1服务提供者启动时会向Dubbo注册中心注册自己提供的服务以及服务的地址信息。
2服务消费者启动时会向Dubbo注册中心订阅需要消费的服务以及服务地址信息。
3服务消费者通过Dubbo代理类调用Dubbo服务Dubbo代理类会在本地缓存中查找可用的Dubbo服务提供者。
4如果本地缓存中没有可用的Dubbo服务提供者Dubbo代理类会向Dubbo注册中心查询可用的Dubbo服务提供者。
5Dubbo注册中心返回可用的Dubbo服务提供者地址信息Dubbo代理类根据负载均衡策略选择一个Dubbo服务提供者。
6Dubbo代理类将请求发送到Dubbo服务提供者。
7Dubbo服务提供者接收到请求后根据请求的服务名、方法名等信息调用相应的Java方法得到结果。
8Dubbo服务提供者将结果返回给Dubbo代理类。
9Dubbo代理类将结果返回给服务消费者。 需要注意的是Dubbo还提供了多种配置方式和扩展机制使得Dubbo的执行流程可以根据具体的业务场景进行灵活定制。例如Dubbo可以支持多种注册中心、协议、序列化方式等并且提供了众多的过滤器和扩展点方便用户进行二次开发和定制。 3、SpringBoot集成Dubbo的完整实例 下面是一个SpringBoot集成Dubbo的完整实例。本例子使用Dubbo 2.7.9版本和SpringBoot 2.5.0版本。 第一步在pom.xml中添加Dubbo和SpringBoot的依赖。在dependencies中添加以下内容
dependencies!-- Dubbo --dependencygroupIdorg.apache.dubbo/groupIdartifactIddubbo-spring-boot-starter/artifactIdversion2.7.9/version/dependency!-- SpringBoot --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdversion2.5.0/version/dependency
/dependencies第二步在application.properties中添加Dubbo的配置。
#Dubbo
dubbo.application.nameexample-provider
dubbo.registry.addresszookeeper://127.0.0.1:2181
dubbo.protocol.namedubbo
dubbo.protocol.port20880第三步创建一个接口定义我们的Dubbo服务。
public interface ExampleService {String sayHello(String name);
}第四步创建一个实现类实现ExampleService接口。
Service
public class ExampleServiceImpl implements ExampleService {Overridepublic String sayHello(String name) {return Hello name;}
}第五步在Dubbo配置类中将ExampleServiceImpl暴露为Dubbo服务。
Configuration
public class DubboConfig {Beanpublic ApplicationConfig applicationConfig() {ApplicationConfig applicationConfig new ApplicationConfig();applicationConfig.setName(example-provider);return applicationConfig;}Beanpublic RegistryConfig registryConfig() {RegistryConfig registryConfig new RegistryConfig();registryConfig.setAddress(zookeeper://127.0.0.1:2181);return registryConfig;}Beanpublic ProtocolConfig protocolConfig() {ProtocolConfig protocolConfig new ProtocolConfig();protocolConfig.setName(dubbo);protocolConfig.setPort(20880);return protocolConfig;}Beanpublic ServiceConfigExampleService serviceConfig(ExampleService exampleService) {ServiceConfigExampleService serviceConfig new ServiceConfig();serviceConfig.setInterface(ExampleService.class);serviceConfig.setRef(exampleService);serviceConfig.setVersion(1.0.0);serviceConfig.setTimeout(5000);return serviceConfig;}
}第六步创建一个RestController将Dubbo服务注入进去。
RestController
public class ExampleController {Reference(version 1.0.0)private ExampleService exampleService;GetMapping(/hello/{name})public String hello(PathVariable(name) String name) {return exampleService.sayHello(name);}
}第七步启动SpringBoot应用程序运行Dubbo服务提供者。
第八步测试Dubbo服务。使用curl或Postman等工具访问http://localhost:8080/hello/yourname 看到返回的字符串是Hello yourname。