dubbo的文件上传

我们将customer和provider分开部署了,这次主要记录文件在customer和provider之间的传输.

如果文件直接在customer中进行保存,不需要传递到provider,则和dubbo就没有关系了.

如果需要传递,如果是使用dubbo协议的话,是不支持 file,inputStream 这种文件,流的传输的.

dubbo中customer和provider之间的通信协议支持很多种

我们这里使用hessian协议进行传输(当然也可以转换成byte[]继续使用dubbo协议)

 

下面是需要进行的配置

customer

需要引入hessian的包

 

[html] view plain copy

print?在CODE上查看代码片派生到我的代码片

  1. <dependency>  
  2.     <groupId>com.caucho</groupId>  
  3.     <artifactId>hessian</artifactId>  
  4.     <version>4.0.7</version>  
  5. </dependency>  


provider

 

pom.xml 需要引入 hessian,jetty的包(Hessian底层采用Http通讯,采用Servlet暴露服务,Dubbo缺省内嵌Jetty作为服务器实现)

 

[html] view plain copy

print?在CODE上查看代码片派生到我的代码片

  1. <dependency>  
  2.     <groupId>com.caucho</groupId>  
  3.     <artifactId>hessian</artifactId>  
  4.     <version>4.0.7</version>  
  5. </dependency>  
  6. <dependency>  
  7.     <groupId>org.mortbay.jetty</groupId>  
  8.     <artifactId>jetty</artifactId>  
  9.     <version>6.1.26</version>  
  10. </dependency>  

provider.xml 需要配置hessian协议,并给service设置

 

 

[html] view plain copy

print?在CODE上查看代码片派生到我的代码片

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans    
  6.   http://www.springframework.org/schema/beans/spring-beans.xsd    
  7.   http://code.alibabatech.com/schema/dubbo  
  8.   http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
  9.     
  10.     <!-- 提供方应用信息,用于计算依赖关系 -->  
  11.     <dubbo:application name="provider" />  
  12.   
  13.     <!-- 使用zookeeper注册中心暴露服务地址 -->  
  14.     <dubbo:registry address="zookeeper://127.0.0.1:2181" />  
  15.       
  16.     <!-- 监控中心 -->  
  17.     <dubbo:monitor protocol="registry" />  
  18.   
  19.     <!-- 暴露服务 -->  
  20.     <dubbo:protocol name="dubbo" port="20886" />  
  21.     <dubbo:protocol name="hessian" port="20887"/>  
  22.   
  23.     <dubbo:service interface="com.dingcheng.user.facade.UserFacade" ref="userFacade" />  
  24.   
  25.     <!-- 需要指定hessian协议,否则会在上面设置的协议中随机调用,就会一会成功一会失败 -->  
  26.     <dubbo:service protocol="hessian" interface="com.dingcheng.user.facade.UploadFacade" ref="uploadFacade" />  
  27. </beans>  



其中 <dubbo:protocol name="hessian" port="20887"/> 就是默认的 server="jetty", 如果设置server="servlet",则需要web容器支持,我们的provider是以jar方式运行的,所以不适用这种.
 

 

 

 

转载于:https://my.oschina.net/u/3246951/blog/846994

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值