Reprint a blog, write well (at least I refer to the build success)
Reprint Address: http://my.oschina.net/wangt10/blog/522799
Dubbo Introduction
Node role Description:
Provider: The service provider that exposes the service.
Consumer: Invokes the service consumer of the remote service.
Registry: Registration Center for service Registration and discovery.
Monitor: The monitoring center of the call times of the statistics service and the call time.
Container: The service runs the container.
Call Relationship Description:
0. The service container is responsible for starting, loading, and running the service provider.
1. Upon launch, the service provider registers its services with the registry.
2. When the service consumer starts, it subscribes to the registration center for the services it needs.
3. The registry returns the service provider address list to the consumer, and if there is a change, the registry will push the change data to the consumer based on a long connection.
4. Service consumers, from the provider address list, based on the soft load equalization algorithm, select a provider to make the call, if the call fails, then choose another call.
5. Service consumers and providers, the cumulative number of calls in memory and call time, timed to send statistics every minute to the monitoring center.
Four Steps
1 Building Zookeeper Message Center
2 Building Dubbo service-side code
3 Write Dubbo client code
4 Dubbo-admin-2.5.4.war Management Console provided by Dubbo
A: Build Zookeeper Message Center
1 Download Zookeeper installation files
Zookeeper-3.3.6.tar.gz
2 Execute command tar zxvf zookeeper-3.4.6.tar.gz extract, 3 to zookeeper-3.3.6/conf directory
Copy the zoo_sample.cfg as a zoo.cfg, as the default configuration file
4 Configuration Instructions
Ticktime: This time is the time interval between the Zookeeper server or between the client and the server to maintain the heartbeat, that is, each ticktime time sends a heartbeat.
DataDir: As the name implies is Zookeeper to save the data directory, by default, Zookeeper will write the data log file is also stored in this directory.
ClientPort: This port is the port that the client connects to the Zookeeper server, Zookeeper listens to the port and accepts the client's access request.
My configuration: Port 2181 is the default configuration
5 Execute in Zookper-3.3.6/bin directory
./zkserver.sh Start Start zookeeper
6 Verifying that the zookeeper is started
Using NETSTAT-LPN | grep 2181
If there is a port number, the description is already started
PS: Because I Linux is installed in the virtual machine inside, Zookeer in the virtual machine, Dubboserver, dubboclient, dubboadmin are all on Windows, note to open Linux 2181 port
Two Dubboserver project
Dubboserver segment is a Web engineering, service provider, I here is Dubbo and spring combine to build.
The spring build process can be found in the SPRINGMVC + mybatis configuration
I'm only here to build spring and Dubbo examples, using the least configuration
1 Test Code writing
2 Dubbo XML File configuration
<?xml version="1.0" encoding="UTF-8"?><Beansxmlns="Http://www.springframework.org/schema/beans"xmlns:p="Http://www.springframework.org/schema/p"xmlns:dubbo="Http://code.alibabatech.com/schema/dubbo"Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="Http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsd Http://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd "><Dubbo:applicationName="Wt-dubbo-server"/><!--Message Center address--<Dubbo:registryaddress="zookeeper://192.168.20.129:2181" check="false"/><dubbo:protocol name= "Dubbo" port="20880" serialization="hessian2"/><!--declaration interface --< Dubbo:service interface="com. Dubboserver " ref=" Dubboserver "/></beans>
3 Exporting the jar for the interface layer
Export the server layer code to the jar and put it in the dubboclient!!
Then start the project
Three Dubboclient Project
Dubboclient can be a Web project or an ordinary javaproject.
I also use the spring integration, but using JUnit for testing,
1 Dubboclient Terminal code
XML configuration for 2 Dubbo
<?xml version="1.0" encoding="UTF-8"?><Beansxmlns="Http://www.springframework.org/schema/beans"xmlns:p="Http://www.springframework.org/schema/p"xmlns:dubbo="Http://code.alibabatech.com/schema/dubbo"Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="Http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/ Dubbo.xsd "><dubbo:application name="dys-client"/><!--Message Center address--<dubbo:registry address="zookeeper://192.168.20.129:2181" check="false"/><!--declaration interface--< dubbo:reference id="dubboserver" interface= "com. Dubboserver "/></beans>
3 Test run client side code (zookeeper and Dubboserver end already started)
Run successfully!
Four Dubbo-admin-2.5.4.war Management Console
Put this war pack in Tomcat's WebApps directory.
1 Modify the port number of Tomcat do not conflict with other services.
2 Modify the Dubbo.properties file under Web-inf
dubbo.registry.address=zookeeper://192.168.20.129:2181dubbo.admin.root.password=rootdubbo.admin.guest.password=guest
3 launch Tomcat, access.
Click on the service governance--the provider can see the following, there are some other information, then check it, for the time being I am not very clear
160719, Spring + Dubbo + Zookeeper (Linux) frame construction