RPC远程调用 之 Hessian 以spring boot整合hessian为例 注意: 设置hessian超时时间

  Hessian将网络传输的对象转换为二进制流通过Http进行传递,不过它是使用自己的序列化机制实现的编组与反编组,其支持的数据类型是有限制的,不支持复杂的对象。Hessian的优点是可以透过防火墙。

  Hessian也是轻量级的 ws服务,好处是不需要关心过程,调用时就像调用本地一样,毕竟是RMI,http的话,需要自己做好对象的解析  --------方便

首先

服务端 和 客户端

添加hessian依赖

<dependency>    
      <groupId>com.caucho</groupId>    
       <artifactId>hessian</artifactId>    
        <version>4.0.38</version>
</dependency>


服务端

public interface HelloService {
  public String sayHello();
}


@Service("helloService")
public class HelloServiceImpl implements HelloService{
  @Override
  public String sayHello() {
    return "Hello Service!!!";
  }
}


@Component
public class HelloServicePublic {
  @Autowired
  private HelloService helloService;
  //发布服务
  @Bean(name = "/helloService")
  public HessianServiceExporter accountService() {
    HessianServiceExporter exporter = new HessianServiceExporter();
    exporter.setService(helloService);
    exporter.setServiceInterface(HelloService.class);
    return exporter;
  }
}

RPC远程调用 之 Hessian
以spring boot整合hessian为例
注意:
设置hessian超时时间


客户端

public interface HelloService {
  public String sayHello();
}

@Component
public class HelloServiceClient {
  @Bean
  public HessianProxyFactoryBean helloClient() {
    HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
    factory.setServiceUrl("http://localhost:8081/taskServer/helloService");
    factory.setServiceInterface(HelloService.class);
    return factory;
  }
}

@Controller
public class UserController {

  @RequestMapping(value="/getHelloRpc",method= RequestMethod.GET)
  @ResponseBody
  public String getHelloRpc(HttpServletRequest request ,ShopTaskUser user) {
    return helloService.sayHello();
  }

}

RPC远程调用 之 Hessian
以spring boot整合hessian为例
注意:
设置hessian超时时间

简单,再也不需要自己做对象的解析了……

注意:

1、当参数是一个实体类时,如 com.a.projects.hessian.model.Hello  两边路径需一致,interface 接口类没有路径限制。

  当以提供 jar  形式时,忽视这个情况……

设置hessian超时时间

修改 com.caucho.hessian.client.HessianProxyFactory 

private long _readTimeout = 6000;
private long _connectTimeout = 6000;

RPC远程调用 之 Hessian
以spring boot整合hessian为例
注意:
设置hessian超时时间