`

软负载--springmvc+dubbox+zookeeper,分享下

 
阅读更多
第一步:下载
maven:  https://maven.apache.org/download.cgi#   
dubbox:  https://github.com/dangdangdotcom/dubbox,
      介绍:http://www.open-open.com/lib/view/open1417426480618.html 
      dubbox: 是一波大牛在dubbo的基础上的扩展,比如加入的rest,升级了spring版本等等。
下载:zookeeper 我这下载的3.4.6  http://apache.fayea.com/zookeeper/zookeeper-3.4.6/
eclipse:要装下maven插件。

第二部:安装
maven: 安装使用自己百度吧,其实就是配置下环境变量,修改下jar包的存放位置
dubbox:用CMD命令到解压出来的dubbox目录执行mvn install -Dmaven.test.skip=true来尝试编译一下dubbo(并将dubbo的jar安装到本地maven库),这样导入eclipse里面就可测试自带的demo了
zookeeper:解压之后到conf目录新建个zoo.cfg,其实就是zoo_sample.cfg上修改的,主要修改两个地方就行
1、# 存储内存中数据库快照的位置,如果不设置参数,更新事务日志将被存储到默认位置。 
dataDir=D:\\apache-zookeeper-3.4.6\\dataDir 
2、# 错误日志的存放位置 
dataLogDir=D:\\apache-zookeeper-3.4.6\\dataLogDir

第三步用eclipse 创建自己的项目,这里我直接把我搭建的项目上传。大家可以自己看下
spring-dubbo-demo-provider.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
 - 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.
-->
<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-2.5.xsd
	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <dubbo:application name="demo-provider" owner="programmer" organization="dubbox"/>
  

    <dubbo:registry protocol="zookeeper" file="C://Users/Administrator//dubbo//output//p1.cache" address="zookeeper://127.0.0.1:2181"/>

<!-- 	<dubbo:registry address="multicast://224.5.6.7:1234?unicast=false"/> -->

<!-- 	<dubbo:registry address="192.168.1.104:9090"/> -->
	
    <!--uncomment this if you want to test dubbo's monitor-->
<!--     <dubbo:monitor protocol="registry"/> -->

    <!-- here we demonstrate both annotation-based and xml-based configs -->
    <dubbo:annotation package="com.alibaba.dubbo.demo.user.facade" />

    <dubbo:protocol name="dubbo" serialization="kryo" optimizer="com.alibaba.dubbo.demo.SerializationOptimizerImpl" port="20880" />
    <!--<dubbo:protocol name="dubbo" serialization="fst" optimizer="com.alibaba.dubbo.demo.SerializationOptimizerImpl"/>-->

    <!--<dubbo:protocol name="dubbo" serialization="nativejava"/>-->
    <!--<dubbo:protocol name="dubbo" serialization="hessian2"/>-->
    <!--<dubbo:protocol name="dubbo" serialization="fastjson"/>-->
    <!--<dubbo:protocol name="dubbo" serialization="dubbo"/>-->


    <!--TODO according to the spring convention, we should use something like keep-alive-->
    <!-- use netty server -->
    <!--<dubbo:protocol name="rest" port="8888" keepalive="true" server="netty" iothreads="5" threads="100" contextpath="services"/>-->

    <!-- use tjws server -->
    <!--<dubbo:protocol name="rest" port="8888" server="tjws" contextpath="services"/>-->

    <!-- use tomcat server -->
    <dubbo:protocol name="rest" port="8888" threads="500" contextpath="services" server="tomcat" accepts="500"
                    extension="com.alibaba.dubbo.demo.extension.TraceInterceptor,
                    com.alibaba.dubbo.demo.extension.TraceFilter,
                    com.alibaba.dubbo.demo.extension.ClientTraceFilter,
                    com.alibaba.dubbo.demo.extension.DynamicTraceBinding,
                    com.alibaba.dubbo.demo.extension.CustomExceptionMapper,
                    com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"/>

    <!-- use the external tomcat or other server with the servlet approach; the port and contextpath must be exactly the same as those in external server -->
    <!--<dubbo:protocol name="rest" port="8888" contextpath="services" server="servlet"/>-->

<!--     <dubbo:protocol name="http" port="8889"/> -->
<!--     <dubbo:protocol name="hessian" port="8890"/> -->
<!--     <dubbo:protocol name="webservice" port="8892"/> -->

	<dubbo:service interface="com.alibaba.dubbo.demo.bid.BidService" ref="bidService"  protocol="dubbo"/>

    <!-- we add the group property since there's another annotation-configured service impl: com.alibaba.dubbo.demo.user.facade.AnnotationDrivenUserRestServiceImpl -->
    <dubbo:service interface="com.alibaba.dubbo.demo.user.UserService" ref="userService"  protocol="dubbo" group="xmlConfig"/>

	<dubbo:service interface="com.alibaba.dubbo.demo.user.facade.UserRestService" ref="userRestService"  protocol="rest" validation="true"/>
	<dubbo:service interface="com.alibaba.dubbo.demo.user.facade.AnotherUserRestService" ref="anotherUserRestService"  protocol="rest"  timeout="2000" connections="100" validation="true"/>

    <bean id="bidService" class="com.alibaba.dubbo.demo.bid.BidServiceImpl" />

    <bean id="userService" class="com.alibaba.dubbo.demo.user.UserServiceImpl" />

    <bean id="userRestService" class="com.alibaba.dubbo.demo.user.facade.UserRestServiceImpl">
        <property name="userService" ref="userService"/>
    </bean>

    <bean id="anotherUserRestService" class="com.alibaba.dubbo.demo.user.facade.AnotherUserRestServiceImpl">
        <property name="userService" ref="userService"/>
    </bean>
</beans>


spring-dubbo-demo-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-3.2.xsd
	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd" >

    <dubbo:application name="opspeedc" owner="programmer" organization="dubbox"/>
    
	<dubbo:registry protocol="zookeeper" file="C://Users/Administrator//dubbo//output//c1.cache" address="zookeeper://127.0.0.1:2181"/>
	
<!-- 	<dubbo:registry address="multicast://224.5.6.7:1234?unicast=false" /> -->

<!-- 	<dubbo:registry address="192.168.1.104:9090"/> --> 
    <!--uncomment this if you want to test dubbo's monitor-->
    <!--<dubbo:monitor protocol="registry"/>-->

    <dubbo:reference id="bidService" interface="com.alibaba.dubbo.demo.bid.BidService"/> <!-- sticky="true" --> 
    
    <dubbo:reference id="anotherUserRestService" interface="com.alibaba.dubbo.demo.user.facade.AnotherUserRestService"/>

    <!-- directly connect to provider to simulate the access to non-dubbo rest services -->
<!--     <dubbo:reference id="anotherUserRestService" interface="com.alibaba.dubbo.demo.user.facade.AnotherUserRestService" url="rest://localhost:8888/services/"/> -->
</beans>


我消费者  和提供者 都是web项目 直接上传到附近,大家下载下来后倒入eclipse就可以跑了,
消费者是springMVC 解析器配置的jsp和freemarker。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics