原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicoolhtml
Dubbo是一個分佈式服務框架,致力於提供高性能和透明化的RPC遠程服務調用方案,以及SOA服務治理方案java
主要核心部件linux
Remoting: 網絡通訊框架,實現了sync-over-async 和 request-response 消息機制.git
RPC: 一個遠程過程調用的抽象,支持負載均衡、容災和集羣功能github
Registry: 服務目錄框架用於服務的註冊和服務事件發佈和訂閱。web
Dubbo採用全Spring配置方式,透明化接入應用,對應用沒有任何API侵入,只需用Spring加載Dubbo的配置便可,Dubbo基於Spring的Schema擴展進行加載。redis
首先maven項目增長dubbo的jar依賴,由於要用到zookeeper註冊中心,也要依賴可是要去掉自帶的log4j否則會默認的版本依賴jms-1.1.jar jmxtools-1.2.1.jar jmxri-1.2.1.jar等3個包,下載挺麻煩,固然若是我的已經在本身的倉庫中有了就無所謂了。spring
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ruishenh</groupId> <artifactId>gomeTest</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>gomeTest Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>3.1.0.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>com.alibaba.rocketmq</groupId> <artifactId>rocketmq-all</artifactId> <version>3.0.4-open</version> <type>pom</type> </dependency> <dependency> <groupId>com.alibaba.rocketmq</groupId> <artifactId>rocketmq-client</artifactId> <version>3.0.4-open</version> </dependency> <dependency> <groupId>com.alibaba.rocketmq</groupId> <artifactId>rocketmq-common</artifactId> <version>3.0.4-open</version> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2.3</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.2.3</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.2.3</version> <scope>compile</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.swinglabs</groupId> <artifactId>swingx</artifactId> <version>1.6.1</version> </dependency> <!--Redis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.4.2</version> <type>jar</type> <scope>compile</scope> </dependency> <!-- spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <!-- 定時器 --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>1.7.2</version> </dependency> <!-- dubbo --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.0.13</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.6</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> <!-- spring mvc 返回 json使用 --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.8.4</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.8.4</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8090</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin> </plugins> <finalName>gomeTest</finalName> </build> </project>
Spring的依賴本身添加就行了express
由於要增長zookeeper的註冊管理,因此若是有可用的zookeeper就用可用的zookeeper,沒有能夠按照以下的安裝去本地安裝一個。apache
項目結構圖
/gomeTest/src/main/resources/spring/dubbo-provider.xml
<?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://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <dubbo:application name="hello-world-app" /> <!-- zookeeper註冊中心 --> <dubbo:registry protocol="zookeeper" address="10.118.62.89:2181" /> <!-- 使用multicast廣播註冊中心暴露服務地址 --> <!-- <dubbo:registry address="multicast://10.57.41.19:1234" /> --> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:service interface="com.ruishenh.dubbo.example.DemoService" ref="demoService" /> <!-- 和本地bean同樣實現服務 --> <bean id="demoService" class="com.ruishenh.dubbo.example.DemoServiceImpl" /> </beans>
/gomeTest/src/main/resources/spring/dubbo-consumer.xml
<?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://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <!-- 消費方應用名,用於計算依賴關係,不是匹配條件,不要與提供方同樣 --> <dubbo:application name="consumer-of-helloworld-app" /> <!-- zookeeper註冊中心 --> <dubbo:registry protocol="zookeeper" address="10.118.62.89:2181" /> <!-- 使用multicast廣播註冊中心暴露的服務地址 --> <!--<dubbo:registry address="multicast://10.57.41.19:1234" /> --> <!-- 生成遠程服務代理,能夠和本地bean同樣使用demoService --> <dubbo:reference id="demoService" interface="com.ruishenh.dubbo.example.DemoService" /> </beans>
/gomeTest/src/main/java/com/ruishenh/dubbo/example/DemoService.java
package com.ruishenh.dubbo.example; public interface DemoService { public void sayHello(); public String returnHello(); public MsgInfo returnMsgInfo(MsgInfo info); }
/gomeTest/src/main/java/com/ruishenh/dubbo/example/DemoServiceImpl.java
package com.ruishenh.dubbo.example; public class DemoServiceImpl implements DemoService{ public void sayHello() { System.out.println("hello world!"); } public String returnHello() { return "hello world!"; } public MsgInfo returnMsgInfo(MsgInfo info) { info.getMsgs().add("處理完畢"); return info; } }
/gomeTest/src/main/java/com/ruishenh/dubbo/example/LuncherProvider.java
package com.ruishenh.dubbo.example; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class LuncherProvider { public static void main(String[] args) throws InterruptedException{ LuncherProvider luncher=new LuncherProvider(); luncher.start(); Thread.sleep(1000*60*10); } void start(){ String configLocation="spring/dubbo-provider.xml"; ApplicationContext context =new ClassPathXmlApplicationContext(configLocation); String [] names=context.getBeanDefinitionNames(); System.out.print("Beans:"); for (String string : names) System.out.print(string+","); System.out.println(); } }
/gomeTest/src/main/java/com/ruishenh/dubbo/example/LuncherConsumer.java
package com.ruishenh.dubbo.example; import java.util.ArrayList; import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class LuncherConsumer { public static void main(String[] args) throws InterruptedException{ LuncherConsumer luncher=new LuncherConsumer(); luncher.start(); } void start(){ String configLocation="spring/dubbo-consumer.xml"; ApplicationContext context =new ClassPathXmlApplicationContext(configLocation); DemoService ds=(DemoService) context.getBean("demoService"); String [] names=context.getBeanDefinitionNames(); System.out.print("Beans:"); for (String string : names) { System.out.print(string); System.out.print(","); } System.out.println(); MsgInfo info =new MsgInfo(); info.setId(1); info.setName("ruisheh"); List<String> msgs=new ArrayList<String>(); msgs.add("I"); msgs.add("am"); msgs.add("test"); info.setMsgs(msgs); System.out.println(ds.returnMsgInfo(info).getMsgs()); } }
/gomeTest/src/main/java/com/ruishenh/dubbo/example/MsgInfo.java
package com.ruishenh.dubbo.example; import java.io.Serializable; import java.util.List; public class MsgInfo implements Serializable { private static final long serialVersionUID = -2814022769568306965L; int id; String name; List<String> msgs; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<String> getMsgs() { return msgs; } public void setMsgs(List<String> msgs) { this.msgs = msgs; } }
//啓動provider:運行LuncherProvider.java
- Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5829428e: startup date [Fri Mar 31 16:21:30 CST 2017]; root of context hierarchy - Loading XML bean definitions from class path resource [spring/dubbo-provider.xml] - using logger: com.alibaba.dubbo.common.logger.support.Log4jLoggerFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7cfefe3f: defining beans [hello-world-app,com.alibaba.dubbo.config.RegistryConfig,dubbo,com.ruishenh.dubbo.example.DemoService,demoService]; root of factory hierarchy - [DUBBO] No dubbo.properties found on the class path., dubbo version: 2.0.13, current host: 127.0.0.1 - [DUBBO] Export dubbo service com.ruishenh.dubbo.example.DemoService to url dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=hello-world-app&dubbo=2.0.13&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 127.0.0.1 - [DUBBO] Register dubbo service com.ruishenh.dubbo.example.DemoService url dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=hello-world-app&dubbo=2.0.13&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision= to registry registry://10.118.62.89:2181/com.alibaba.dubbo.registry.RegistryService?application=hello-world-app®istry=zookeeper, dubbo version: 2.0.13, current host: 127.0.0.1 - [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /10.118.62.89:20880, dubbo version: 2.0.13, current host: 127.0.0.1 - Client environment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT - Client environment:host.name=SF0001107252A.sf.com - Client environment:java.version=1.6.0_29 - Client environment:java.vendor=Sun Microsystems Inc. - Client environment:java.home=C:\Java\jdk1.6.0_29\jre - Client environment:java.class.path=D:\shiva\omcs\gomeTest\target\classes;D:\local\repo\com\alibaba\rocketmq\rocketmq-client\3.0.4-open\rocketmq-client-3.0.4-open.jar;D:\local\repo\com\alibaba\rocketmq\rocketmq-common\3.0.4-open\rocketmq-common-3.0.4-open.jar;D:\local\repo\com\alibaba\rocketmq\rocketmq-remoting\3.0.4-open\rocketmq-remoting-3.0.4-open.jar;D:\local\repo\com\alibaba\fastjson\1.1.33\fastjson-1.1.33.jar;D:\local\repo\io\netty\netty-all\4.0.9.Final\netty-all-4.0.9.Final.jar;D:\local\repo\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;D:\local\repo\commons-io\commons-io\2.4\commons-io-2.4.jar;D:\local\repo\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar;D:\local\repo\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;D:\local\repo\commons-codec\commons-codec\1.2\commons-codec-1.2.jar;D:\local\repo\org\apache\httpcomponents\httpclient\4.2.3\httpclient-4.2.3.jar;D:\local\repo\org\apache\httpcomponents\httpcore\4.2.3\httpcore-4.2.3.jar;D:\local\repo\org\apache\httpcomponents\httpmime\4.2.3\httpmime-4.2.3.jar;D:\local\repo\ch\qos\logback\logback-classic\1.1.1\logback-classic-1.1.1.jar;D:\local\repo\org\slf4j\slf4j-api\1.7.6\slf4j-api-1.7.6.jar;D:\local\repo\ch\qos\logback\logback-core\1.1.1\logback-core-1.1.1.jar;D:\local\repo\org\swinglabs\swingx\1.6.1\swingx-1.6.1.jar;D:\local\repo\com\jhlabs\filters\2.0.235\filters-2.0.235.jar;D:\local\repo\org\swinglabs\swing-worker\1.1\swing-worker-1.1.jar;D:\local\repo\redis\clients\jedis\2.4.2\jedis-2.4.2.jar;D:\local\repo\org\apache\commons\commons-pool2\2.0\commons-pool2-2.0.jar;D:\local\repo\org\springframework\spring-webmvc\3.1.0.RELEASE\spring-webmvc-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-asm\3.1.0.RELEASE\spring-asm-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-context-support\3.1.0.RELEASE\spring-context-support-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-web\3.1.0.RELEASE\spring-web-3.1.0.RELEASE.jar;D:\local\repo\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\local\repo\org\springframework\spring-test\3.1.0.RELEASE\spring-test-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-expression\3.1.0.RELEASE\spring-expression-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-tx\3.1.0.RELEASE\spring-tx-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-aop\3.1.0.RELEASE\spring-aop-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-beans\3.1.0.RELEASE\spring-beans-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-core\3.1.0.RELEASE\spring-core-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-context\3.1.0.RELEASE\spring-context-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-jdbc\3.1.0.RELEASE\spring-jdbc-3.1.0.RELEASE.jar;D:\local\repo\org\quartz-scheduler\quartz\1.7.2\quartz-1.7.2.jar;D:\local\repo\com\alibaba\dubbo\2.0.13\dubbo-2.0.13.jar;D:\local\repo\org\springframework\spring\2.5.6.SEC03\spring-2.5.6.SEC03.jar;D:\local\repo\org\javassist\javassist\3.15.0-GA\javassist-3.15.0-GA.jar;D:\local\repo\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;D:\local\repo\org\apache\zookeeper\zookeeper\3.3.6\zookeeper-3.3.6.jar;D:\local\repo\jline\jline\0.9.94\jline-0.9.94.jar;D:\local\repo\log4j\log4j\1.2.16\log4j-1.2.16.jar;D:\local\repo\org\codehaus\jackson\jackson-core-asl\1.8.4\jackson-core-asl-1.8.4.jar;D:\local\repo\org\codehaus\jackson\jackson-mapper-asl\1.8.4\jackson-mapper-asl-1.8.4.jar;D:\local\repo\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;D:\local\repo\javax\servlet\jsp-api\2.0\jsp-api-2.0.jar - Client environment:java.library.path=C:\Java\jdk1.6.0_29\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Java/jre1.8.0_31/bin/server;C:/Java/jre1.8.0_31/bin;C:/Java/jre1.8.0_31/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Java\jdk1.8.0_31\bin;C:\Java\jdk1.8.0_31\jre\bin;C:\Windows\System32;d:\Program Files (x86)\Lua\5.1\clibs;GRADLE_HOME/bin;C:\Python27;D:\soft\maven\apache-maven-3.3.9\bin;$STORM_HOME/bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Mercurial;D:\soft\gradle-2.12-all\bin;D:\soft\spark\spark-2.1.0-bin-hadoop2.7\bin;%system%\system32;C:\Program Files (x86)\Google\Chrome\Application;C:\ProgramData\Oracle\Java\javapath;C:\Java\jdk1.8.0_31\bin;C:\Java\jdk1.8.0_31\jre\bin;C:\Windows\System32;d:\Program Files (x86)\Lua\5.1\clibs;GRADLE_HOME/bin;C:\Python27;D:\soft\maven\apache-maven-3.3.9\bin;$STORM_HOME\bin;D:\soft\gradle-2.12-all\bin;D:\soft\developer tools\eclipse-jee-mars-2-win32-x86_64\eclipse;;. - Client environment:java.io.tmpdir=C:\Users\01107252\AppData\Local\Temp\ - Client environment:java.compiler=<NA> - Client environment:os.name=Windows 7 - Client environment:os.arch=amd64 - Client environment:os.version=6.1 - Client environment:user.name=01107252 - Client environment:user.home=d:\user\01107252 - Client environment:user.dir=D:\shiva\omcs\gomeTest - Initiating client connection, connectString=10.118.62.89:2181 sessionTimeout=60000 watcher=com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry$1@6b12da40 - [DUBBO] Register: dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=hello-world-app&dubbo=2.0.13&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 127.0.0.1 - Opening socket connection to server /10.118.62.89:2181 - Socket connection established to SF0001107252A.sf.com/10.118.62.89:2181, initiating session - Session establishment complete on server SF0001107252A.sf.com/10.118.62.89:2181, sessionid = 0x15b23746f340000, negotiated timeout = 40000 - [DUBBO] Recover register services [dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=hello-world-app&dubbo=2.0.13&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=], dubbo version: 2.0.13, current host: 127.0.0.1 - [DUBBO] Register: dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=hello-world-app&dubbo=2.0.13&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 127.0.0.1 Beans:hello-world-app,com.alibaba.dubbo.config.RegistryConfig,dubbo,com.ruishenh.dubbo.example.DemoService,demoService, - [DUBBO] All clients has discontected from /10.118.62.89:20880. You can graceful shutdown now., dubbo version: 2.0.13, current host: 127.0.0.1 - [DUBBO] disconected from /10.118.62.89:57216,url:dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=hello-world-app&channel.readonly.sent=true&codec=dubbo&codec.downstream=dubbo&dubbo=2.0.13&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 127.0.0.1
//啓動Consumer:運行LuncherConsumer.java
- Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7d2a1e44: startup date [Fri Mar 31 16:21:40 CST 2017]; root of context hierarchy - Loading XML bean definitions from class path resource [spring/dubbo-consumer.xml] - using logger: com.alibaba.dubbo.common.logger.support.Log4jLoggerFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@667cbde6: defining beans [consumer-of-helloworld-app,com.alibaba.dubbo.config.RegistryConfig,demoService]; root of factory hierarchy - [DUBBO] No dubbo.properties found on the class path., dubbo version: 2.0.13, current host: 127.0.0.1 - Client environment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT - Client environment:host.name=SF0001107252A.sf.com - Client environment:java.version=1.6.0_29 - Client environment:java.vendor=Sun Microsystems Inc. - Client environment:java.home=C:\Java\jdk1.6.0_29\jre - Client environment:java.class.path=D:\shiva\omcs\gomeTest\target\classes;D:\local\repo\com\alibaba\rocketmq\rocketmq-client\3.0.4-open\rocketmq-client-3.0.4-open.jar;D:\local\repo\com\alibaba\rocketmq\rocketmq-common\3.0.4-open\rocketmq-common-3.0.4-open.jar;D:\local\repo\com\alibaba\rocketmq\rocketmq-remoting\3.0.4-open\rocketmq-remoting-3.0.4-open.jar;D:\local\repo\com\alibaba\fastjson\1.1.33\fastjson-1.1.33.jar;D:\local\repo\io\netty\netty-all\4.0.9.Final\netty-all-4.0.9.Final.jar;D:\local\repo\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;D:\local\repo\commons-io\commons-io\2.4\commons-io-2.4.jar;D:\local\repo\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar;D:\local\repo\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;D:\local\repo\commons-codec\commons-codec\1.2\commons-codec-1.2.jar;D:\local\repo\org\apache\httpcomponents\httpclient\4.2.3\httpclient-4.2.3.jar;D:\local\repo\org\apache\httpcomponents\httpcore\4.2.3\httpcore-4.2.3.jar;D:\local\repo\org\apache\httpcomponents\httpmime\4.2.3\httpmime-4.2.3.jar;D:\local\repo\ch\qos\logback\logback-classic\1.1.1\logback-classic-1.1.1.jar;D:\local\repo\org\slf4j\slf4j-api\1.7.6\slf4j-api-1.7.6.jar;D:\local\repo\ch\qos\logback\logback-core\1.1.1\logback-core-1.1.1.jar;D:\local\repo\org\swinglabs\swingx\1.6.1\swingx-1.6.1.jar;D:\local\repo\com\jhlabs\filters\2.0.235\filters-2.0.235.jar;D:\local\repo\org\swinglabs\swing-worker\1.1\swing-worker-1.1.jar;D:\local\repo\redis\clients\jedis\2.4.2\jedis-2.4.2.jar;D:\local\repo\org\apache\commons\commons-pool2\2.0\commons-pool2-2.0.jar;D:\local\repo\org\springframework\spring-webmvc\3.1.0.RELEASE\spring-webmvc-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-asm\3.1.0.RELEASE\spring-asm-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-context-support\3.1.0.RELEASE\spring-context-support-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-web\3.1.0.RELEASE\spring-web-3.1.0.RELEASE.jar;D:\local\repo\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\local\repo\org\springframework\spring-test\3.1.0.RELEASE\spring-test-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-expression\3.1.0.RELEASE\spring-expression-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-tx\3.1.0.RELEASE\spring-tx-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-aop\3.1.0.RELEASE\spring-aop-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-beans\3.1.0.RELEASE\spring-beans-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-core\3.1.0.RELEASE\spring-core-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-context\3.1.0.RELEASE\spring-context-3.1.0.RELEASE.jar;D:\local\repo\org\springframework\spring-jdbc\3.1.0.RELEASE\spring-jdbc-3.1.0.RELEASE.jar;D:\local\repo\org\quartz-scheduler\quartz\1.7.2\quartz-1.7.2.jar;D:\local\repo\com\alibaba\dubbo\2.0.13\dubbo-2.0.13.jar;D:\local\repo\org\springframework\spring\2.5.6.SEC03\spring-2.5.6.SEC03.jar;D:\local\repo\org\javassist\javassist\3.15.0-GA\javassist-3.15.0-GA.jar;D:\local\repo\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;D:\local\repo\org\apache\zookeeper\zookeeper\3.3.6\zookeeper-3.3.6.jar;D:\local\repo\jline\jline\0.9.94\jline-0.9.94.jar;D:\local\repo\log4j\log4j\1.2.16\log4j-1.2.16.jar;D:\local\repo\org\codehaus\jackson\jackson-core-asl\1.8.4\jackson-core-asl-1.8.4.jar;D:\local\repo\org\codehaus\jackson\jackson-mapper-asl\1.8.4\jackson-mapper-asl-1.8.4.jar;D:\local\repo\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;D:\local\repo\javax\servlet\jsp-api\2.0\jsp-api-2.0.jar - Client environment:java.library.path=C:\Java\jdk1.6.0_29\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Java/jre1.8.0_31/bin/server;C:/Java/jre1.8.0_31/bin;C:/Java/jre1.8.0_31/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Java\jdk1.8.0_31\bin;C:\Java\jdk1.8.0_31\jre\bin;C:\Windows\System32;d:\Program Files (x86)\Lua\5.1\clibs;GRADLE_HOME/bin;C:\Python27;D:\soft\maven\apache-maven-3.3.9\bin;$STORM_HOME/bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Mercurial;D:\soft\gradle-2.12-all\bin;D:\soft\spark\spark-2.1.0-bin-hadoop2.7\bin;%system%\system32;C:\Program Files (x86)\Google\Chrome\Application;C:\ProgramData\Oracle\Java\javapath;C:\Java\jdk1.8.0_31\bin;C:\Java\jdk1.8.0_31\jre\bin;C:\Windows\System32;d:\Program Files (x86)\Lua\5.1\clibs;GRADLE_HOME/bin;C:\Python27;D:\soft\maven\apache-maven-3.3.9\bin;$STORM_HOME\bin;D:\soft\gradle-2.12-all\bin;D:\soft\developer tools\eclipse-jee-mars-2-win32-x86_64\eclipse;;. - Client environment:java.io.tmpdir=C:\Users\01107252\AppData\Local\Temp\ - Client environment:java.compiler=<NA> - Client environment:os.name=Windows 7 - Client environment:os.arch=amd64 - Client environment:os.version=6.1 - Client environment:user.name=01107252 - Client environment:user.home=d:\user\01107252 - Client environment:user.dir=D:\shiva\omcs\gomeTest - Initiating client connection, connectString=10.118.62.89:2181 sessionTimeout=60000 watcher=com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry$1@1d96f4b5 - Opening socket connection to server /10.118.62.89:2181 - Socket connection established to SF0001107252A.sf.com/10.118.62.89:2181, initiating session - [DUBBO] Subscribe: subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Register: subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - Session establishment complete on server SF0001107252A.sf.com/10.118.62.89:2181, sessionid = 0x15b23746f340001, negotiated timeout = 40000 - [DUBBO] Recover register services [subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello], dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Register: subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Recover subscribe services {subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello=[com.alibaba.dubbo.registry.support.RegistryDirectory@57922f46]}, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Subscribe: subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Register: subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Start NettyClient SF0001107252A/10.118.62.89 connect to the server /10.118.62.89:20880, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Refer dubbo service com.ruishenh.dubbo.example.DemoService from url zookeeper://10.118.62.89:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 10.118.62.89 Beans:consumer-of-helloworld-app,com.alibaba.dubbo.config.RegistryConfig,demoService, [I, am, test, 處理完畢] - [DUBBO] Run shutdown hook now., dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Close all registries [zookeeper://10.118.62.89:2181/com.alibaba.dubbo.registry.RegistryService?application=consumer-of-helloworld-app&refer=application%3Dconsumer-of-helloworld-app%26dubbo%3D2.0.13%26id%3DdemoService%26interface%3Dcom.ruishenh.dubbo.example.DemoService%26methods%3DreturnMsgInfo%2CreturnHello%2CsayHello], dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Destroy registry: zookeeper://10.118.62.89:2181/com.alibaba.dubbo.registry.RegistryService?application=consumer-of-helloworld-app&refer=application%3Dconsumer-of-helloworld-app%26dubbo%3D2.0.13%26id%3DdemoService%26interface%3Dcom.ruishenh.dubbo.example.DemoService%26methods%3DreturnMsgInfo%2CreturnHello%2CsayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Unregister: subscribe://10.118.62.89/com.ruishenh.dubbo.example.DemoService?application=consumer-of-helloworld-app&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello, dubbo version: 2.0.13, current host: 10.118.62.89 - Session: 0x15b23746f340001 closed - [DUBBO] Destroy reference: dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=consumer-of-helloworld-app&check=false&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 10.118.62.89 - EventThread shut down - [DUBBO] Close netty channel [id: 0x1494cb8b, /10.118.62.89:57216 => /10.118.62.89:20880], dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Close dubbo connect: 10.118.62.89:0-->10.118.62.89:20880, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] Close dubbo connect: 10.118.62.89:0-->10.118.62.89:20880, dubbo version: 2.0.13, current host: 10.118.62.89 - [DUBBO] disconected from /10.118.62.89:20880,url:dubbo://10.118.62.89:20880/com.ruishenh.dubbo.example.DemoService?anyhost=true&application=consumer-of-helloworld-app&check=false&codec=dubbo&dubbo=2.0.13&id=demoService&interface=com.ruishenh.dubbo.example.DemoService&methods=returnMsgInfo,returnHello,sayHello&prompt=dubbo&revision=, dubbo version: 2.0.13, current host: 10.118.62.89
在上面能夠看到調用結果的輸出。
先將app-config.xml文件中的dubbo-provider.xml打開
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--將dubbo的配置文件導入 --> <import resource="dubbo-provider.xml" /> <!-- <import resource="dubbo-consumer.xml" /> --> </beans>
再看下web.xml文件的配置,web.xml位置:
web.xml內容:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>gomeTest</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/app-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter> <filter-name>EncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <servlet-name>springmvc</servlet-name> </filter-mapping> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <error-page> <error-code>404</error-code> <location>/WEB-INF/views/error/404.html</location> </error-page> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
在pom.xml中增長jetty的插件jetty-maven-plugin插件
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8090</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin> </plugins> <finalName>gomeTest</finalName> </build>
調試模式運行:
啓動成功後,訪問http://localhost:8080/test/dubbo
一、安裝Dubbo服務管理中心,須要選擇一個Web容器,咱們使用Tomcat服務器。首先下載Dubbo管理中心安裝文件dubbo-admin-2.5.3.war,或者直接從源碼構建獲得該WAR文件;http://download.csdn.net/download/tangyali516/9219461
二、下載tomcat7
三、下載jdk1.7,http://download.csdn.net/download/zknxx/9662614(這裏有兩個包)
四、修改tomcat默認使用的jdk版本
一、windows平臺
在catalina.bat文件和setclasspath.bat文件開頭的空白處加上以下兩句(指定JDK):
set JAVA_HOME=D:\soft\jdk\jdk1.7.0_64.01\jdk1.7.0_64
set JRE_HOME=D:\soft\jdk\jdk1.7.0_64.01\jdk1.7.0_64\jre
其中後面爲指定的jdk安裝路徑。
二、linux平臺
在catalina.sh文件和setclasspath.sh文件開頭的空白處加上以下兩句(指定JDK)
export JAVA_HOME=/usr/local/java/jdk1.6.0_18
export JRE_HOME=/usr/local/java/jdk1.6.0_18/jre
啓動tomcat,dubbo-admin-2.5.3.war被解壓,webapps/ROOT/WEB-INF/dubbo.properties,指定咱們的註冊中心地址以及登陸密碼,內容以下所示:
dubbo.registry.address=zookeeper://127.0.0.1:2181?backup=127.0.0.1:2182,127.0.0.1:2183 dubbo.admin.root.password=root dubbo.admin.guest.password=guest
而後訪問地址http://10.10.4.130:8080/便可,根據配置文件指定的root用戶密碼,就能夠登陸Dubbo管理控制檯。
咱們將上面開發的服務提供方服務,部署到2個獨立的節點上(192.168.14.1和10.10.4.125),而後能夠經過Dubbo管理中心查看對應服務的情況,如圖所示:
如圖所示:
上圖中能夠看出,該服務有兩個獨立的節點能夠提供,由於配置的集羣模式爲failover,若是某個節點的服務發生故障沒法使用,則會自動透明地重試另外一個節點上的服務,這就不至於出現拒絕服務的狀況。若是想要查看提供方某個節點上的服務詳情,能夠點擊對應的IP:Port連接,示例如圖所示:
上圖能夠看到服務地址:
1 |
dubbo://10.10.4.125:20880/org.shirdrn.dubbo.api.ChatRoomOnlineUserCounterService?actives=100&anyhost=true&application=chatroom-cluster-provider&cluster=failover&dubbo=0.0.1-SNAPSHOT&executes=200&interface=org.shirdrn.dubbo.api.ChatRoomOnlineUserCounterService&loadbalance=random&methods=getMaxOnlineUserCount,queryRoomUserCount&pid=30942&queryRoomUserCount.actives=50&queryRoomUserCount.loadbalance=leastactive&queryRoomUserCount.retries=2&queryRoomUserCount.timeout=500&retries=2&revision=0.0.1-SNAPSHOT&side=provider&timeout=1000×tamp=1427793652814&version=1.0.0 |
若是咱們直接暴露該地址也是能夠的,不過這種直連的方式對服務消費方不是透明的,若是之後IP地址更換,也會影響調用方,因此最好是經過註冊中心來隱蔽服務地址。同一個服務所部署在的多個節點上,也就對應對應着多個服務地址。另外,也能夠對已經發布的服務進行控制,如修改訪問控制、負載均衡相關配置內容等,能夠經過上圖中「消費者」查看服務消費方調用服務的狀況,如圖所示:
也在管理控制檯能夠對消費方進行管理控制。
Dubbo監控中心是以Dubbo服務的形式發佈到註冊中心,和普通的服務時同樣的。例如,我這裏下載了Dubbo自帶的簡易監控中心文件dubbo-monitor-simple-2.5.3-assembly.tar.gz,下載地址:http://download.csdn.net/download/liweifengwf/7864009能夠解壓縮之後,修改配置文件~/dubbo-monitor-simple-2.5.3/conf/dubbo.properties的內容,以下所示:
[sfapp@cmos1 bin]$ vi ../conf/dubbo.properties ## # Copyright 1999-2011 Alibaba Group. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## dubbo.container=log4j,spring,registry,jetty dubbo.application.name=simple-monitor dubbo.application.owner= #dubbo.registry.address=multicast://224.5.6.7:1234 dubbo.registry.address=zookeeper://10.118.62.89:2181 #dubbo.registry.address=redis://127.0.0.1:6379 #dubbo.registry.address=dubbo://127.0.0.1:9090 dubbo.protocol.port=7070 dubbo.jetty.port=8080 dubbo.jetty.directory=${user.home}/monitor dubbo.charts.directory=${dubbo.jetty.directory}/charts dubbo.statistics.directory=${user.home}/monitor/statistics dubbo.log4j.file=logs/dubbo-monitor-simple.log dubbo.log4j.level=WARN
而後啓動簡易監控中心,執行以下命令:
[sfapp@cmos1 duan]$ cd dubbo-monitor-simple-2.5.3/bin [sfapp@cmos1 bin]$ ./start.sh Starting the simple-monitor .......OK! PID: 120076 STDOUT: logs/stdout.log
這裏使用了Jetty Web容器,訪問地址http://10.202.11.117:8080/就能夠查看監控中心,Applications選項卡頁面包含了服務提供方和消費方的基本信息,如圖所示:
上圖主要列出了全部提供方發佈的服務、消費方調用、服務依賴關係等內容。
接着,查看Services選項卡頁面,包含了服務提供方提供的服務列表,如圖所示:
點擊上圖中Providers連接就能看到服務提供方的基本信息,包括服務地址等,如圖所示:
點擊上圖中Consumers連接就能看到服務消費方的基本信息,包括服務地址等,如圖所示:
因爲上面是Dubbo自帶的一個簡易監控中心,可能所展示的內容並不能知足咱們的須要,因此能夠根據須要開發本身的監控中心。Dubbo也提供了監控中心的擴展接口,若是想要實現本身的監控中心,能夠實現接口com.alibaba.dubbo.monitor.MonitorFactory和com.alibaba.dubbo.monitor.Monitor,其中MonitorFactory接口定義以下所示:
/** * MonitorFactory. (SPI, Singleton, ThreadSafe) * * @author william.liangf */ @SPI("dubbo") public interface MonitorFactory { /** * Create monitor. * @param url * @return monitor */ @Adaptive("protocol") Monitor getMonitor(URL url); }
Monitor接口定義以下所示:
/** * Monitor. (SPI, Prototype, ThreadSafe) * * @see com.alibaba.dubbo.monitor.MonitorFactory#getMonitor(com.alibaba.dubbo.common.URL) * @author william.liangf */ public interface Monitor extends Node, MonitorService { }
具體定義內容能夠查看MonitorService接口,再也不累述。
總結
Dubbo還提供了其餘不少高級特性,如路由規則、參數回調、服務分組、服務降級等等,並且不少特性在給出內置實現的基礎上,還給出了擴展的接口,咱們能夠給出自定義的實現,很是方便並且強大。更多能夠參考Dubbo官網用戶手冊和開發手冊。
附錄:Dubbo使用Maven構建依賴配置
<properties> <spring.version>3.2.8.RELEASE</spring.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <properties> <dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </exclusion> <exclusion> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.15.0-GA</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>hessian-lite</artifactId> <version>3.2.1-fixed-2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.8</version> </dependency> <dependency> <groupId>org.jvnet.sorcerer</groupId> <artifactId>sorcerer-javac</artifactId> <version>0.8</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.5</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency> <dependency> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> <version>3.2.7.Final</version> </dependency> </dependencies>