1.添加配置文件:server.properties
DataCenter=beijing
ClusterName=search
LocalName=xiaoming
ZeromqPath=/Volumes/workspace/yundiz/cloud.cluster/lib/zeromq/
DebugMode=TRUE
EnableDubbo=TRUE
DebugEtcdEndPoint=http://192.168.6.72:2379
EtcdEndPoint=http://192.168.100.126:2379
DebugZooConnectString=192.168.6.1:2181
# 应用名
dubbo.application.name=demo
# 注册中心地址
dubbo.registry.address=192.168.6.1:2181
dubbo.registry.protocol=zookeeper
# 调用协议地址
dubbo.protocol.name=dubbo
2. 添加microservice的注解
2.1 在Service接口上添加注解:@org.x3.annotation.Service
2.2 在每个方法上添加注解:@org.x3.annotation.Method
如果是http协议的接口,可以添加path、command等相关参数。 例:
@Method(path="/appList", command = "get")
String test9(@Param(name = "value") String value);
2.3 在方法的参数上添加注解:@org.x3.annotation.Param(name="参数名")
3. 删除Service实现类上的注解:@com.alibaba.dubbo.config.annotation.Service
3. 启动服务
import org.x3.rpc.ServiceDict;
import org.x3.rpc.ServiceFactory;
import org.x3.rpc.common.Context;
/**
* Created by liuquan on 2017/10/27.
*/
public class Main {
public static void main(String[] args) {
ServiceDict.init();
ServiceFactory.registerContext(AppContext.class);
ServiceFactory.loadServices();
AppServer.startup("demo");
}
}
class AppContext extends Context {
@Override
public void init(String cookieId) {
System.out.println("cookieId=" + cookieId);
}
}