[go: up one dir, main page]

CN107181675B - Service invocation method and device - Google Patents

Service invocation method and device Download PDF

Info

Publication number
CN107181675B
CN107181675B CN201710469894.2A CN201710469894A CN107181675B CN 107181675 B CN107181675 B CN 107181675B CN 201710469894 A CN201710469894 A CN 201710469894A CN 107181675 B CN107181675 B CN 107181675B
Authority
CN
China
Prior art keywords
service
calling
invocation
request
identifier
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710469894.2A
Other languages
Chinese (zh)
Other versions
CN107181675A (en
Inventor
梁云龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201710469894.2A priority Critical patent/CN107181675B/en
Publication of CN107181675A publication Critical patent/CN107181675A/en
Application granted granted Critical
Publication of CN107181675B publication Critical patent/CN107181675B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/66Arrangements for connecting between networks having differing types of switching systems, e.g. gateways
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/146Markers for unambiguous identification of a particular session, e.g. session cookie or URL-encoding

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Computer And Data Communications (AREA)

Abstract

本发明提供了一种服务调用方法及装置,服务网关接收服务调用请求并将该服务调用请求发送给相应的服务提供端;以及,由服务网关将服务提供端返回的响应结果返回给服务调用端。其中,服务调用请求中包含唯一标示当前调用链路的调用标识,且该调用标识在整个调用链路中的各个服务提供端间传递。每个服务调用请求和调用结果都需要经过服务网关转发,因此,服务网关能够获取所有服务调用对应的调用信息。因此,从该调用信息中查找该调用标识所对应的服务调用链路。该方法只需要在服务网关上设置埋点进行采样即可,不需要在客户端和服务端都设置埋点,因此,大大降低了服务的客户端和服务端的开发、部署成本。

Figure 201710469894

The invention provides a service invocation method and device. The service gateway receives the service invocation request and sends the service invocation request to the corresponding service provider; and the service gateway returns the response result returned by the service provider to the service invocation end. . Wherein, the service invocation request includes an invocation identifier that uniquely identifies the current invocation link, and the invocation identifier is passed between each service provider in the entire invocation link. Each service invocation request and invocation result need to be forwarded by the service gateway. Therefore, the service gateway can obtain invocation information corresponding to all service invocations. Therefore, the service invocation link corresponding to the invocation identifier is searched from the invocation information. This method only needs to set buried points on the service gateway for sampling, and does not need to set buried points on both the client and the server. Therefore, the development and deployment costs of the client and the server of the service are greatly reduced.

Figure 201710469894

Description

服务调用方法及装置Service invocation method and device

技术领域technical field

本发明属于计算机领域,尤其涉及一种服务调用方法及装置。The invention belongs to the field of computers, and in particular relates to a service invocation method and device.

背景技术Background technique

目前,互联网公司的系统通常由大量提供不同功能的子系统采用微服务的架构组成。微服务是指开发多个独立小型、但有完整业务功能的服务,每个服务都有自己的处理和通讯机制,可以部署在单个或多个服务器上。At present, the system of Internet companies usually consists of a large number of subsystems that provide different functions using a microservice architecture. Microservices refer to the development of multiple independent and small services with complete business functions. Each service has its own processing and communication mechanism and can be deployed on a single or multiple servers.

微服务架构中存在大量的微服务,而且,微服务之间存在复杂的调用关系,因此,开发者很难搞清楚整个系统所包含的各个微服务之间的调用关系,而且,当整个调用链出现性能瓶颈时,很难定位出现问题的服务组件。There are a large number of microservices in the microservice architecture, and there are complex calling relationships between microservices. Therefore, it is difficult for developers to figure out the calling relationship between the various microservices included in the whole system. When a performance bottleneck occurs, it can be difficult to locate the faulty service component.

针对上述问题,传统的解决方案是:在每个微服务的客户端和服务端分别进行埋点采样,最后综合所有的采样数据分析得出系统的服务调用链路,但这样的方式会给每个微服务的客户端和服务端带来开发和部署压力,并且不同的微服务提供方难以协调出统一的埋点采样方案。In response to the above problems, the traditional solution is to perform buried point sampling on the client and server of each microservice, and finally analyze all the sampled data to obtain the service call link of the system. The client and server of each microservice bring development and deployment pressure, and it is difficult for different microservice providers to coordinate a unified buried point sampling plan.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明的目的在于提供一种服务调用方法及装置,以解决传统解决方案存在的微服务的客户端和服务端开发和部署难,以及,不同的服务提供方难以统一埋点采样的技术问题。本发明的技术方案如下:In view of this, the purpose of the present invention is to provide a service invocation method and device, so as to solve the difficulty of client and server development and deployment of microservices existing in traditional solutions, and it is difficult for different service providers to unify buried point sampling technical issues. The technical scheme of the present invention is as follows:

第一方面,本申请提供一种服务调用方法,应用于服务网关中,该方法包括:In a first aspect, the present application provides a service invocation method, which is applied in a service gateway, and the method includes:

接收服务调用请求,所述服务调用请求包括服务调用端标识、服务名称和调用标识,所述调用标识用于唯一标示所述服务调用请求所对应的服务调用链路;Receive a service invocation request, where the service invocation request includes a service invocation terminal identifier, a service name and an invocation identifier, and the invocation identifier is used to uniquely identify a service invocation link corresponding to the service invocation request;

根据所述服务名称将所述服务调用请求发送给相应的服务提供端;sending the service invocation request to the corresponding service provider according to the service name;

接收所述服务提供端返回的调用结果,并将所述调用结果发送给服务调用端;Receive the call result returned by the service provider, and send the call result to the service caller;

获取所述服务调用请求对应的调用信息,以使调用分析端分析所述调用信息中的服务调用端标识、服务提供端标识和所述调用标识获得与所述调用标识对应的服务调用链路。Acquire the invocation information corresponding to the service invocation request, so that the invocation analysis terminal analyzes the service invocation terminal identification, the service provider identification and the invocation identification in the invocation information to obtain a service invocation link corresponding to the invocation identification.

可选地,所述调用信息还包括调用时间信息,所述调用时间信息包括调用耗时;获取所述调用耗时的过程包括:Optionally, the invocation information further includes invocation time information, and the invocation time information includes invocation time-consuming; the process of acquiring the invocation time-consuming includes:

记录接收到所述服务调用请求的第一时间戳,以及,记录接收到所述调用请求对应的调用结果的第二时间戳;recording the first timestamp of receiving the service invocation request, and recording the second timestamp of receiving the invocation result corresponding to the invocation request;

计算所述第二时间戳与所述第一时间戳的时间差,得到每个服务的调用耗时。Calculate the time difference between the second time stamp and the first time stamp to obtain the calling time of each service.

可选地,所述接收服务调用请求包括:Optionally, the receiving a service invocation request includes:

接收客户端发送的所述服务调用请求;receiving the service invocation request sent by the client;

或者,or,

接收第一服务提供端发送的调用第二服务提供端的服务调用请求。Receive a service invocation request sent by the first service provider to invoke the second service provider.

第二方面,本申请还提供另一种服务调用方法,应用于服务提供端,该方法包括:In the second aspect, the present application also provides another service invocation method, which is applied to the service provider, and the method includes:

第一服务提供端接收服务网关转发的第一调用请求,所述第一调用请求包括第一服务调用端标识、第一服务名称和调用标识,所述调用标识用于唯一标示所述服务调用请求所对应的服务调用链路;The first service provider receives the first call request forwarded by the service gateway, where the first call request includes a first service caller identifier, a first service name and a call identifier, and the call identifier is used to uniquely identify the service call request The corresponding service call link;

所述第一服务提供端解析所述第一调用请求得到所述第一调用请求所需调用的第二服务名称,以及所述调用标识;The first service provider parses the first invocation request to obtain the second service name to be invoked by the first invocation request, and the invocation identifier;

所述第一服务提供端根据所述第二服务名称生成第二调用请求,所述第二调用请求包括第二服务调用端标识、第二服务名称和所述调用标识;The first service provider generates a second call request according to the second service name, where the second call request includes a second service caller identifier, a second service name, and the call identifier;

所述第一服务提供端将所述第二调用请求发送给所述服务网关,以使所述服务网关将所述第二调用请求转发给第二服务提供端,所述第二服务提供端提供所述第二服务名称对应的服务;以及,使所述服务网关获得调用信息,并由调用分析端根据所述调用信息获得与所述调用标识对应的服务调用链路。The first service provider sends the second invocation request to the service gateway, so that the service gateway forwards the second invocation request to the second service provider, and the second service provider provides the service corresponding to the second service name; and, enabling the service gateway to obtain invocation information, and the invocation analysis terminal obtains the service invocation link corresponding to the invocation identifier according to the invocation information.

可选地,所述方法还包括:Optionally, the method further includes:

所述第一服务提供端通过所述服务网关接收所述第二服务提供端返回的第二调用结果,所述第二调用结果由所述第二服务提供端响应所述第二调用请求得到;The first service provider receives the second invocation result returned by the second service provider through the service gateway, and the second invocation result is obtained by the second service provider in response to the second invocation request;

所述第一服务提供端根据所述第二调用结果响应所述第一调用请求,生成第一调用结果,并将所述第一调用结果通过所述服务网关转发给发起所述第一调用请求的第一服务调用端。The first service provider responds to the first invocation request according to the second invocation result, generates a first invocation result, and forwards the first invocation result to initiating the first invocation request through the service gateway The first service caller of .

第三方面,本申请提供一种服务调用装置,应用于服务网关中,所述装置包括:In a third aspect, the present application provides a service invocation apparatus, which is applied in a service gateway, and the apparatus includes:

第一接收单元,用于接收服务调用请求,所述服务调用请求包括服务调用端标识、服务名称和调用标识,所述调用标识用于唯一标示所述服务调用请求所对应的服务调用链路;a first receiving unit, configured to receive a service invocation request, where the service invocation request includes a service invocation terminal identifier, a service name and an invocation identifier, and the invocation identifier is used to uniquely identify a service invocation link corresponding to the service invocation request;

第一发送单元,用于根据所述服务名称将所述服务调用请求发送给相应的服务提供端;a first sending unit, configured to send the service invocation request to a corresponding service provider according to the service name;

第二接收单元,用于接收所述服务提供端返回的调用结果;a second receiving unit, configured to receive the calling result returned by the service provider;

第二发送单元,用于将所述调用结果发送给服务调用端;a second sending unit, configured to send the calling result to the service calling end;

获取单元,用于获取所述服务调用请求对应的调用信息,以使调用分析端分析所述调用信息中的服务调用端标识、服务提供端标识和所述调用标识获得与所述调用标识对应的服务调用链路。The acquiring unit is configured to acquire the invocation information corresponding to the service invocation request, so that the invocation analysis terminal analyzes the service invocation terminal identification, the service provider identification and the invocation identification in the invocation information to obtain the corresponding invocation identification. Service call link.

可选地,所述调用信息还包括调用时间信息,所述调用时间信息包括调用耗时,所述获取单元包括:Optionally, the invocation information further includes invocation time information, and the invocation time information includes invocation time-consuming, and the acquiring unit includes:

第一记录子单元,用于记录接收到所述服务调用请求的第一时间戳;a first recording subunit, configured to record the first timestamp of receiving the service invocation request;

第二记录子单元,用于记录接收到所述调用请求对应的调用结果的第二时间戳;a second recording subunit, configured to record the second timestamp of receiving the invocation result corresponding to the invocation request;

计算子单元,用于计算所述第二时间戳与所述第一时间戳的时间差,得到每个服务对应的调用耗时。A calculation subunit, configured to calculate the time difference between the second time stamp and the first time stamp, and obtain the invocation time corresponding to each service.

可选地,所述第一接收单元具体用于:Optionally, the first receiving unit is specifically configured to:

接收客户端发送的所述服务调用请求;receiving the service invocation request sent by the client;

或者,or,

接收第一服务提供端发送的调用第二服务提供端的服务调用请求。Receive a service invocation request sent by the first service provider to invoke the second service provider.

第四方面,本申请提供一种服务调用装置,应用于服务提供端,该装置包括:In a fourth aspect, the present application provides a service invocation device, which is applied to a service provider, and the device includes:

第一接收单元,用于使第一服务提供端接收服务网关转发的第一调用请求,所述第一调用请求包括第一服务调用端标识、第一服务名称和调用标识,所述调用标识用于唯一标示所述服务调用请求所对应的服务调用链路;The first receiving unit is configured to enable the first service provider to receive the first invocation request forwarded by the service gateway, where the first invocation request includes the first service invocation terminal identifier, the first service name and the invocation identifier, and the invocation identifier is to uniquely identify the service invocation link corresponding to the service invocation request;

第一解析单元,用于使所述第一服务提供端解析所述第一调用请求得到所述第一调用请求所需调用的第二服务名称,以及所述调用标识;a first parsing unit, configured to enable the first service provider to parse the first invocation request to obtain the second service name and the invocation identifier to be invoked by the first invocation request;

请求生成单元,用于使所述第一服务提供端根据所述第二服务名称生成第二调用请求,所述第二调用请求包括第二服务调用端标识、第二服务名称和所述调用标识;A request generating unit, configured to enable the first service provider to generate a second invocation request according to the second service name, where the second invocation request includes a second service invocation terminal identifier, a second service name and the invocation identifier ;

第一发送单元,用于使所述第一服务提供端将所述第二调用请求发送给所述服务网关,以使所述服务网关将所述第二调用请求转发给第二服务提供端,所述第二服务提供端提供所述第二服务名称对应的服务;以及,使所述服务网关获得调用信息,并由调用分析端根据所述调用信息获得与所述调用标识对应的服务调用链路。a first sending unit, configured to make the first service provider send the second invocation request to the service gateway, so that the service gateway forwards the second invocation request to the second service provider, The second service provider provides the service corresponding to the second service name; and the service gateway obtains invocation information, and the invocation analysis end obtains the service invocation chain corresponding to the invocation identifier according to the invocation information road.

可选地,所述装置还包括:Optionally, the device further includes:

第二接收单元,用于使所述第一服务提供端通过所述服务网关接收所述第二服务提供端返回的第二调用结果,所述第二调用结果由所述第二服务提供端响应所述第二调用请求得到;a second receiving unit, configured to enable the first service provider to receive a second invocation result returned by the second service provider through the service gateway, and the second invocation result is responded by the second service provider The second invocation request is obtained;

响应单元,用于使所述第一服务提供端根据所述第二调用结果响应所述第一调用请求,生成第一调用结果,并将所述第一调用结果通过所述服务网关转发给发起所述第一调用请求的第一服务调用端。A response unit, configured to make the first service provider respond to the first invocation request according to the second invocation result, generate a first invocation result, and forward the first invocation result to the initiator through the service gateway The first service calling end of the first calling request.

本实施例提供的服务调用方法,服务网关接收服务调用请求,服务网关根据服务名称将该服务调用请求发送给相应的服务提供端,服务调用请求中包含唯一标示当前调用链路的调用标识,且该调用标识在整个调用链路中的各个服务提供端间传递;每个服务调用请求和调用结果都需要经过网关进行转发,因此,服务网关能够获取所有服务调用对应的调用信息。调用信息包括服务调用端标识、服务提供端标识、调用标识和调用时间信息,因此,从该调用信息中查找该调用标识所对应的服务调用端标识和服务提供端标识能够获得该调用标识对应的服务调用链路。该方法只需要在服务网关上设置埋点进行采样即可,不需要在客户端和服务端都设置埋点,因此,大大降低了每个服务的客户端和服务端的开发、部署成本。In the service invocation method provided in this embodiment, the service gateway receives the service invocation request, the service gateway sends the service invocation request to the corresponding service provider according to the service name, and the service invocation request includes the invocation identifier that uniquely identifies the current invocation link, and The call identifier is passed between each service provider in the entire call chain; each service call request and call result need to be forwarded through the gateway, so the service gateway can obtain call information corresponding to all service calls. The call information includes the service caller identifier, the service provider identifier, the call identifier, and the call time information. Therefore, searching for the service caller identifier and the service provider identifier corresponding to the call identifier from the call information can obtain the corresponding call identifier. Service call link. This method only needs to set buried points on the service gateway for sampling, and does not need to set buried points on both the client and the server. Therefore, the development and deployment costs of the client and server of each service are greatly reduced.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are For some embodiments of the present invention, for those of ordinary skill in the art, other drawings can also be obtained according to these drawings without creative efforts.

图1示出了一种典型的微服务架构的示意图;Figure 1 shows a schematic diagram of a typical microservice architecture;

图2示出了本发明实施例一种服务调用系统的示意图;2 shows a schematic diagram of a service invocation system according to an embodiment of the present invention;

图3示出了本发明实施例一种服务调用方法的流程图;3 shows a flowchart of a service invocation method according to an embodiment of the present invention;

图4示出了本发明实施例另一种服务调用方法的流程图;FIG. 4 shows a flowchart of another service invocation method according to an embodiment of the present invention;

图5示出了本申请实施例一种服务调用装置的框图;FIG. 5 shows a block diagram of an apparatus for invoking a service according to an embodiment of the present application;

图6示出了本申请实施例一种获取单元的框图;FIG. 6 shows a block diagram of an acquisition unit according to an embodiment of the present application;

图7示出了本申请实施例另一种服务调用装置的框图。FIG. 7 shows a block diagram of another service invocation apparatus according to an embodiment of the present application.

具体实施方式Detailed ways

在详细介绍本发明的技术方案之前,首先介绍下微服务构架:Before introducing the technical solution of the present invention in detail, first introduce the microservice architecture:

微服务是指开发多个独立小型但有完整业务功能的服务,每个服务都有自己的处理和通讯机制,可以部署在单个或多个服务器上。微服务架构的思想和理念如下:把系统解耦成更小的单元;每个单元都有自己的职责;每个单元通过应用程序编程接口(Application Programming Interface,API)暴露,外界不需要关心它的具体实现;所有的单元都是独立的,可以独立的进行开发、部署、扩展以及监控;各个单元之间可以通过远程过程调用协议(Remote Procedure Call Protocol,RPC)请示进行交互。Microservices refer to the development of multiple independent and small services with complete business functions. Each service has its own processing and communication mechanism and can be deployed on a single or multiple servers. The ideas and concepts of the microservice architecture are as follows: decouple the system into smaller units; each unit has its own responsibilities; each unit is exposed through an application programming interface (API), and the outside world does not need to care about it All units are independent and can be developed, deployed, extended and monitored independently; each unit can interact with each other through the Remote Procedure Call Protocol (RPC).

在微服务架构中客户端与服务端需要服务网关装置进行交互,服务网关作为系统的入口,它会负责服务请求路由、组合及协议转换等。另外,还需要对接入客户端的身份认证、防报文重放与防数据篡改、功能调用的业务鉴权、响应数据的脱敏、流量与并发控制,甚至基于API调用的计量或计费。In the microservice architecture, the client and the server need to interact with the service gateway device. As the entrance of the system, the service gateway is responsible for service request routing, composition, and protocol conversion. In addition, identity authentication of access clients, anti-message replay and anti-data tampering, service authentication of function calls, desensitization of response data, traffic and concurrency control, and even metering or billing based on API calls are also required.

如图1所示,示出了一种典型的微服务架构,该微服务系统包括六个微服务分别是:A、B、C、D、E和F。例如,该微服务系统中包含3个微服务路由:新用户注册由微服务A,B,C和E实现,其中,微服务之间的调用关系是A调用B,B调用C,C调用E;下订单由微服务A,B,C和D实现;支付由微服务A,B,C,D和F实现。As shown in Figure 1, a typical microservice architecture is shown. The microservice system includes six microservices: A, B, C, D, E, and F. For example, the microservice system contains 3 microservice routes: new user registration is implemented by microservices A, B, C and E, where the calling relationship between microservices is that A calls B, B calls C, and C calls E ; placing an order is implemented by microservices A, B, C and D; payment is implemented by microservices A, B, C, D and F.

在微服务架构中,微服务之间存在着复杂的调用关系,导致系统的开发者都很难搞清楚整个微服务系统中微服务之间的调用关系,当整个调用链路出现性能瓶颈时,很难定位出问题出在哪个节点上。本申请提供的服务调用方法,在服务网关中设置埋点采样,服务网关负责服务请求路由,每一次服务调用都需要经过服务网关,因此,服务网关能够采样到每个服务调用的调用信息,例如,调用关系、调用耗时等。然后,分析服务网关采集到的调用信息。In the microservice architecture, there is a complex calling relationship between microservices, which makes it difficult for system developers to figure out the calling relationship between microservices in the entire microservice system. When a performance bottleneck occurs in the entire calling chain, It's hard to pinpoint which node is the problem. In the service invocation method provided by this application, buried point sampling is set in the service gateway, the service gateway is responsible for service request routing, and each service invocation needs to go through the service gateway. Therefore, the service gateway can sample the invocation information of each service invocation, such as , call relationship, call time, etc. Then, analyze the call information collected by the service gateway.

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments These are some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

请参见图2,示出了本发明实施例一种服务调用系统的示意图,如图2所示,该系统包括服务调用端1、服务网关2、服务提供端3、日志收集器4和调用分析端5。Please refer to FIG. 2, which shows a schematic diagram of a service invocation system according to an embodiment of the present invention. As shown in FIG. 2, the system includes a service invocation terminal 1, a service gateway 2, a service provider 3, a log collector 4, and an invocation analysis terminal. end 5.

服务调用端1,用于向服务网关发送服务调用请求,并且每次服务调用请求中都包含用于唯一标示当前调用链路的调用标识。The service invocation terminal 1 is used to send a service invocation request to the service gateway, and each service invocation request includes an invocation identifier for uniquely marking the current invocation link.

服务网关2,用于将服务调用路由到正确的服务提供端,并记录本次调用的调用信息,其中,调用信息包括调用标识、服务调用端标识、服务提供端标识。The service gateway 2 is used to route the service call to the correct service provider, and record the call information of this call, wherein the call information includes the call identifier, the service caller identifier, and the service provider identifier.

服务提供端3,用于接收并处理第一服务调用请求,如果服务提供端需要再次发起服务调用,则产生第二服务调用请求,且该第二服务调用请求中携带第一服务调用请求中所包含的调用标识,调用标识依次传递下去,直到本次调用的最后一个服务提供端。The service provider 3 is used to receive and process the first service invocation request. If the service provider needs to initiate a service invocation again, a second service invocation request is generated, and the second service invocation request carries the information in the first service invocation request. Included call identifier, the call identifier is passed in sequence until the last service provider of this call.

日志收集器4,用于收集服务网关采样得到的调用信息,并将调用信息发送给调用分析端5。The log collector 4 is used to collect the call information sampled by the service gateway, and send the call information to the call analysis terminal 5 .

在本发明的一种可能的实现方式中,日志收集器4可以部署在服务网关所在的设备中;In a possible implementation manner of the present invention, the log collector 4 may be deployed in the device where the service gateway is located;

在本发明的另一种可能的实现方式中,日志收集器4可以部署在除服务网关之外的设备中,此种应用场景中,日志收集器4需要知道服务网关的地址,并从服务网关中获得调用信息。In another possible implementation manner of the present invention, the log collector 4 may be deployed in a device other than the service gateway. In this application scenario, the log collector 4 needs to know the address of the service gateway, and obtains the information from the service gateway. to get call information.

调用分析端5,分析日志收集器收集到的调用信息,确定包含同一调用标识的所有调用请求属于同一调用链路,根据各个不同的调用链路得到该服务系统的服务拓扑。以及,获得各个调用请求对应调用耗时,根据调用耗时确定服务系统的性能瓶颈。其中,调用耗时是指从发起服务调用到得到所述服务的响应所需的时间。The invocation analysis terminal 5 analyzes the invocation information collected by the log collector, determines that all invocation requests including the same invocation identifier belong to the same invocation link, and obtains the service topology of the service system according to different invocation links. And, the call time corresponding to each call request is obtained, and the performance bottleneck of the service system is determined according to the call time. Wherein, the invocation time-consuming refers to the time required from initiating a service invocation to obtaining a response from the service.

请参见图3,示出了本发明实施例一种服务调用方法的流程图,该方法应用于服务网关中,如图3所示,该方法可以包括:Referring to FIG. 3 , a flowchart of a method for invoking a service according to an embodiment of the present invention is shown. The method is applied to a service gateway. As shown in FIG. 3 , the method may include:

S110,服务网关接收服务调用请求。S110, the service gateway receives the service invocation request.

服务网关接收服务调用端发送的服务调用请求,该服务调用请求包括服务调用端标识、服务名称和调用标识,该调用标识用于唯一标示服务调用请求所对应的调用链路。The service gateway receives the service invocation request sent by the service invocation end, the service invocation request includes the service invocation end identification, the service name and the invocation identification, and the invocation identification is used to uniquely identify the invocation link corresponding to the service invocation request.

服务调用端是发起该服务调用请求的一方,服务调用端标识可以是能够唯一标识该服务调用端的标识信息,例如,媒体访问控制(Medium Access Control,MAC)地址。The service invocation end is the party that initiates the service invocation request, and the service invocation end identifier may be identification information that can uniquely identify the service invocation end, for example, a media access control (Medium Access Control, MAC) address.

在本发明一种可能的实现方式中,服务调用端可以是客户端,即,客户端向服务网关发起服务调用请求的应用场景;In a possible implementation manner of the present invention, the service invoking end may be a client, that is, an application scenario in which the client initiates a service invocation request to the service gateway;

在本发明另一种可能的实现方式中,服务调用端可以是服务提供端,即,该服务提供端实现某个服务时,需要调用其它的服务,因此,需要向其它的服务提供端发送服务调用请求。In another possible implementation manner of the present invention, the service invoking end may be a service provider, that is, when the service provider implements a certain service, it needs to call other services, so it needs to send services to other service providers call request.

延用图1所示微服务构架的实例,当客户端发起新用户注册请求时,由客户端向服务网关发送“新用户注册”的服务调用请求,此种应用场景下,服务调用者(即,发送服务调用请求的一方)就是客户端;例如,新用户注册服务由A-B-C-E四个微服务实现,微服务A调用微服务B时,服务调用端就是微服务A的服务提供者。Extending the example of the microservice architecture shown in Figure 1, when the client initiates a new user registration request, the client sends a "new user registration" service call request to the service gateway. In this application scenario, the service caller (ie , the party that sends the service invocation request) is the client; for example, the new user registration service is implemented by four microservices A-B-C-E. When microservice A calls microservice B, the service invoking end is the service provider of microservice A.

调用标识用于唯一标示当前调用链路的标识,该调用标识由发起该服务调用的客户端产生,在实现该服务的服务调用链路中被不间断地传递下去。The call identifier is used to uniquely identify the identifier of the current call link, the call identifier is generated by the client that initiates the service call, and is continuously transmitted in the service call link that implements the service.

S120,服务网关根据服务名称将服务调用请求发送给相应的服务提供端。S120, the service gateway sends the service invocation request to the corresponding service provider according to the service name.

服务网关根据服务调用请求中包含的服务名称,找到提供该服务名称对应服务的服务提供端,并将该服务调用请求发送给该服务提供端。The service gateway finds the service provider that provides the service corresponding to the service name according to the service name included in the service invocation request, and sends the service invocation request to the service provider.

S130,服务网关接收服务提供端返回的调用结果,并将调用结果发送给服务调用端。S130, the service gateway receives the call result returned by the service provider, and sends the call result to the service caller.

服务提供端接收到服务调用请求后,如果不需要再调用其它服务,则响应该服务调用请求生成调用结果,并将调用结果返回给服务网关,服务网关再将接收到的调用结果返回给服务调用端。After the service provider receives the service call request, if it does not need to call other services, it will generate the call result in response to the service call request, and return the call result to the service gateway, and the service gateway will then return the received call result to the service call. end.

S140,服务网关获取所述服务调用请求对应的调用信息,以使调用分析端根据所述调用信息获得与所述调用标识对应的服务调用链路,所述调用信息包括所述服务调用端标识、服务提供端标识、所述调用标识和调用时间信息。S140: The service gateway acquires invocation information corresponding to the service invocation request, so that the invocation analysis terminal obtains a service invocation link corresponding to the invocation identifier according to the invocation information, where the invocation information includes the service invocation terminal identifier, Service provider identification, the invocation identification and invocation time information.

服务网关内设置埋点对整个服务调用过程进行采样,得到调用信息,该调用信息包括服务调用端标识、服务提供端标识、调用标识和调用时间信息。Buried points are set in the service gateway to sample the entire service invocation process to obtain invocation information. The invocation information includes service invocation end identification, service provider identification, invocation identification and invocation time information.

调用分析端分析服务网关获得的调用信息得到与该调用标识对应的调用数据,并最终得到本次服务调用的整个服务调用链路。The invocation analysis end analyzes the invocation information obtained by the service gateway to obtain invocation data corresponding to the invocation identifier, and finally obtains the entire service invocation link of this service invocation.

可选地,根据调用信息所包含的调用时间信息能够获得当前调用的调用耗时,获取所述调用耗时的过程包括:Optionally, the calling time-consuming of the current call can be obtained according to the calling time information included in the calling information, and the process of obtaining the calling time-consuming includes:

服务网关记录接收到调用请求的第一时间戳,以及,记录接收到该调用请求对应的调用结果的第二时间戳,计算第二时间戳与所述第一时间戳的时间差,得到每个服务调用的调用耗时。The service gateway records the first timestamp of receiving the invocation request, and records the second timestamp of receiving the invocation result corresponding to the invocation request, calculates the time difference between the second timestamp and the first timestamp, and obtains each service The invocation of the call is time consuming.

根据当前调用链路中各个调用所对应的调用耗时,计算得到整个调用链路的调用耗时,根据调用耗时能够分析得到服务系统的性能瓶颈。According to the call time corresponding to each call in the current call chain, the call time of the entire call chain is calculated, and the performance bottleneck of the service system can be analyzed according to the call time.

本实施例提供的服务跟踪方法,服务网关接收服务调用请求,服务网关根据服务名称将该服务调用请求发送给相应的服务提供端,服务调用请求中包含唯一标示当前调用链路的调用标识,且该调用标识在整个调用链路中的各个服务提供端间传递;每个服务调用请求和调用结果都需要经过网关进行转发,因此,服务网关能够获取所有服务调用对应的调用信息。调用信息包括服务调用端标识、服务提供端标识、调用标识和调用时间信息,因此,从该调用信息中查找该调用标识所对应的服务调用端标识和服务提供端标识能够获得该调用标识对应的服务调用链路。由上述内容可知,该方法由服务网关采样获得调用信息,最终实现调用链路追踪,这样,只需要在服务网关上设置埋点进行采样即可,不需要在客户端和服务端都设置埋点,因此,大大降低了每个服务的客户端和服务端的开发、部署成本。In the service tracking method provided by this embodiment, the service gateway receives the service invocation request, the service gateway sends the service invocation request to the corresponding service provider according to the service name, and the service invocation request includes the invocation identifier that uniquely identifies the current invocation link, and The call identifier is passed between each service provider in the entire call chain; each service call request and call result need to be forwarded through the gateway, so the service gateway can obtain call information corresponding to all service calls. The call information includes the service caller identifier, the service provider identifier, the call identifier, and the call time information. Therefore, searching for the service caller identifier and the service provider identifier corresponding to the call identifier from the call information can obtain the corresponding call identifier. Service call link. As can be seen from the above content, this method obtains the call information by sampling the service gateway, and finally realizes the call link tracking. In this way, it is only necessary to set buried points on the service gateway for sampling, and it is not necessary to set buried points on both the client and the server. , therefore, the development and deployment costs of the client and server side of each service are greatly reduced.

请参见图4,示出了本发明实施例另一种服务调用方法的流程图,该方法应用于图2所示的系统中,如图4所示,该方法包括以下步骤:Please refer to FIG. 4, which shows a flowchart of another service invocation method according to an embodiment of the present invention. The method is applied to the system shown in FIG. 2. As shown in FIG. 4, the method includes the following steps:

S210,客户端向服务网关发送第一服务调用请求。S210, the client sends a first service invocation request to the service gateway.

该第一服务调用请求中包含客户端标识、第一服务名称信息、调用标识,其中,调用标识用于唯一标示当前调用链路。The first service invocation request includes the client identifier, the first service name information, and the invocation identifier, where the invocation identifier is used to uniquely identify the current invocation link.

S220,服务网关根据服务名称信息确定相应的第一服务提供端,并将该第一服务调用请求转发给第一服务提供端,以及,记录第一服务调用请求的调用相关信息。S220: The service gateway determines the corresponding first service provider according to the service name information, forwards the first service invocation request to the first service provider, and records invocation related information of the first service invocation request.

在本申请的一个实施例中,所述调用相关信息可以包括:服务调用端标识、服务提供端标识、调用标识和调用时间信息,例如,调用请求接收时间及相应的调用结果接收时间。In an embodiment of the present application, the invocation-related information may include: service invocation terminal identification, service provider identification, invocation identification and invocation time information, for example, the time of receiving the invocation request and the time of receiving the corresponding invocation result.

S230,第一服务提供端接收第一服务调用请求,并确定是否需要调用其它服务;如果是,则执行S240~S280;如果否,则执行S290。S230, the first service provider receives the first service invocation request, and determines whether other services need to be invoked; if yes, execute S240-S280; if not, execute S290.

第一服务提供端接收到第一服务调用请求后,解析该第一服务调用请求,并确定响应该第一服务调用请求是否需要再调用其它服务。After receiving the first service invocation request, the first service provider parses the first service invocation request, and determines whether another service needs to be invoked in response to the first service invocation request.

如果不需要调用其它服务,则直接响应该第一服务调用请求;如果需要调用其它服务,则继续调用其它服务。If it is not necessary to call other services, directly respond to the first service calling request; if other services need to be called, continue to call other services.

S240,第一服务提供端生成第二服务调用请求并发送给服务网关。S240, the first service provider generates a second service invocation request and sends it to the service gateway.

该第二服务调用请求携带第一服务调用请求所包含的调用标识,以及,包括第一服务提供端的信息和第二服务名称信息。The second service invocation request carries the invocation identifier included in the first service invocation request, and includes the information of the first service provider and the second service name information.

如果第一服务提供端响应第一服务调用请求时,需要调用其它服务,则生成调用所述其它服务的第二服务调用请求,生成第二服务调用请求时,将第一服务调用请求所包含的调用标识写入第二服务调用请求中。即,调用标识在服务调用链路中一直传递下去。If the first service provider needs to call other services when responding to the first service invocation request, it generates a second service invocation request for invoking the other service, and when generating the second service invocation request, the first service invocation request contains The invocation identifier is written into the second service invocation request. That is, the call identifier is passed on in the service call chain.

S250,服务网关接收第二服务调用请求,并确定与第二服务名称信息相对应的第二服务提供端,并将第二服务调用请求发送给第二服务提供端,以及记录第二服务调用请求的调用相关信息。S250, the service gateway receives the second service invocation request, determines the second service provider corresponding to the second service name information, sends the second service invocation request to the second service provider, and records the second service invocation request call-related information.

S260,第二服务提供端响应第二服务调用请求,得到第二调用结果,并将第二调用结果发送给服务网关。S260, the second service provider responds to the second service invocation request, obtains the second invocation result, and sends the second invocation result to the service gateway.

S270,服务网关将第二调用结果返回给第一服务提供端,并记录第二调用结果的调用相关信息。S270, the service gateway returns the second invocation result to the first service provider, and records invocation-related information of the second invocation result.

S280,第一服务提供端根据第二调用结果得到第一调用结果,并将第一调用结果发送给服务网关。S280, the first service provider obtains the first invocation result according to the second invocation result, and sends the first invocation result to the service gateway.

执行完S240~S280之后,依次执行S2100~S2120。After executing S240-S280, execute S2100-S2120 in sequence.

S290,第一服务提供端响应第一服务调用请求,生成第一调用结果并发送给服务网关。S290, the first service provider responds to the first service invocation request, generates a first invocation result, and sends it to the service gateway.

执行完S290之后,依次执行S2100~S2120;After executing S290, execute S2100-S2120 in sequence;

S2100,服务网关将第一调用结果返回给客户端,并记录第一调用结果的调用相关信息。S2100, the service gateway returns the first invocation result to the client, and records invocation-related information of the first invocation result.

S2110,日志收集器从服务网关中收集记录的调用相关信息。S2110, the log collector collects the recorded invocation-related information from the service gateway.

S2120,调用分析端分析日志收集器中的数据,获得与调用标识对应的服务调用链路。S2120: Invoke the analysis end to analyze the data in the log collector, and obtain a service invocation link corresponding to the invocation identifier.

调用分析端处理日志收集器中的数据,得到包含同一个调用标识调用请求,并根据服务调用端标识和服务提供端标识确定调用关系,从而得到该调用标识对应的服务调用链路。利用该方法可以得到各个不同的服务调用链路,从而获得整个微服务结构的服务拓扑结构。The calling analysis terminal processes the data in the log collector, obtains a calling request containing the same calling ID, and determines the calling relationship according to the service calling terminal ID and the service provider ID, so as to obtain the service calling link corresponding to the calling ID. Using this method, various service invocation links can be obtained, so as to obtain the service topology of the entire microservice structure.

在获得调用关系的同时,调用分析端根据日志收集器收集到的调用时间信息,确定各个服务之间的调用耗时,即服务网关接收某调用请求的时间与接收该调用请求所对应的调用结果的时间之间的差值。While obtaining the invocation relationship, the invocation analysis end determines the invocation time between services according to the invocation time information collected by the log collector, that is, the time when the service gateway receives a certain invocation request and the invocation result corresponding to the invocation request. difference between the times.

利用服务拓扑结构和各个服务间的调用耗时,能够分析出整个微服务架构中的性能瓶颈。Using the service topology and the call time between services, the performance bottlenecks in the entire microservice architecture can be analyzed.

调用分析端可以基于文本检索系统实现,通过输入筛选条件所要查看的调用链路详情,例如,可以输入时间段来筛选所要查看的调用发生的时间段,从日志收集器的日志数据中检索出所有该时间段内的服务调用的相关信息,例如,服务调用端标识、服务提供端标识和调用延迟等。The call analysis terminal can be implemented based on the text retrieval system. The details of the call link to be viewed by entering the filter conditions. For example, you can enter the time period to filter the time period of the call to be viewed, and retrieve all the log data from the log collector. Relevant information about service calls within this time period, such as service caller ID, service provider ID, and call delay.

本实施例提供的服务调用方法,在服务网关中设置埋点对微服务架构中的每一次调用都进行采样记录,其中,服务调用请求中包含当前调用链路的调用标识,且该调用标识在整个调用链路中一直传递。日志收集器可以收集服务网关所采集的调用相关信息并提供给调用分析端,由调用分析端分析这些调用相关信息查找该调用标识所对应的服务调用端标识和服务提供端标识能够获得该调用标识对应的服务调用链路。该方法由服务网关采样获得调用信息,最终实现调用链路追踪,这样,只需要在服务网关上设置埋点进行采样即可,不需要在客户端和服务端都设置埋点,因此,大大降低了每个服务的客户端和服务端的开发、部署成本。In the service invocation method provided by this embodiment, a buried point is set in the service gateway to sample and record each invocation in the microservice architecture, wherein the service invocation request includes the invocation identifier of the current invocation link, and the invocation identifier is in It has been passed through the entire call chain. The log collector can collect the call-related information collected by the service gateway and provide it to the call analyzer. The call analyzer can analyze the call-related information to find the service caller identifier and service provider identifier corresponding to the call identifier to obtain the call identifier. Corresponding service invocation link. This method obtains the call information by sampling the service gateway, and finally realizes the call link tracking. In this way, it is only necessary to set buried points on the service gateway for sampling, and it is not necessary to set buried points on both the client and the server. The development and deployment costs of the client and server of each service are calculated.

对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本发明并不受所描述的动作顺序的限制,因为依据本发明,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本发明所必须的。For the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, Certain steps may be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

相应于上述的服务调用方法实施例,本申请还提供了服务调用装置实施例。Corresponding to the foregoing service invocation method embodiments, the present application further provides service invocation apparatus embodiments.

请参见图5,示出了本申请实施例一种服务调用装置的框图,该装置应用于服务网关中。该装置包括:第一接收单元110、第一发送单元120、第二接收单元130、第二发送单元140和获取单元150;Referring to FIG. 5 , it shows a block diagram of an apparatus for invoking a service according to an embodiment of the present application, and the apparatus is applied in a service gateway. The apparatus includes: a first receiving unit 110, a first sending unit 120, a second receiving unit 130, a second sending unit 140 and an obtaining unit 150;

第一接收单元110,用于接收服务调用请求,所述服务调用请求包括服务调用端标识、服务名称和调用标识,所述调用标识用于唯一标示所述服务调用请求所对应的服务调用链路。The first receiving unit 110 is configured to receive a service invocation request, where the service invocation request includes a service invocation terminal identifier, a service name and an invocation identifier, and the invocation identifier is used to uniquely identify a service invocation link corresponding to the service invocation request .

服务调用端是发起该服务调用请求的一方,服务调用端标识可以是能够唯一标识该服务调用端的标识信息,例如,MAC地址。The service caller is the party that initiates the service call request, and the service caller identifier may be identification information that can uniquely identify the service caller, for example, a MAC address.

在本发明一种可能的实现方式中,服务调用端可以是客户端,即,客户端向服务网关发起服务调用请求的应用场景;In a possible implementation manner of the present invention, the service invoking end may be a client, that is, an application scenario in which the client initiates a service invocation request to the service gateway;

在本发明另一种可能的实现方式中,服务调用端可以是服务提供端,即,该服务提供端实现某个服务时,需要调用其它的服务,因此,需要向其它的服务提供端发送服务调用请求。In another possible implementation manner of the present invention, the service invoking end may be a service provider, that is, when the service provider implements a certain service, it needs to call other services, so it needs to send services to other service providers call request.

第一发送单元120,用于根据所述服务名称将所述服务调用请求发送给相应的服务提供端。The first sending unit 120 is configured to send the service invocation request to a corresponding service provider according to the service name.

服务网关根据服务调用请求中包含的服务名称,找到提供该服务名称对应服务的服务提供端,并经由第一发送单元将该服务调用请求发送给该服务提供端。The service gateway finds the service provider that provides the service corresponding to the service name according to the service name included in the service invocation request, and sends the service invocation request to the service provider via the first sending unit.

第二接收单元130,用于接收所述服务提供端返回的调用结果。The second receiving unit 130 is configured to receive the calling result returned by the service provider.

服务提供端接收到服务调用请求后,如果不需要再调用其它服务,则响应该服务调用请求生成调用结果,并将调用结果返回给服务网关,服务网关经由第二接收单元接收该调用结果。After receiving the service invocation request, the service provider generates invocation results in response to the service invocation request if it does not need to invoke other services, and returns the invocation results to the service gateway, which receives the invocation results through the second receiving unit.

第二发送单元140,用于将所述调用结果发送给服务调用端。The second sending unit 140 is configured to send the calling result to the service calling end.

获取单元150,用于获取所述服务调用请求对应的调用信息,以使调用分析端分析所述调用信息获得与所述调用标识对应的服务调用链路。The acquiring unit 150 is configured to acquire invocation information corresponding to the service invocation request, so that the invocation analysis end analyzes the invocation information to obtain a service invocation link corresponding to the invocation identifier.

服务网关内设置埋点对整个服务调用过程进行采样,得到调用信息,该调用信息包括服务调用端标识、服务提供端标识、调用标识和调用时间信息。Buried points are set in the service gateway to sample the entire service invocation process to obtain invocation information. The invocation information includes service invocation end identification, service provider identification, invocation identification and invocation time information.

分析服务网关获得的调用信息得到与该调用标识对应的调用数据,并最终得到本次服务调用的整个服务调用链路。Analyzing the call information obtained by the service gateway obtains call data corresponding to the call identifier, and finally obtains the entire service call link of this service call.

可选地,还可以根据调用耗时确定服务系统的性能瓶颈,其中,调用耗时是指从发起服务调用到得到所述服务响应所经历的时间。Optionally, the performance bottleneck of the service system may also be determined according to the invocation time-consuming, where the invocation time-consuming refers to the time elapsed from initiating a service invocation to obtaining the service response.

如图6所示,获取单元150包括第一记录子单元151、第二记录子单元152和计算子单元153。As shown in FIG. 6 , the acquiring unit 150 includes a first recording subunit 151 , a second recording subunit 152 and a calculating subunit 153 .

第一记录子单元151,用于记录接收到所述服务调用请求的第一时间戳。The first recording subunit 151 is configured to record the first timestamp when the service invocation request is received.

第二记录子单元152,用于记录接收到所述调用请求对应的调用结果的第二时间戳。The second recording subunit 152 is configured to record the second timestamp of receiving the invocation result corresponding to the invocation request.

计算子单元153,用于计算所述第二时间戳与所述第一时间戳的时间差,得到每个服务对应的调用耗时。The calculation subunit 153 is configured to calculate the time difference between the second time stamp and the first time stamp to obtain the invocation time corresponding to each service.

本实施例提供的服务调用装置,服务网关接收服务调用请求,服务网关根据服务名称将该服务调用请求发送给相应的服务提供端,服务调用请求中包含唯一标示当前调用链路的调用标识,且该调用标识在整个调用链路中的各个服务提供端间传递;每个服务调用请求和调用结果都需要经过网关进行转发,因此,服务网关能够获取所有服务调用对应的调用信息。调用信息包括服务调用端标识、服务提供端标识、调用标识和调用时间信息,因此,从该调用信息中查找该调用标识所对应的服务调用端标识和服务提供端标识能够获得该调用标识对应的服务调用链路。该装置只需要在服务网关上设置埋点进行采样即可,不需要在客户端和服务端都设置埋点,因此,大大降低了每个服务的客户端和服务端的开发、部署成本。In the service invocation device provided in this embodiment, the service gateway receives the service invocation request, the service gateway sends the service invocation request to the corresponding service provider according to the service name, and the service invocation request includes a call identifier that uniquely identifies the current call link, and The call identifier is passed between each service provider in the entire call chain; each service call request and call result need to be forwarded through the gateway, so the service gateway can obtain call information corresponding to all service calls. The call information includes the service caller identifier, the service provider identifier, the call identifier, and the call time information. Therefore, searching for the service caller identifier and the service provider identifier corresponding to the call identifier from the call information can obtain the corresponding call identifier. Service call link. The device only needs to set buried points on the service gateway for sampling, and does not need to set buried points on both the client and the server. Therefore, the development and deployment costs of the client and server of each service are greatly reduced.

请参见图7,示出了本申请实施例另一种服务调用装置的框图,该装置应用于服务提供端中,如图7所示,该装置可以包括:第一接收单元210、第一解析单元220、请求生成单元230、第一发送单元240、第二接收单元250和响应单元260。Please refer to FIG. 7 , which shows a block diagram of another service invoking apparatus according to an embodiment of the present application. The apparatus is applied to a service provider. As shown in FIG. 7 , the apparatus may include: a first receiving unit 210 , a first parsing unit 210 unit 220 , a request generating unit 230 , a first sending unit 240 , a second receiving unit 250 and a response unit 260 .

第一接收单元210,用于使第一服务提供端接收服务网关转发的第一调用请求。The first receiving unit 210 is configured to enable the first service provider to receive the first invocation request forwarded by the service gateway.

所述第一调用请求包括第一服务调用端标识、第一服务名称和调用标识,所述调用标识用于唯一标示所述服务调用请求所对应的服务调用链路。The first invocation request includes a first service invocation terminal identifier, a first service name and an invocation identifier, and the invocation identifier is used to uniquely identify a service invocation link corresponding to the service invocation request.

第一解析单元220,用于使所述第一服务提供端解析所述第一调用请求得到所述第一调用请求所需调用的第二服务名称,以及所述调用标识。The first parsing unit 220 is configured to make the first service provider parse the first invocation request to obtain the second service name and the invocation identifier to be invoked by the first invocation request.

第一服务提供端接收到第一服务调用请求后,解析该第一服务调用请求,并确定响应该第一服务调用请求需要调用的第二服务名称。After receiving the first service invocation request, the first service provider parses the first service invocation request, and determines the second service name to be invoked in response to the first service invocation request.

请求生成单元230,用于使所述第一服务提供端根据所述第二服务名称生成第二调用请求,所述第二调用请求包括第二服务调用端标识、第二服务名称和所述调用标识。A request generating unit 230, configured to enable the first service provider to generate a second invocation request according to the second service name, where the second invocation request includes a second service invocation end identifier, a second service name and the invocation logo.

第一服务调用端生成的第二调用请求所包含的调用标识与第一调用请求中的调用标识相同。The call identifier included in the second call request generated by the first service caller is the same as the call identifier in the first call request.

第一发送单元240,用于使所述第一服务提供端将所述第二调用请求发送给所述服务网关;a first sending unit 240, configured to make the first service provider send the second invocation request to the service gateway;

所述服务网关将第二调用请求转发给第二服务提供端,所述第二服务提供端提供第二服务名称对应的服务;以及,使所述服务网关获得调用信息,并由调用分析端根据所述调用信息获得与所述调用标识对应的服务调用链路。The service gateway forwards the second invocation request to the second service provider, and the second service provider provides the service corresponding to the second service name; The invocation information obtains a service invocation link corresponding to the invocation identifier.

第二接收单元250,用于使所述第一服务提供端通过所述服务网关接收所述第二服务提供端返回的第二调用结果,所述第二调用结果由所述第二服务提供端响应所述第二调用请求得到。The second receiving unit 250 is configured to enable the first service provider to receive, through the service gateway, a second invocation result returned by the second service provider, where the second invocation result is returned by the second service provider obtained in response to the second call request.

响应单元260,用于使所述第一服务提供端根据所述第二调用结果响应所述第一调用请求,生成第一调用结果,并将所述第一调用结果通过所述服务网关转发给发起所述第一调用请求的第一服务调用端。A response unit 260, configured to make the first service provider respond to the first invocation request according to the second invocation result, generate a first invocation result, and forward the first invocation result to the service gateway through the service gateway. A first service caller that initiates the first call request.

调用分析端处理日志收集器中的数据,得到包含同一个调用标识的调用请求,并根据每条调用请求中包含的服务调用端标识和服务提供端标识确定调用关系,从而得到该调用标识对应的服务调用链路。利用该方法可以得到各个不同的服务调用链路,从而获得整个微服务结构的服务拓扑结构。Call the analysis terminal to process the data in the log collector, obtain the call request containing the same call ID, and determine the call relationship according to the service caller ID and the service provider ID contained in each call request, so as to obtain the corresponding call ID. Service call link. Using this method, various service invocation links can be obtained, so as to obtain the service topology of the entire microservice structure.

在获得调用关系的同时,调用分析端根据日志收集器收集到的调用时间信息,确定各个服务之间的调用耗时,即服务网关接收某调用请求的时间与接收该调用请求所对应的调用结果的时间之间的差值。While obtaining the invocation relationship, the invocation analysis end determines the invocation time between services according to the invocation time information collected by the log collector, that is, the time when the service gateway receives a certain invocation request and the invocation result corresponding to the invocation request. difference between the times.

利用服务拓扑结构和各个服务间的调用耗时,能够分析出整个微服务架构中的性能瓶颈。Using the service topology and the call time between services, the performance bottlenecks in the entire microservice architecture can be analyzed.

调用分析端可以基于文本检索系统实现,通过输入筛选条件所要查看的调用链路详情,例如,可以输入时间段来筛选所要查看的调用发生的时间段,从日志收集器的日志数据中检索出所有该时间段内的服务调用的相关信息,例如,服务调用端标识、服务提供端标识和调用延迟等。The call analysis terminal can be implemented based on the text retrieval system. The details of the call link to be viewed by entering the filter conditions. For example, you can enter the time period to filter the time period of the call to be viewed, and retrieve all the log data from the log collector. Relevant information about service calls within this time period, such as service caller ID, service provider ID, and call delay.

本实施例提供的服务调用装置,在服务网关中设置埋点对微服务架构中的每一次调用都进行采样记录,其中,服务调用请求中包含当前调用链路的调用标识,且该调用标识在整个调用链路中一直传递。因此,从服务网关调用信息中查找该调用标识所对应的服务调用端标识和服务提供端标识能够获得该调用标识对应的服务调用链路。该装置只需要在服务网关上设置埋点进行采样即可,不需要在客户端和服务端都设置埋点,因此,大大降低了每个服务的客户端和服务端的开发、部署成本。In the service invocation device provided in this embodiment, a buried point is set in the service gateway to sample and record each invocation in the microservice architecture, wherein the service invocation request includes the invocation identifier of the current invocation link, and the invocation identifier is in It has been passed through the entire call chain. Therefore, the service invocation link corresponding to the invocation identification can be obtained by searching the service invocation terminal identification and the service provider identification corresponding to the invocation identification from the service gateway invocation information. The device only needs to set buried points on the service gateway for sampling, and does not need to set buried points on both the client and the server. Therefore, the development and deployment costs of the client and server of each service are greatly reduced.

需要说明的是,本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。对于装置类实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. For the same and similar parts among the various embodiments, refer to each other Can. As for the apparatus type embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for the relevant part, please refer to the partial description of the method embodiment.

最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。Finally, it should also be noted that in this document, relational terms such as first and second are used only to distinguish one entity or operation from another, and do not necessarily require or imply these entities or that there is any such actual relationship or sequence between operations. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass a non-exclusive inclusion such that a process, method, article or device that includes a list of elements includes not only those elements, but also includes not explicitly listed or other elements inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element.

对所公开的实施例的上述说明,使本领域技术人员能够实现或使用本发明。对这些实施例的多种修改对本领域技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本发明的精神或范围的情况下,在其它实施例中实现。因此,本发明将不会被限制于本文所示的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。The above description of the disclosed embodiments enables any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本发明的保护范围。The above are only the preferred embodiments of the present invention. It should be pointed out that for those skilled in the art, without departing from the principles of the present invention, several improvements and modifications can be made. It should be regarded as the protection scope of the present invention.

Claims (10)

1. A service calling method is applied to a service gateway, and comprises the following steps:
receiving a service calling request, wherein the service calling request comprises a service calling end identifier, a service name and a calling identifier, and the calling identifier is used for uniquely marking a service calling link corresponding to the service calling request;
sending the service calling request to a corresponding service provider according to the service name;
receiving a calling result returned by the service providing terminal, and sending the calling result to a service calling terminal;
and acquiring the calling information corresponding to the service calling request so that a calling analysis end analyzes the service calling end identification, the service providing end identification and the calling identification in the calling information to obtain a service calling link corresponding to the calling identification.
2. The method of claim 1, wherein the invocation information further includes invocation time information, the invocation time information including invocation time; the process of obtaining the call time consumption comprises the following steps:
recording a first time stamp of the received service calling request and a second time stamp of a calling result corresponding to the received calling request;
and calculating the time difference between the second time stamp and the first time stamp to obtain the calling time consumption of each service.
3. The method of claim 1, wherein receiving the service invocation request comprises:
receiving the service calling request sent by the client;
or,
and receiving a service calling request for calling the second service provider, which is sent by the first service provider.
4. A service calling method is applied to a service provider, and comprises the following steps:
a first service provider receives a first calling request forwarded by a service gateway, wherein the first calling request comprises a first service calling end identifier, a first service name and a calling identifier, and the calling identifier is used for uniquely marking a service calling link corresponding to the service calling request;
the first service providing terminal analyzes the first calling request to obtain a second service name required to be called by the first calling request and the calling identifier;
the first service providing terminal generates a second calling request according to the second service name, wherein the second calling request comprises a second service calling terminal identification, a second service name and the calling identification;
the first service provider sends the second calling request to the service gateway so that the service gateway forwards the second calling request to a second service provider, and the second service provider provides a service corresponding to the second service name; and enabling the service gateway to obtain calling information, and obtaining a service calling link corresponding to the calling identifier by a calling analysis end according to the calling information.
5. The method of claim 4, further comprising:
the first service provider receives a second calling result returned by the second service provider through the service gateway, and the second calling result is obtained by the second service provider responding to the second calling request;
and the first service providing terminal responds to the first calling request according to the second calling result to generate a first calling result, and forwards the first calling result to the first service calling terminal initiating the first calling request through the service gateway.
6. A service invocation device, applied in a service gateway, the device comprising:
the first receiving unit is used for receiving a service calling request, wherein the service calling request comprises a service calling end identifier, a service name and a calling identifier, and the calling identifier is used for uniquely marking a service calling link corresponding to the service calling request;
the first sending unit is used for sending the service calling request to a corresponding service provider according to the service name;
the second receiving unit is used for receiving a calling result returned by the service providing end;
the second sending unit is used for sending the calling result to a service calling end;
and the obtaining unit is used for obtaining the calling information corresponding to the service calling request so that the calling analysis end analyzes the service calling end identifier, the service providing end identifier and the calling identifier in the calling information to obtain a service calling link corresponding to the calling identifier.
7. The apparatus according to claim 6, wherein the call information further includes call time information, the call time information includes call elapsed time, and the obtaining unit includes:
the first recording subunit is used for recording a first timestamp of the received service calling request;
the second recording subunit is used for recording a second timestamp of the calling result corresponding to the received calling request;
and the calculating subunit is configured to calculate a time difference between the second timestamp and the first timestamp, so as to obtain a call time consumption corresponding to each service.
8. The apparatus of claim 6, wherein the first receiving unit is specifically configured to:
receiving the service calling request sent by the client;
or,
and receiving a service calling request for calling the second service provider, which is sent by the first service provider.
9. A service invoking device is applied to a service provider, and the device comprises:
the first receiving unit is used for enabling a first service providing end to receive a first calling request forwarded by a service gateway, wherein the first calling request comprises a first service calling end identifier, a first service name and a calling identifier, and the calling identifier is used for uniquely marking a service calling link corresponding to the service calling request;
a first parsing unit, configured to enable the first service providing end to parse the first invocation request to obtain a second service name to be invoked by the first invocation request and the invocation identifier;
a request generating unit, configured to enable the first service provider to generate a second call request according to the second service name, where the second call request includes a second service call end identifier, a second service name, and the call identifier;
a first sending unit, configured to enable the first service provider to send the second invocation request to the service gateway, so that the service gateway forwards the second invocation request to a second service provider, where the second service provider provides a service corresponding to the second service name; and enabling the service gateway to obtain calling information, and obtaining a service calling link corresponding to the calling identifier by a calling analysis end according to the calling information.
10. The apparatus of claim 9, further comprising:
a second receiving unit, configured to enable the first service provider to receive, through the service gateway, a second invocation result returned by the second service provider, where the second invocation result is obtained by the second service provider in response to the second invocation request;
and the response unit is used for enabling the first service providing end to respond to the first calling request according to the second calling result, generating a first calling result and forwarding the first calling result to the first service calling end initiating the first calling request through the service gateway.
CN201710469894.2A 2017-06-20 2017-06-20 Service invocation method and device Active CN107181675B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710469894.2A CN107181675B (en) 2017-06-20 2017-06-20 Service invocation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710469894.2A CN107181675B (en) 2017-06-20 2017-06-20 Service invocation method and device

Publications (2)

Publication Number Publication Date
CN107181675A CN107181675A (en) 2017-09-19
CN107181675B true CN107181675B (en) 2020-03-03

Family

ID=59844243

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710469894.2A Active CN107181675B (en) 2017-06-20 2017-06-20 Service invocation method and device

Country Status (1)

Country Link
CN (1) CN107181675B (en)

Families Citing this family (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107741885B (en) * 2017-10-09 2020-12-01 用友网络科技股份有限公司 Transaction and service association method and system based on CS framework
CN107766164A (en) * 2017-11-17 2018-03-06 深圳市泉眼网络科技有限公司 Data calling method and device
CN107944295B (en) * 2017-11-28 2020-04-03 中国农业银行股份有限公司 Sensitive information desensitization method and system for transaction message
CN108199876A (en) * 2017-12-29 2018-06-22 北京奇艺世纪科技有限公司 A kind of daily record data store method, device and distribution service
CN108415925B (en) * 2018-01-10 2020-11-24 平安科技(深圳)有限公司 Electronic device, data call log generation and query method and storage medium
CN108600045A (en) * 2018-04-05 2018-09-28 厦门快商通信息技术有限公司 A kind of service link monitoring method and device
CN108901022B (en) * 2018-06-28 2021-08-20 深圳云之家网络有限公司 Micro-service unified authentication method and gateway
CN108847989B (en) * 2018-06-29 2021-07-06 杭州安恒信息技术股份有限公司 Log processing method, business service system and electronic device based on microservice architecture
CN109672662B (en) * 2018-10-11 2021-03-26 中山大学 Method for constructing service dependency relationship in micro-service environment
CN109412944B (en) * 2018-10-16 2023-05-12 深圳壹账通智能科技有限公司 Request forwarding method and device based on micro-service and server
CN109508431A (en) * 2018-11-15 2019-03-22 北京芯盾时代科技有限公司 Bury point code method for implanting, device, electronic equipment and computer storage medium
WO2020107342A1 (en) * 2018-11-29 2020-06-04 华为技术有限公司 Method and device for tracking service execution process in distributed system
CN110138741B (en) * 2019-04-15 2022-06-17 平安科技(深圳)有限公司 Micro-service management method and device based on unified management platform and computer equipment
CN110213240A (en) * 2019-05-09 2019-09-06 国电南瑞科技股份有限公司 A kind of electric power dispatching system and its transregional service calling method of routing self-adaption
CN110445667B (en) * 2019-05-29 2021-10-26 北京大米科技有限公司 Link delay detection method, device, storage medium and terminal
CN110262889B (en) * 2019-06-27 2024-10-29 深圳前海微众银行股份有限公司 Link tracking method and device
CN110807050B (en) * 2019-09-25 2023-05-30 平安科技(深圳)有限公司 Performance analysis method, device, computer equipment and storage medium
CN111163063B (en) * 2019-12-12 2022-07-12 万翼科技有限公司 Edge application management method and related product
CN111343242B (en) * 2020-02-13 2022-09-02 北京奇艺世纪科技有限公司 Information collection method, device, equipment, storage medium and distributed system
CN111580896B (en) * 2020-05-04 2023-07-07 武汉众邦银行股份有限公司 Link calling method based on atomization service
CN111897604B (en) * 2020-07-30 2023-08-11 北京百度网讯科技有限公司 Service call data processing method and device
CN113868345B (en) * 2021-10-11 2024-05-28 支付宝(杭州)信息技术有限公司 Method and device for subject classification of business data
CN114661382B (en) * 2022-03-14 2025-10-21 京东科技控股股份有限公司 Method, device, equipment, medium and program product for generating data call records
CN117194176B (en) * 2023-11-03 2024-06-04 中国电子科技集团公司第十五研究所 Non-intrusive operation monitoring method, device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101252443A (en) * 2008-03-20 2008-08-27 华为技术有限公司 Method and device for detecting message security
CN104348650A (en) * 2013-08-05 2015-02-11 腾讯科技(深圳)有限公司 Website monitoring method, business device and website monitoring system
CN105577710A (en) * 2014-10-09 2016-05-11 阿里巴巴集团控股有限公司 Service providing method, service acquiring method, devices and system
CN106790718A (en) * 2017-03-16 2017-05-31 北京搜狐新媒体信息技术有限公司 Service call link analysis method and system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130138768A1 (en) * 2011-11-30 2013-05-30 Vincent Huang Method and System for Dynamic Service Creation on Sensor Gateways

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101252443A (en) * 2008-03-20 2008-08-27 华为技术有限公司 Method and device for detecting message security
CN104348650A (en) * 2013-08-05 2015-02-11 腾讯科技(深圳)有限公司 Website monitoring method, business device and website monitoring system
CN105577710A (en) * 2014-10-09 2016-05-11 阿里巴巴集团控股有限公司 Service providing method, service acquiring method, devices and system
CN106790718A (en) * 2017-03-16 2017-05-31 北京搜狐新媒体信息技术有限公司 Service call link analysis method and system

Also Published As

Publication number Publication date
CN107181675A (en) 2017-09-19

Similar Documents

Publication Publication Date Title
CN107181675B (en) Service invocation method and device
CN112217856B (en) Method, device, equipment and storage medium for obtaining address of application example
US20070121626A1 (en) User and activity based end-to-end utilization measurement system
CN106375458B (en) Service calling system, method and device
CN112073512B (en) Data processing method and device
CN106850782A (en) Method and system for log processing
CN108063714A (en) A kind of processing method and processing device of network request
CN111431773A (en) A Link Tracing Method Based on OpenTracing
CN107784552A (en) Information push task executing method, device, computer equipment and storage medium
CN115104336A (en) Tracking and publishing data for generating analytics
WO2023109524A1 (en) Information leakage monitoring method and system, and electronic device
US10616378B2 (en) Adaptive session intelligence extender
CN109639767A (en) A kind of Service Gateway data processing method, device, equipment
CN113596078A (en) Service problem positioning method and device
WO2019137208A1 (en) Underlying data monitoring method, medium, device and apparatus
US9749840B1 (en) Generating and analyzing call detail records for various uses of mobile network resources
CN114297495A (en) Service data search method, device, electronic device and storage medium
JP2014523671A (en) Assessing the overall performance of interactive application services
CN102137022A (en) Method for identifying information of data packet, crawler engine and network system
CN108876608B (en) Block chain application method and system
CN114301988B (en) Distributed calling method, device, storage medium and electronic device
CN114222284B (en) Terminal equipment identification method, device and readable storage medium
CN115086376A (en) Government affair data processing system based on micro service
CN110149365B (en) Service adaptation method, device, system and computer readable medium
CN112148508A (en) Information processing method and related device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 100080 Room 108, 1st Floor, No. 52 West Beisihuan Road, Haidian District, Beijing

Patentee after: BEIJING QIYI CENTURY SCIENCE & TECHNOLOGY Co.,Ltd.

Country or region after: China

Address before: 100080 Beijing, North Street, No. 1, Iqiyi innovation building, floor 10, level 2, level 11, Haidian District

Patentee before: BEIJING QIYI CENTURY SCIENCE & TECHNOLOGY Co.,Ltd.

Country or region before: China