PS: Maven project dependent on the configuration between the rack and the project temporarily omitted, the follow-up to see the situation might write an article caressed his frame structure alone, before Mark ~
Configuration and startup
1.pom the document introduction dubbo zookeeper and operating the client (in this step and configured with the same manufacturer)
<! - introducing Dubbo -> < dependency > < the groupId > com.alibaba </ the groupId > < the artifactId > Dubbo </ the artifactId > < Version > 2.6.2 </ Version > </ dependency > <! - As used herein, as registry zookeeper, zookeeper client pull-in operation -> < dependency > < the groupId > org.apache.curator </ the groupId > < the artifactId >curator-framework</ The artifactId > < Version > 2.12.0 </ Version > </ dependency > <-! Framework relies End ->
2. Create a new consumer xml file, configuration information for consumers
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns:component="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"path configuration scan package<! -> -> < the Component: Scan the Component- Base-Package Penalty for = "com.zhanghaoBF.gmall.service.impl" > </ the Component: the Component-Scan > <-! 1. specify the name of the current service / application (the same service same name, but not to other services of the same name) -> < Dubbo: the Application name = "the Order-service" > </ Dubbo: the Application > <! - 2. designated registration center location -> <! - wording . 1 -> < Dubbo: Registry address = "ZooKeeper: //127.0.0.1: 2181" > </ Dubbo: Registry > <! - wording 2 -> <! -<Dubbo: Registry Protocol = "ZooKeeper" address = "127.0.0.1:2181"> </ Dubbo: Registry> -> <-! Interface remote service need to call the statement of: generating the remote service agent -> < Dubbo : Reference interface = "dubbo.service.user.UserService" ID = "that userService" > </ Dubbo: Reference > </ Beans >
3. Create a consumer startup class Consumer.java
public class Consumer { public static void main (String [] args) throws Exception { // read IOC container the ClassPathXmlApplicationContext context = new new the ClassPathXmlApplicationContext ( "consumer.xml" ); // Get the object from the container assembly OrderService OrderService orderService = context. getBean (OrderService. class ); // call orderService service, the service implementation in remote calls UserService of dubbo service orderService.initOrder ( "1" ); // set the blocking System.out.println ( "call is completed ...." ) ; System.in.read ();// this code: Press any key to exit } }
4. Start
Right after debug startup class, opened the last chapter explains the console, you can see consumers can already see, in the console Hey hey, a little mean thiophene ~
PS: Before you start you need to start zk and the console to achieve results in the figure below