In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to use Dubbo framework to achieve remote invocation of RPC services in SpringBoot2, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will get something after reading this article on how to use Dubbo framework to achieve remote invocation of RPC services in SpringBoot2. Let's take a look.
1. Introduction to Dubbo framework 1. Framework dependency
The legend shows:
1) the squares Protocol, Cluster, Proxy, Service, Container, Registry, and Monitor in the figure represent layers or modules. The blue indicates that there is interaction with the business, and the green indicates that the internal interaction is only for Dubbo.
2) the background blocks Consumer, Provider, Registry, and Monitor in the figure represent deployment logical topology nodes.
3) in the figure, the blue dotted line is the initialization call, the red dashed line is the run-time asynchronous call, and the red solid line is the run-time synchronous call.
4) the figure contains only the layers of RPC, but not the layers of Remoting, and Remoting as a whole is hidden in Protocol.
2. Core role description
1) Service provider of Provider exposure service
2) the service consumer of Consumer invoking the remote service (load balancer)
3) registries for registration and discovery of Registry services (monitoring, heartbeat, kick-out, re-entry)
4) Monitor service consumers and providers accumulate the number of calls and call time in memory and actively schedule to send statistics to the monitoring center every minute.
5) Container service runtime container: remote invocation, serialization
Second, integration with SpringBoot2.0 1, core dependency com.alibaba.boot dubbo-spring-boot-starter 0.2.02, project structure description
Structure description
Dubbo-consume: service consumer dubbo-provider: service provider dubbo-common: common code block, Dubbo interface, entity class 3, core configuration
1) provider configuration
Server: tomcat: uri-encoding: UTF-8 max-threads: 1000 min-spare-threads: 30 port: 7007 connection-timeout: 5000msspring: application: name: block-dubbo-provider# Dubbo configuration file dubbo: application: name: block-dubbo-provider registry: address: 127.0.0.1 block-dubbo-provider# Dubbo 2181 protocol: zookeeper protocol: name: dubbo port: 20880 scan: base-packages: com.boot.consume
2) Consumer configuration
Server: tomcat: uri-encoding: UTF-8 max-threads: 1000 min-spare-threads: 30 port: 7008 connection-timeout: 5000msspring: application: name: block-dubbo-consume# Dubbo configuration file dubbo: application: name: block-dubbo-consume registry: address: 127.0.0.1 uri-encoding 2181 protocol: zookeeper III, demo case 1, service remote call
1) provider service interface
Pay attention to the notes here
Com.alibaba.dubbo.config.annotation.Service
@ Service@Componentpublic class DubboServiceImpl implements DubboService {private static Logger LOGGER = LoggerFactory.getLogger (DubboServiceImpl.class); @ Override public String getInfo (String param) {LOGGER.info ("character parameter: {}", param); return "[Hello,Cicada]";} @ Override public UserEntity getUserInfo (UserEntity userEntity) {LOGGER.info ("entity class parameter: {}", userEntity); return userEntity;}}
2) Consumer interface
Note the notes here.
Com.alibaba.dubbo.config.annotation.Reference
Org.springframework.stereotype.Service
@ Servicepublic class ConsumeService implements DubboService {@ Referenceprivate DubboService dubboService; @ Overridepublic String getInfo (String param) {return dubboService.getInfo (param);} @ Overridepublic UserEntity getUserInfo (UserEntity userEntity) {return dubboService.getUserInfo (userEntity);}} 2, interface timeout configuration
This configuration can be configured at the service provider or at the service consumer, which is demonstrated here.
Note: timeout
1) Service interface comments
@ Service (timeout = 2000) @ Componentpublic class DubboServiceImpl implements DubboService {}
2) the consumer calls
@ Overridepublic String timeOut (Integer time) {return dubboService.timeOut (time);}
3) Test interface
Service timeout throws an exception
Com.alibaba.dubbo.remoting.TimeoutException3, interface multi-version configuration
1) Service provider
The same interface provides two versions of the implementation. Note: version.
Version 1:
@ Service (version = "1.0.0") @ Componentpublic class VersionOneImpl implements VersionService {@ Overridepublic String getVersion () {return "{current version: 1.0.0}";}}
Version 2:
@ Service (version = "2.0.0") @ Componentpublic class VersionTwoImpl implements VersionService {@ Overridepublic String getVersion () {return "{current version: 2.0.0}";}}
2) the consumer calls
The @ Reference (version) annotation points to different versions of the interface implementation.
@ Servicepublic class VersionServiceImpl implements VersionService {@ Reference (version = "1.0.0") private VersionService versionService1; @ Reference (version = "2.0.0") private VersionService versionService2; @ Overridepublic String getVersion () {return versionService1.getVersion ();} public String version2 () {return versionService2.getVersion ();}} this is the end of the article on "how to use the Dubbo framework to implement remote calls to RPC services in SpringBoot2". Thank you for reading! I believe that everyone has a certain understanding of "how to use Dubbo framework to achieve remote invocation of RPC services in SpringBoot2". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.