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

标签: 负载 springmvc dubbox | 发表时间:2016-08-03 09:42 | 作者:c297186864
出处:http://www.iteye.com
第一步:下载
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。



已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐



相关 [负载 springmvc dubbox] 推荐:

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

- - 企业架构 - ITeye博客
      介绍: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/.

Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)

- - 企业架构 - ITeye博客
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的. 现在核心业务抽取出来,作为独立的服务,使前端应用能更快速和稳定的响应. 大规模服务化之前,应用可能只是通过RMI或Hessian等工具,简单的暴露和引用远程服务,通过配置服务的URL地址进行调用,通过F5等硬件进行负载均衡.

SpringMVC传参

- - 企业架构 - ITeye博客
Spring MVC 的请求参数获取的几种方法. 通过@PathVariabl注解获取路径中传递参数. 用@ModelAttribute注解获取POST请求的FORM表单数据. 直接用HttpServletRequest获取. 用注解@RequestParam绑定请求参数a到变量a. 当请求参数a不存在时会有异常发生,可以通过设置属性required=false解决,.

SpringMVC+ajaxfileupload上传

- - CSDN博客互联网推荐文章
看这篇的文章之前最好看一下上篇文章这样可以更好的理解. 整个项目的基本配置和上面差不多. 不同的是在webRoot文件夹下的js中引入jQuery.js 和ajaxfileupload.js. 如何没有这个两个js文件可以到各自的官网下载. DemoController.java   跳转到upload.jsp.

SpringMVC 注解配置

- - CSDN博客互联网推荐文章
在Spring项目开发中呢,最好是搞明白原理,其次装上Spring为eclipse开发的插件,这样会大大提高开发效率,而且减少了大量信息的记忆负担. SpringIDE插件,可自行到eclipse插件库中进行下载,还有其他Spring相关的plugin可以自行研究下. 当装好这个插件之后呢,可以根据向导创建一个简单的SpringMVC项目,大量的基本信息都可以自动生成,当然了是建立在明白原理的基础上,熟练了之后再去使用插件.

springmvc框架配置

- - CSDN博客编程语言推荐文章
. . .

struts1,struts2,springMVC终极对比

- - CSDN博客Web前端推荐文章
         最近做项目用到了struts2,之前一直是用struts1和springMVC. 感觉到了struts2从很大程度上和这两个还是有很大区别的,所以今天搜集了些资料,给他们做一下对比.          Struts1官方已经停止更新,现在用的也比较少,这里主要讲一下struts2和struts1比较都有哪些不同和进步.

springmvc文件上传下载

- - ITeye博客
在网上搜索的代码 参考整理了一份. commons-fileupload.jar与commons-io-1.4.jar二个文件. 1、表单属性为: enctype="multipart/form-data". 2、springmvc配置.

SpringMVC 拦截器 筛选

- - ITeye博客
 如果只配置拦截类似于*.do格式的url,则对静态资源的访问是没有问题的,但是如果配置拦截了所有的请求(如我们上面配置的“/”),就会造成js文件、css文件、图片文件等静态资源无法访问. 一般Web应用服务器默认的Servlet名称是"default",所以这里我们激活Tomcat的defaultServlet来处理静态文件.

SpringMVC 消息转换器HttpMessageConverter

- - 企业架构 - ITeye博客
在SpringMVC中,可以使用@RequestBody和@ResponseBody两个注解,分别完成请求报文到对象和对象到响应报文的转换,底层这种灵活的消息转换机制,就是Spring3.x中新引入的HttpMessageConverter即消息转换器机制. 还是回到请求-响应,也就是解析请求体,然后返回响应报文这个最基本的Http请求过程中来.