先把zookeeper在本地給安裝好,
這裏的話講述了兩個工程一個工程是提供服務的,一個工程是調用服務的,因爲dubbo是跟spring進行無縫連接的,故功能配置在spring的配置文件中,跟spring進行整合開發
1、工程是以maven進行構建的,使用的jar包如下:
2、服務提供者的工程
a、dubbo-demo-api 定義接口
[java] view plain copy
public interface IProcessData {
public String deal(String data);
}
b、dubbo-demo-provider 服務提供者
[java] view plain copy
public class ProcessDataImpl implements IProcessData {
/*
* @see com.xxx.bubbo.provider.IProcessData#deal(java.lang.String)
*/
@Override
public String deal(String data) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "Finished:" + data;
}
}
c、applicationProvider.xml配置
[html] view plain copy
<?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
">
<!-- Application name -->
<dubbo:application name="hello-world-app" />
<!-- registry address, used for service to register itself -->
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<!-- expose this service through dubbo protocol, through port 20880 -->
<!--
<dubbo:protocol name="dubbo" port="20880" />
<dubbo:protocol name="dubbo" port="9090" server="netty"
client="netty" codec="dubbo" serialization="hessian2" charset="UTF-8"
threadpool="fixed" threads="100" queues="0" iothreads="9" buffer="8192"
accepts="1000" payload="8388608" />
-->
<!-- Service interface Concurrent Control -->
<dubbo:service interface="com.huangjie.dubbo_Service.service.IProcessData"
ref="demoService" executes="10" />
<!-- Default Protocol -->
<!--
<dubbo:protocol server="netty" />
-->
<!-- designate implementation -->
<bean id="demoService" class="com.huangjie.dubbo_Service.service.impl.ProcessDataImpl" />
</beans>
d、啓動服務
[java] view plain copy
public class DubboProviderMain {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"applicationProvider.xml"});
context.start();
System.out.println("Press any key to exit.");
System.in.read();
}
}
3、服務調用者的工程
a、調用類
[java] view plain copy
public class ConsumerThd implements Runnable {
/*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"applicationConsumer.xml"});
context.start();
IProcessData demoService = (IProcessData) context.getBean("demoService"); // get
// service
// invocation
// proxy
String hello = demoService.deal("nihao"); // do invoke!
System.out.println(Thread.currentThread().getName() + " "+hello);
}
public static void main(String[] args) {
new Thread(new ConsumerThd()).start();
/**
* 輸出結果:
* Thread-0 Finished:nihao
*/
}
}
b、applicationConsumer.xml配置
[html] view plain copy
<?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
">
<!-- consumer application name -->
<dubbo:application name="consumer-of-helloworld-app" />
<!-- registry address, used for consumer to discover services -->
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<dubbo:consumer timeout="5000"/>
<!-- which service to consume? -->
<dubbo:reference id="demoService" interface="com.huangjie.dubbo_Service.service.IProcessData" />
</beans>
4、最後需要把zookeeper的服務給啓動,在zookeeper安裝文件夾下面的bin目錄裏面的zkServer.cmd給點擊運行。不要關閉窗口,保持服務運行
這樣整個調用就完成了,這樣的好處是隻要遠程提供ip地址及端口號,以及對外調用的類,客戶端就可以調用,客戶端不必知道服務端的地址之類的
而且服務端可以開多個zookeeper服務,這樣如果其中一個zookeeper 服務死掉了,其他服務還能正常運行
框架/平臺構成:
Maven+Springmvc + Mybatis + Shiro(權限)+ Tiles(模板) +ActiveMQ(消息隊列) + Rest(服務) + WebService(服務)+ EHcache(緩存) + Quartz(定時調度)+ Html5(支持PC、IOS、Android)
用戶權限系統:
組織結構:角色、用戶、用戶組、組織機構;權限點:頁面、方法、按鈕、數據權限、分級授權
項目管理新體驗:
快速出原型系統、組件樹、版本控制、模塊移植、協同開發、實時監控、發佈管理
可持續集成:
所有組件可移植、可定製、可擴充,開發成果不斷積累,形成可持續發展的良性循環
支持平臺平臺:
Windows XP、Windows 7 、Windows 10 、 Linux 、 Unix
服務器容器:
Tomcat 5/6/7 、Jetty、JBoss、WebSphere 8.5