In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to get started with dubbo". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to get started with dubbo.
I. the basic principles of dubbo
The dubbo architecture diagram is as follows:
Description of invocation relationship:
0. The service container is responsible for starting, loading, and running the service provider.
1. Upon startup, the service provider registers the services it provides with the registry.
two。 Service consumers subscribe to the services they need from the registry when they start up.
3. The registry returns a list of service provider addresses to the consumer, and if there is a change, the registry will push the change data to the consumer based on the persistent connection.
4. The service consumer, from the provider address list, chooses one provider to call based on the soft load balancing algorithm, and then chooses another one if the call fails.
5. Service consumers and providers accumulate the number of calls and call time in memory and regularly send statistics to the monitoring center every minute.
Introduction to getting started with demo
The demo consists of three projects, namely:
Service provider project: provider
Service consumer project: consumer
Common Service Interface Project: api
The dependencies are shown in the figure:
The api project is a jar project that packages the generated jar into a maven repository and imports it as a dependency on provider and consumer projects.
Third, the concrete implementation of dubbo- remote call (RPC)
1. Download and configure zookeeper
Start the zookeeper before starting the service provider project, because we need to register the service provider with the zookeeper before it can be discovered and invoked by the service consumer.
Zookeeper will not be introduced in detail here, but a simple summary is the distributed service governance framework, which is used for service registration and discovery, remote invocation functions, and so on.
Zookeeper download
Http://zookeeper.apache.org/
Extract and modify the configuration
After the zookeeper download is completed, extract it to the appropriate directory, then go to the conf directory of zookeeper, find the zoo_sample.cfg file and rename it to zoo.cfg, then open the file, and modify the dataDir and dataLogDir as follows:
DataDir=E:\\ Soft\\ zookeeper-3.4.6\\ data
DataLogDir=E:\\ Soft\\ zookeeper-3.4.6\\ log
Change to the directory of your local hard drive
Start zookeeper
Go to the bin directory of zookeeper, double-click zkServer.cmd, and start zookeeper
2.dubbo Interface Service api Project
Create a new maven project api and pay attention to changing the packaging method in its pom.xml to jar
Then create a new DemoService interface under the com.dubbo.api.service package, as follows:
Public interface DemoService {
String sayHello (String name)
}
The project structure is shown in the figure:
Then package the project (just install it), find the jar in the E:\ temp\ api\ target\ directory, package it to the local maven warehouse, open the cmd command window, and enter the following command:
Mvn install:install-file-Dfile=E:\ temp\ api\ target\ api.jar-DgroupId=com.dubbo.api-DartifactId=api-Dversion=1.0.0-Dpackaging=jar-DgeneratePom=true-DcreateChecksum=true
Note: the jar path should be your own path
3.dubbo Service provider provider Project
Create a new maven project provider and add the following dependencies to pom.xml:
Com.dubbo.api
Api
1.0.0
Com.alibaba
Dubbo
2.5.3
Com.101tec
Zkclient
0.10
Org.springframework
Spring-context
4.0.5.RELEASE
The above generated api interface dependencies, dubbo dependencies, zookeeper client-side dependencies, and necessary dependencies for starting the project are introduced here
Then create a new DemoServiceImp under the com.dubbo.provider.service.impl package and implement the DemoService interface, as follows:
Public class DemoServiceImpl implements DemoService {
@ Override
Public String sayHello (String name) {
Return "Hello" >}
Then create a new provider.xml file under resources, and configure it as follows:
/ / Note that you need to introduce constraints into eclipse, and constrain the dubbo.xsd file after dubbo.2.5.3.jar decompression.
Then create a new Provider directly under java to start the project:
Public class Provider {
Public static void main (String [] args) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext ("provider.xml")
Context.start ()
System.out.println ("dubbo service provider started.")
System.in.read (); / / Press any key to exit
}
}
The provider project structure is shown in the figure:
Then run the main function directly-the dubbo service provider has started!
4.dubbo Service Consumer consumer Project
Create a new maven project consumer and add the following dependencies to pom.xml:
Com.dubbo.api
Api
1.0.0
Com.alibaba
Dubbo
2.5.3
Com.101tec
Zkclient
0.10
Org.springframework
Spring-context
4.0.5.RELEASE
The same dependencies are added by the provider project.
Then create a new comsumer.xml under resources and configure the service consumer as follows:
Then create a new Consumer.class under java to start the project, as follows:
Public class Consumer {
Public static void main (String [] args) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext ("consumer.xml")
Context.start ()
System.out.println ("dubbo service consumer has started...")
DemoService demoService = (DemoService) context.getBean ("demoService"); / / get remote service agent
String hello = demoService.sayHello ("world"); / / execute remote methods
System.out.println (hello); / / display the result of the call
System.in.read (); / / Press any key to exit
}
}
Start the project and display the result of the call, as shown in the figure:
At this point, the remote call to dubbo is completed. The following is about the dubbo-admin Management console
4. Dubbo-admin Management console
Dubbo services can be better managed through dubbo-admin.
First download the war package of dubbo-admin at:
When the download is complete, copy the dubbo-admin-2.6.0.war to the webapps directory of tomcat. Then start tomcat and visit
Http://localhost:8080/dubbo-admin-2.6.0/
You can also rename dubbo-admin-2.6.0 to access http://localhost:8080/dubbo-admin directly when you access dubbo-admin.
Both user name and password are root
After logging in, you can manage the dubbo service through the web page, as shown in the figure:
At this point, I believe you have a deeper understanding of "how to get started with dubbo". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.