The invention provides a distributed service registration method and device. The method includes: performing the following steps regularly in the form of a daemon process: parsing the local configuration file of the target application, obtaining an HTTP interface for obtaining the corresponding service information of the target application, and initiating an HTTP request to the target application according to the HTTP interface in order to obtain the target application. The corresponding service information transforms the service information into service registration information and writes the service registration information into the distributed storage node. The distributed service registration method and device provided by the invention provides a unified service registration model for distributed services in different languages. The application requiring service registration only needs to provide an HTTP interface to obtain service information. It belongs to the registration mode outside the application and is separated from the application program, thus avoiding the shortcomings of the internal registration mode in the application.
【技术实现步骤摘要】
一种分布式服务注册方法及装置
本专利技术涉及软件工程领域,更具体地,涉及一种分布式服务注册方法及装置。
技术介绍
在微服务架构生态系统中,服务的注册和发现是基础支撑。服务的注册就是将微服务的运行信息写入到存储节点或集群,服务发现就是从存储节点或集群读取微服务的运行信息。基于分布式服务的服务信息,服务网关可实现负载均衡功能,应用管理中心可实现应用运行的监控。目前实现服务注册的常用方案是在应用内实现服务注册,即开发人员将服务注册功能以工具包的方式提供给应用程序,然后应用程序通过主动调用服务注册功能来完成服务信息的注册。但应用内实现服务注册这种方案会有如下不足:1)应用程序所采用的编程语言众多,如c++、php、java、go等,需要为每种语言都提供服务注册功能的工具包,并进行持续维护,成本很高;2)服务注册工具包的升级困难,因为这会造成依赖工具包的应用程序更新工具包版本,并且测试重新发布,在实践中,这是很困难的。
技术实现思路
为了解决应用内服务注册的方式所存在的以上问题,本专利技术提供一种分布式服务注册方法及装置。根据本专利技术的一个方面,提供一种分布式服务注册方法,以守护进程的形式定时执行以下步骤:S1,对目标应用本地的配置文件进行解析,获得用于获取所述目标应用所对应的服务信息的http接口;S2,根据所述http接口向所述目标应用发起http请求,以获取所述目标应用所对应的服务信息;S3,将所述服务信息转换为服务注册信息,并将所述服务注册信息写入分布式存储节点。其中,步骤S1中所述用于获取所述目标应用所对应的服务信息的http接口包括:服务监听的本机端口和获 ...
【技术保护点】
1.一种分布式服务注册方法,其特征在于,以守护进程的形式定时执行以下步骤:S1,对目标应用本地的配置文件进行解析,获得用于获取所述目标应用所对应的服务信息的http接口;S2,根据所述http接口向所述目标应用发起http请求,以获取所述目标应用所对应的服务信息;S3,将所述服务信息转换为服务注册信息,并将所述服务注册信息写入分布式存储节点。
【技术特征摘要】
1.一种分布式服务注册方法,其特征在于,以守护进程的形式定时执行以下步骤:S1,对目标应用本地的配置文件进行解析,获得用于获取所述目标应用所对应的服务信息的http接口;S2,根据所述http接口向所述目标应用发起http请求,以获取所述目标应用所对应的服务信息;S3,将所述服务信息转换为服务注册信息,并将所述服务注册信息写入分布式存储节点。2.根据权利要求1所述的方法,其特征在于,步骤S1中所述用于获取所述目标应用所对应的服务信息的http接口包括:服务监听的本机端口和获取所述目标应用运行状态的httpuri接口。3.根据权利要求2所述的方法,其特征在于,所述步骤S2进一步包括:根据所述http接口所包含的信息构造完整的httpurl地址,并向所述httpurl地址发起获取所述目标应用所对应的服务信息的http请求。4.根据权利要求3所述的方法,其特征在于,所述目标应用所对应的服务信息包括:所述目标应用的名称、所述目标应用的实例、所述目标应用的版本信息和可自定义的扩展信息。5.根据权利要求1所述的方法,其特征在于,所述服务注册信息包括:所述目标应用的名称、所述目标应用的ID、所述目标应用的版本信息、所述目标应用所在的IP地址、所述目标应用所在的主机名和可自定义的扩展信息。...
【专利技术属性】
技术研发人员:支猛,张文明,陈少杰,
申请(专利权)人:武汉斗鱼网络科技有限公司,
类型:发明
国别省市:湖北,42
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。