1. Project directory structure
Where edu_service_user is the provider of the service, and edu-web_boss is the consumer of the service
Two xml core configuration
①, service provider
<!-- provider application information, used to calculate dependencies --> <dubbo:application name="gw-service-user" /> <!-- Use the zookeeper registry to expose the service address --> <dubbo:registry protocol="zookeeper" address="192.168.201.1:2181" /> <!-- Expose services on port 20880 using the dubbo protocol --> <dubbo:protocol name="dubbo" port="20880" /> <!-- User service interface --> <dubbo:service interface="wusc.edu.facade.user.service.PmsUserFacade" ref="pmsUserFacade" />
(Explanation: address is the current ip interface of my machine: the interface that provides services)
---------------------------------------------------------------------------------------------------------------------------------------------
②, the service consumer
<!-- Consumer application name, used to calculate dependencies, not matching conditions, not the same as the provider --> <dubbo:application name="edu-web-boss" /> <!-- Use the zookeeper registry to expose the service address --> <!-- Registration Center Address --> <dubbo:registry protocol="zookeeper" address="192.168.201.1:2181" /> <!-- User service interface --> <dubbo:reference interface="wusc.edu.facade.user.service.PmsUserFacade" id="pmsUserFacade" check="false" />
This is similar to the configuration of the service provider
Three, start the effect
①, start Zookeeper first (I am running on Windows here)
② , install the dubbo console
*(The installation package is at the end of the article)*
③, start Tomcat
④. Register the service to Zookeeper and run the code as follows
⑤, run the project, run the console (127.0.0.1:8080/)
The effect diagram is as follows
The final picture of the project is as follows
A simple code example is like this, the project source code