DUBBO API 服务
更新时间:
网关提供服务端 DUBBO Demo 代码供用户下载测试,下载 API 提供者 Demo 后,DUBBO Demo 接口位置为:com.alipay.gateway.dubbo.DubboServiceImpl。
说明
DUBBO 和 DUBBOX 的使用方法一致,只需根据协议引入正确的 DUBBO 依赖即可。
DUBBO 服务 Demo
public class DubboServiceImpl implements DubboService {
@Override
public Map<String, String> booleanParam(Boolean booleanParam) {
Map map = new HashMap();
map.put("boolean", "hello " + booleanParam);
return map;
}
@Override
public Map<String, String> byteParam(Byte byteParam) {
Map map = new HashMap();
map.put("byte", "hello " + byteParam);
return map;
}
@Override
public Map<String, String> charParam(Character charParam) {
Map map = new HashMap();
map.put("char", "hello " + charParam);
return map;
}
@Override
public Map<String, String> shortParam(Short shortParam) {
Map map = new HashMap();
map.put("short", "hello " + shortParam);
return map;
}
@Override
public Map<String, String> intParam(Integer intParam) {
Map map = new HashMap();
map.put("int", "hello " + intParam);
return map;
}
@Override
public Map<String, String> longParam(Long longParam) {
Map map = new HashMap();
map.put("long", "hello " + longParam);
return map;
}
@Override
public Map<String, String> floatParam(Float floatParam) {
Map map = new HashMap();
map.put("float", "hello " + floatParam);
return map;
}
@Override
public Map<String, String> doubleParam(Double doubleParam) {
Map map = new HashMap();
map.put("double", "hello " + doubleParam);
return map;
}
@Override
public Map<String, String> noParam() {
Map map = new HashMap();
map.put("zym", "hello");
return map;
}
@Override
public Person personParam(Person person) {
return person;
}
@Override
public Map<String, String> stringParam(String param) {
Map map = new HashMap();
map.put("string", "hello " + param);
return map;
}
}
public interface DubboService {
public Map<String, String> booleanParam(Boolean booleanParam);
public Map<String, String> byteParam(Byte byteParam);
public Map<String, String> charParam(Character charParam);
public Map<String, String> shortParam(Short shortParam);
public Map<String, String> intParam(Integer intParam);
public Map<String, String> longParam(Long longParam);
public Map<String, String> floatParam(Float floatParam);
public Map<String, String> doubleParam(Double doubleParam);
public Map<String, String> noParam();
public Person personParam(Person person);
public Map<String, String> stringParam(String param);
}
发布服务
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="${spring.application.name}"/>
<!-- 声明需要暴露的服务接口(注意是接口,不是实现类)
这里是具体实现类,id和上面的暴露的服务接口ref要一致,dubbo就是通过这个来注册对应的服务
同模块的registry使用local,不同模块的使用远程的register -->
<dubbo:registry id="register" address="zookeeper://${zookeeper.address}:2181"/>
<dubbo:protocol serialization="fastjson" name="dubbo" port="20881" />
<bean id="dubboService" class="com.alipay.gateway.dubbo.DubboServiceImpl"/>
<dubbo:service version="2.0.0" registry="register"
interface="com.alipay.gateway.facade.dubbo.DubboService"
ref="dubboService" protocol="dubbo" group="zym_group" />
</beans>
文档内容是否对您有帮助?