dubbox 发布rest服务调用过程记录
2017-08-14 11:14
405 查看
<?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"
xmlns:context="http://www.springframework.org/schema/context"
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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="HSFServiceA"/>
<!-- 使用zookeeper统一管理 -->
<dubbo:registry protocol="zookeeper" address="192.168.136.129:2181" />
<!-- 不同协议在不同端口暴露服务 -->
<!-- <dubbo:protocol id="dubbo" name="dubbo" port="31106" accesslog="E:\\logs\\hsf\\hsfserverA.log" /> -->
<dubbo:protocol id="rest" name="rest" port="8080" server="servlet" contextpath="HSFServiceA" accesslog="E:\\logs\\hsf\\hsfserverA.log"/>
<bean id="ServiceAImpl" class="com.services.impl.ServiceAImpl" ></bean>
<dubbo:service interface="com.services.ServiceA" ref="ServiceAImpl" loadbalance="random" timeout="30000" executes="10" >
</dubbo:service>
</beans>
最近在使用dubbox作开发,发布为rest服务,服务起动进使用server=servlet这个模式,但是在调用时怎么也调用不通,所以一直在找原因,上面是服务的xml配置文件,下面是调用者的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"
xmlns:context="http://www.springframework.org/schema/context"
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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="HSFClient" />
<!-- 注册中心地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.136.129:2181" />
<dubbo:protocol id="rest" name="rest" />
<!-- 生成远程服务代理,可以和本地bean一样使用 -->
<dubbo:reference id="ServiceA" interface="com.services.ServiceA" />
</beans>
最后发现是tomcat中server.xml中配置的connector中指定的ip是192.168开头的内部地址,所以通过外网ip获取请求时出错。需要注意的是当使用server=servlet时,port要和外置容器的port一致,而且contextpath要以外置容器的访问路径保持正确的关系,比如我这里是HSFServiceA,那么contextpath要以HSFServiceA开头。
<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"
xmlns:context="http://www.springframework.org/schema/context"
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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="HSFServiceA"/>
<!-- 使用zookeeper统一管理 -->
<dubbo:registry protocol="zookeeper" address="192.168.136.129:2181" />
<!-- 不同协议在不同端口暴露服务 -->
<!-- <dubbo:protocol id="dubbo" name="dubbo" port="31106" accesslog="E:\\logs\\hsf\\hsfserverA.log" /> -->
<dubbo:protocol id="rest" name="rest" port="8080" server="servlet" contextpath="HSFServiceA" accesslog="E:\\logs\\hsf\\hsfserverA.log"/>
<bean id="ServiceAImpl" class="com.services.impl.ServiceAImpl" ></bean>
<dubbo:service interface="com.services.ServiceA" ref="ServiceAImpl" loadbalance="random" timeout="30000" executes="10" >
</dubbo:service>
</beans>
最近在使用dubbox作开发,发布为rest服务,服务起动进使用server=servlet这个模式,但是在调用时怎么也调用不通,所以一直在找原因,上面是服务的xml配置文件,下面是调用者的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"
xmlns:context="http://www.springframework.org/schema/context"
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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="HSFClient" />
<!-- 注册中心地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.136.129:2181" />
<dubbo:protocol id="rest" name="rest" />
<!-- 生成远程服务代理,可以和本地bean一样使用 -->
<dubbo:reference id="ServiceA" interface="com.services.ServiceA" />
</beans>
最后发现是tomcat中server.xml中配置的connector中指定的ip是192.168开头的内部地址,所以通过外网ip获取请求时出错。需要注意的是当使用server=servlet时,port要和外置容器的port一致,而且contextpath要以外置容器的访问路径保持正确的关系,比如我这里是HSFServiceA,那么contextpath要以HSFServiceA开头。
相关文章推荐
- 基于注解的spring+dubbo发布一个简单的helloWord服务及调用
- dubbox rest调用过程分析
- dubbo 源码学习笔记 (二) —— dubbo发布服务的过程
- 当当网开源Dubbox,扩展Dubbo服务框架支持REST风格远程调用
- 当当网开源Dubbox,扩展Dubbo服务框架支持REST风格远程调用
- 手机调用ArcGIS Server发布的Rest地图服务不显示问题
- java调用arcgis soe发布的rest服务,中文传值乱码问题
- CXF系列之JAX-RS:CXF发布与调用REST服务
- dubbo源码解析(六) dubbo服务发布过程及本地暴露
- dubbo版本2.8.4 消费者远程调用过程
- 通过 Jersey 客户端 API 调用 REST 风格的 Web 服务
- arcgis开发笔记【silverlight 发布rest地图服务】
- 在Dubbo中开发REST风格的远程调用(RESTful Remoting)(转)
- GeoServer基础教程(五):使用OpenLayers调用GeoServer发布的地图服务
- 部署在WildFly上的EJB客户端,调用另一个WildFly上的EJB服务的过程详解
- Silverlight调用GP服务第二篇之调用GP服务(Geoprocessing Service)过程详解
- Dubbo源码分析之四:服务的调用
- spring-cxf集成rest实现webservice以及调用过程
- 被事务代理的spring service 不能使用注解方式发布dubbo服务
- 使用Zipkin和Brave 实现dubbo服务调用跟踪