微服务注册之八轨忠读后小记

微服务发布的三种方式:restful api,xml配置,idl文件,其中idl不是很懂,也没想去研究本文主要记录xml的发布

restful风格,主要用于http请求的接口协议中,也就是我们常用的mvc接口定义。

XML配置主要分成三步:

1.服务提供者定义接口,并实现接口

接口定义:
public interface FooService {
public String hello(String name);
}

接口实现
public FooServiceImpl implements FooService

{
public String hello (String name){

System.out.println(name + "invoked rpc service ");
return "hello :" + name;
}
}

2.服务提供者进程启动,通过加载server.xml 配置文件将接口暴露出去

<!-- service implemention bean-->
<bean id="serviceImpl" class="quickstart.FooServiceImpl"/>
<!-- exporting service by motan-->
<motan:service interface="quickstart.FooService" ref="serviceImpl" export="8002"/>

3.服务消费者进程启动,通过加载client.xml配置文件引入需要的调用的接口

<!-- reference to the remote service -->
<motan:referr id = "remoteService" interface="quickstart.FooService" directUrl="localhost:8002"/>

 

二/如何发现和注册服务之zookeeper的实现原理

zookeeper由注册中心(registry) ,服务提供者(service),客户端服务消费者(client)

registry 
服务提供者:拥有服务注册接口,销毁接口,心跳接口(ping server跟registry是否存活)
服务消费者:订阅接口,服务变更查询接口
。。。
通常都是以集群的形式去搭建zookeeper集群,zookeeper有自己的选举机制,会选择一个leader,主要负责处理数据更新同步,使得各个server中数据一致。



posted @ 2018-11-16 00:05  霖仔  阅读(114)  评论(0编辑  收藏  举报