CN112732456A - Micro-service calling method and device, electronic equipment and storage medium - Google Patents

Micro-service calling method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112732456A
CN112732456A CN202011484237.3A CN202011484237A CN112732456A CN 112732456 A CN112732456 A CN 112732456A CN 202011484237 A CN202011484237 A CN 202011484237A CN 112732456 A CN112732456 A CN 112732456A
Authority
CN
China
Prior art keywords
server
service
list
micro
server list
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.)
Pending
Application number
CN202011484237.3A
Other languages
Chinese (zh)
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.)
JD Digital Technology Holdings Co Ltd
Original Assignee
JD Digital Technology Holdings 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 JD Digital Technology Holdings Co Ltd filed Critical JD Digital Technology Holdings Co Ltd
Priority to CN202011484237.3A priority Critical patent/CN112732456A/en
Publication of CN112732456A publication Critical patent/CN112732456A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application provides a micro-service calling method, a micro-service calling device, electronic equipment and a storage medium, wherein the method comprises the following steps: acquiring a locally stored server list; selecting a target server from the server list according to a preset load balancing rule; and sending a service calling request to the target server. According to the method, the client can efficiently and quickly acquire the available target server through the locally stored server list, and the target server is called through the preset load balancing rule, so that service discovery and load balancing in micro-service calling are realized.

Description

Micro-service calling method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for invoking a micro service, an electronic device, and a storage medium.
Background
Microservice is an architectural and organizational method of developing software consisting of small, independent services communicating through well-defined APIs, which are responsible for individual small, independent teams.
gRPC (Google Remote Procedure Call) is a language neutral, platform independent, open source Remote Call framework. At present, when a gRPC is used for providing Python service, the gRPC has relatively good support for a point-to-point C/S (client/server) architecture, but service discovery, load balancing and the like of micro service are not realized yet.
Disclosure of Invention
The application provides a micro-service calling method and device, electronic equipment and a storage medium.
An embodiment of one aspect of the present application provides a method for invoking a micro service, including:
acquiring a locally stored server list;
selecting a target server from the server list according to a preset load balancing rule;
and sending a service calling request to the target server.
According to the micro-service calling method, the locally stored server list is obtained, the target server is selected from the server list according to the preset load balancing rule, and the service calling request is sent to the target server. Therefore, through the locally stored server list, the client can efficiently and quickly acquire the available target server, and the target server is called through the preset load balancing rule, so that service discovery and load balancing in micro-service calling are realized.
In one aspect of this application, in a possible implementation manner of an embodiment, before the obtaining the locally stored server list, the method further includes:
acquiring a server side updating notice sent by a micro service center, wherein the updating notice comprises the server side list;
and storing the server list.
In one possible implementation manner of an embodiment of an aspect of the present application, before the obtaining of the server update notification sent by the micro service center, the method further includes:
and sending a server list subscription request to the micro service center.
In an aspect of this application, in one possible implementation manner of an embodiment, there are a plurality of locally stored server lists, and service types corresponding to each server list are different, where the obtaining of the locally stored server list includes:
determining a target service type to be acquired according to the type of the current source data to be processed;
and acquiring a locally stored target service end list corresponding to the target service type.
In another aspect, an embodiment of the present application provides a method for invoking a micro service, including:
updating a server list when the state of any server is monitored to be changed;
and sending a server list change notification to the client so that the client updates a local server list.
According to the method for calling the micro-service, when the state of any one server is monitored to be changed, the server list is updated, and a server list change notification is sent to the client, so that the client updates the local server list. Therefore, the change of the dynamic monitoring server side in the micro-service calling is realized.
In another aspect of this application, in one possible implementation manner of an embodiment, the monitoring that any server side is changed includes:
in a continuous time interval, not monitoring the heartbeat packet of any server;
or,
and acquiring a registration request sent by any server.
In a possible implementation manner of another embodiment of the present application, the updating the server list includes:
determining the service type of any one server;
and updating a server list corresponding to the service type.
Another embodiment of the present application provides a micro service invoking device, including:
the first acquisition module is used for acquiring a locally stored server list;
the selecting module is used for selecting a target server from the server list according to a preset load balancing rule;
and the sending module is used for sending a service calling request to the target server.
The micro-service calling device of the embodiment of the application selects the target server from the server list by acquiring the locally stored server list and according to the preset load balancing rule, and sends the service calling request to the target server. Therefore, through the locally stored server list, the client can efficiently and quickly acquire the available target server, and the target server is called through the preset load balancing rule, so that service discovery and load balancing in micro-service calling are realized.
In one possible implementation manner of another embodiment of the present application, the apparatus further includes:
the second acquisition module is used for acquiring a server side updating notice sent by a micro service center, wherein the updating notice comprises the server side list;
and the storage module is used for storing the server list.
In a possible implementation manner of another embodiment of the present application, the sending module is further configured to send a server list subscription request to the micro service center.
In another aspect of this application, in a possible implementation manner of an embodiment of the present application, there are a plurality of locally stored server lists, and service types corresponding to each server list are different, where the first obtaining module is configured to:
determining a target service type to be acquired according to the type of the current source data to be processed;
and acquiring a locally stored target service end list corresponding to the target service type.
Another embodiment of the present application provides a micro service invoking device, including:
the updating module is used for updating the server list when monitoring the state change of any server;
and the sending module is used for sending a server list change notification to the client so that the client updates the local server list.
The micro-service calling device of the embodiment of the application updates the server list and sends the server list change notification to the client when monitoring the state change of any server, so that the client updates the local server list. Therefore, the change of the dynamic monitoring server side in the micro-service calling is realized.
In another aspect of this application, in one possible implementation manner of an embodiment, the monitoring that any server side is changed includes:
in a continuous time interval, not monitoring the heartbeat packet of any server;
or,
and acquiring a registration request sent by any server.
In a possible implementation manner of another embodiment of the present application, the update module is configured to:
determining the service type of any one server;
and updating a server list corresponding to the service type.
Another embodiment of the present application provides an electronic device, including a processor and a memory;
wherein the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to implement the micro-service calling method according to the embodiment of the above-mentioned aspect, or implement the micro-service calling method according to the embodiment of the above-mentioned aspect.
Another embodiment of the present application proposes a non-transitory computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the micro-service invocation method according to an embodiment of the above-mentioned aspect, or implements the micro-service invocation method according to an embodiment of the above-mentioned another aspect.
Additional aspects and advantages of the present application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the present application.
Drawings
The foregoing and/or additional aspects and advantages of the present application will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings of which:
fig. 1 is a schematic flowchart of a method for invoking a micro service according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of another micro-service invocation method according to an embodiment of the present application;
fig. 3 is a schematic flowchart of another micro-service invocation method according to an embodiment of the present application;
fig. 4 is a schematic flowchart of another micro-service invocation method according to an embodiment of the present application;
fig. 5 is a schematic flowchart of another micro-service invocation method according to an embodiment of the present application;
fig. 6 is a schematic process diagram of a micro service invocation according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a micro service invocation device according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of another microservice calling apparatus according to an embodiment of the present disclosure.
Detailed Description
Reference will now be made in detail to embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary and intended to be used for explaining the present application and should not be construed as limiting the present application.
The method, the apparatus, the electronic device, and the storage medium for invoking a micro service according to embodiments of the present application are described below with reference to the accompanying drawings.
According to the micro-service calling method provided by the embodiment of the application, the available target server can be efficiently and quickly obtained through the locally stored server list, and the target server is called through the preset load balancing rule, so that service discovery and load balancing in micro-service calling are realized.
Fig. 1 is a schematic flowchart of a method for invoking a micro service according to an embodiment of the present disclosure.
The method for invoking the micro-service in the embodiment of the present application can be applied to a client, for example, a Java client, and can be executed by a micro-service invoking device on the client side in the embodiment of the present application, and the device can be configured in an electronic device, such as a mobile phone, a wearable device, and the like, to achieve efficient and fast acquisition of an available target server, and achieve invocation of the target server through a preset load balancing rule, thereby achieving service discovery and load balancing.
As shown in fig. 1, the micro-service calling method includes:
step 101, a locally stored server list is obtained.
In this embodiment, when the client needs to call a service, the client may read the local configuration file to obtain a locally stored server list. The service side list may include an identifier of the service side, an IP address of the service side, a service type provided by the service side, and the like, and if one service side provides multiple services, the service side list may further include an interface corresponding to each service type.
For example, the server list includes a plurality of services provided by a certain server, such as a voice recognition service, an image processing service, and a voice synthesis service, and an interface corresponding to each service.
And 102, selecting a target server from the server list according to a preset load balancing rule.
In order to implement load balancing, in this embodiment, the client may select a service provider, i.e., a target server, from the server list according to a preset load balancing rule.
The preset load balancing rule may be preset. For example, a target server is selected from the server list by using a randomly selected policy, and for example, the target server is determined according to the service order of the servers.
Or, the load balancing rule may also be determined according to the current processing capability of the device where the client is located. Therefore, the load balancing rule is dynamically determined according to the processing capacity of the equipment, and the processing efficiency is improved while the responsible balancing is realized.
And 103, sending a service calling request to the target server.
After the target server is determined, the client may send a service invocation request to the target server according to the IP address of the target server and the interface corresponding to the invoked service, etc.
The service invocation request may include an identification of the client, an identification of a device where the client is located, an identification of the invoked service, parameters required by the service, and the like. Therefore, after the target server side obtains the service calling request, the corresponding calling service is executed, and the result is returned to the client side.
Service discovery refers to the need to discover which nodes can now provide a service when a client accesses the service.
In this embodiment, according to a preset load balancing rule, a target server is selected from the server list, and a service invocation request is sent to the target server, so that service discovery and load balancing in micro-service invocation are achieved.
In a specific implementation, the service end may be implemented based on a Python language, and the service provided by the Python service end is also implemented by the Python language. Because the Python language belongs to the interpretive voice, compiling is not needed, and restarting is not needed after code updating, hot updating and hot loading can be realized. Therefore, when the Python language-based service is started, a subprocess is copied, and the subprocess is responsible for monitoring whether the file is updated or not. When there is an update, the child process exits, so that a special identifier is sent to the parent process, and the parent process can derive a child process again to run the updated file, so that the child process provides service according to the updated file.
The client may be implemented based on Python language, or may be implemented in other languages, such as Java. Therefore, the micro-service calling method can achieve service discovery, load balancing, hot updating, hot loading and the like under cross-language calling of the micro-service.
In the embodiment of the application, a target server is selected from the server list by acquiring the locally stored server list and according to a preset load balancing rule, and a service calling request is sent to the target server. Therefore, the available target server can be efficiently and quickly obtained through the locally stored server list, and the target server is called through the preset load balancing rule, so that service discovery and load balancing in micro-service calling are realized.
In an embodiment of the present application, a server update notification may be obtained from the micro service center, and the server list may be updated according to the server update notification. Fig. 2 is a schematic flowchart of another micro-service invocation method provided in an embodiment of the present application.
As shown in fig. 2, the micro-service calling method includes:
step 201, obtaining a server update notification sent by a micro service center, where the update notification includes a server list.
In this embodiment, the state of each server may be monitored through the micro service center, and when it is monitored that the state of the server changes, for example, the server fails or a new server is added, the micro service center may update the corresponding server list and send a server update notification to the client, so that the client obtains the server update notification sent by the micro service center. The server update notification includes a server list, and the server in the server list is a currently and normally operating server capable of providing services.
In order to reduce the data transmission quantity, when the service end is increased or decreased, the micro service center can also send a corresponding updating notice to the client, and the client updates the locally stored service end list according to the updating notice. Wherein, the update notice comprises the information of the new or reduced service end.
For example, when the micro service center monitors a registration request of the server a, the micro service center may send a client update notification to the client, where the update notification includes time when the server a joins, an identifier of the server a, a service provided by the server, and the like, to notify that the client is added with the client a, and after receiving the update notification, the client may add information of the server a to a server list corresponding to the provided service according to the server update notification.
For another example, each server may periodically send a heartbeat packet to the micro service center, and if the micro service center does not monitor the heartbeat packet of the server B in a continuous period, the micro service center may consider that the server B is deleted, and send a server update notification to the client. The update notification includes the identifier of the server B to notify the client that the server B is added. After receiving the update notification, the client may delete the information of the server B from the local server list according to the server update notification.
In particular implementations, the Zookeeper or Zookeeper cluster may be used as a microservice center. Wherein, zookeeper is a distributed and open source distributed application program coordination service, and is an important component of Hadoop and Hbase. It is a software that provides a consistent service for distributed applications, and the functions provided include: configuration maintenance, domain name service, distributed synchronization, group service, etc.
Step 202, store the server list.
In this embodiment, after acquiring the server list sent by the micro service center, the client may store the server list locally. If the client stores the server list locally, the latest server list acquired from the micro-service center can be replaced by the old server list corresponding to the client locally.
Step 203, obtain the locally stored server list.
In this embodiment, when the client needs to call a service, the client may read the local configuration file to obtain a locally stored server list. Specifically, as described in the above embodiments, the details are not repeated herein.
And 204, selecting a target server from the server list according to a preset load balancing rule.
Step 205, sending a service calling request to the target server.
In this embodiment, steps 203-205 are similar to steps 101-103, and therefore are not described herein again.
In the embodiment of the application, before the locally stored server list is obtained, a server update notification sent by the micro-service center can be obtained, wherein the update notification includes the server list and stores the server list, when the service needs to be called, the locally stored server list can be obtained, and a target server is selected according to a preset load balancing rule to send a service calling request to the target server. Therefore, the local server list can be updated in real time by acquiring the server updating notice sent by the micro-service center, the latest server list is utilized to call the service, and the accuracy of service calling is improved.
In practical application, in order to avoid that the micro service center frequently sends a server list update notification to each client, the clients are disturbed. Based on this, in an embodiment of the present application, before obtaining the server update notification sent by the micro service center, a server list subscription request may be sent to the micro service center.
In this embodiment, each client may send a server list subscription request to the micro service center as needed, where the server list subscription request includes an identifier of the client, an identifier of a device where the client is located, and the like. Therefore, the micro-service center can acquire the information of each client sending the server list subscription request according to the received server list subscription request, and the micro-service center can determine which clients subscribe to the server list update notification.
When the state of any server side is changed, the micro-service center can send the server side update notification to the client sides which subscribe the server side update notification, so that the problem that the server side update notification is sent to all the client sides and other client sides are disturbed is avoided.
Since each server may provide different services and one server may also provide multiple services, in order to improve personalized requirements, further, when the micro service center has multiple types of services, the client may specify the type of service to be subscribed when subscribing to the server list update notification. The server list subscription request sent to the micro service center may include an identifier of a service type of the subscription. Therefore, when a certain service type provided by a service end changes, such as the service type is deleted, the micro service center can send a service end list updating notification to the client subscribed to the service type so as to notify the client of the service end list of the service type currently provided.
In the embodiment of the application, before the server update notification sent by the micro-service center is obtained, a server list subscription request can be sent to the micro-service center. Therefore, by sending the server list subscription request to the micro-service center, the micro-service center can send the server list update notification to the corresponding client according to the subscription request, so that the update notification is prevented from being sent to all the clients, and the disturbance to other clients is reduced.
In order to further improve the service invocation efficiency, in an embodiment of the present application, if there are a plurality of server lists locally stored in the client, and each server list corresponds to a different service type, a target server list may be obtained from the locally stored server list, and a target server is selected from the target server list. Fig. 3 is a schematic flowchart of another micro-service invocation method provided in the embodiment of the present application.
As shown in fig. 3, the micro-service calling method includes:
step 301, determining a target service type to be acquired according to a source data type to be processed currently.
In this embodiment, the client may locally store a plurality of server lists, where each server list corresponds to a different service type, such as an image processing service, a voice recognition service, a voice synthesis service, and the like.
For example, a certain server list corresponds to a speech recognition service, which indicates that the server list includes a list of servers capable of providing the speech recognition service.
When the client needs to send a call request to the server, the client can determine a target service type to be acquired according to the type of the current source data to be processed. For example, if the type of the source data to be processed is an image type, it may be determined that the corresponding service type is an image processing service; as another example, the type of the source data to be processed is a voice type, and the target service type may be determined to be a voice recognition service.
Step 302, a locally stored target service end list corresponding to the target service type is obtained.
After the target service type is obtained, a target service end list corresponding to the target service type can be obtained from the plurality of service end lists according to the service type corresponding to each locally stored service end list.
And 303, selecting a target server from the target server list according to a preset load balancing rule.
After the target server list is obtained, the target server can be selected from the target server list according to a preset load balancing rule. For example, a server is randomly selected from the target server list as a target server.
In this embodiment, the method for selecting the target server is similar to the step 102, and therefore, the description thereof is omitted here.
Step 304, sending a service calling request to the target server.
In this embodiment, step 304 is similar to step 103 described above and therefore will not be described herein again.
In the embodiment of the application, if a plurality of locally stored server lists are provided and the service types corresponding to each server list are different, when the locally stored server list is obtained, the target service type to be obtained can be determined according to the current source data type to be processed, the locally stored target server list corresponding to the target service type is obtained, so that the target server is selected from the target server list, and a service calling request is sent to the target server. Therefore, when a plurality of server lists are stored locally, the target service type to be acquired is determined according to the type of the current source data to be processed, and the target server list is determined according to the target service type, so that the service calling efficiency is improved.
In order to implement the foregoing embodiments, the present application further provides a micro-service invoking method. Fig. 4 is a flowchart illustrating another method for invoking a micro service according to an embodiment of the present disclosure.
The method for calling the micro-service in the embodiment of the application can be executed by a micro-service center, for example, executed by a Zookeeper or a Zookeeper cluster, so as to realize dynamic monitoring on the server side.
As shown in fig. 4, the micro-service calling method includes:
step 401, updating the server list when monitoring the state change of any server.
In this embodiment, the micro service center may monitor each server that has been registered in the micro service center, and update the server list when monitoring that any server state has changed.
As a possible implementation manner, a monitoring message may be sent to each server at preset intervals, and if the feedback message is not received within the preset time, the server may be considered to stop providing services, and the server may be deleted from the server list.
As another possible implementation manner, each server may send a heartbeat packet to the micro service center at preset intervals, and if the micro service center does not monitor the heartbeat packet of any server within a continuous time period, for example, for 5 minutes or 10 minutes continuously, the server may be considered to stop providing services, and the server may be deleted from the server list.
It should be noted that the continuous time period may be determined as needed, and the present application is not limited thereto.
As another possible implementation manner, the server may send a registration request to the micro service center to perform registration in the micro service center. The registration request may include information such as an identifier of the server, a type of service provided, and a corresponding interface.
When the micro-service center obtains the registration request sent by any one of the service terminals, the micro-service center can add any one of the service terminals to the corresponding service terminal list according to the service type provided by any one of the service terminals, so as to update the service terminal list.
In specific implementation, the Zookeeper or Zookeeper cluster can be used as a microservice center, and the Python server can be registered when being started. Specifically, after the Python server is successfully started, firstly, when the Python parent process service is started, a child process is derived at the same time, when the child process monitors that the file is changed, the child process calls an exit method of the child process to exit the process, sends a special identifier to the parent process, and starts the child process again after the parent process obtains the special identifier. And finally, sending service information to the micro-service center for service registration.
Step 402, sending a server list change notification to the client, so that the client updates the local server list.
After updating the server list, the micro service center may send a server list change notification to the client, so that the client updates the local server list. The server list change notification may include a latest server list, so that the client replaces the locally stored server list with the latest server list. Or, the server list change notification may also include the server information with the changed state, so that the client updates the locally stored server list according to the server information with the changed state.
For example, in a continuous period, if a heartbeat packet of a certain server is not monitored, the micro service center may delete the server from the server list and send a server list update notification to the client, where the update notification may include an updated server list, and the updated server list does not include the server. Or, the update notification may also include the information of the server, so that the client deletes the server from the local server list according to the information of the server.
If there is a newly registered server, the micro service center may send a server list update notification to the client. The update notification may include a server list with newly added servers, that is, a latest server list, so that the client replaces the locally stored server list with the latest server list. Or, the update notification may also include information of a newly added server, so that the client adds the information of the server in the local server list according to the information of the server.
In the embodiment of the application, when the state of any one server is monitored to be changed, the server list is updated, and a server list change notification is sent to the client, so that the client updates the local server list. Therefore, dynamic monitoring of the server can be achieved, and when the state of the server changes, an update notification is sent to the client, so that the client can update the locally stored server list in real time.
In order to improve the accuracy of updating the server list, in an embodiment of the present application, a server with a changed state may be updated to a server list corresponding to a service type to which the server belongs. Fig. 5 is a schematic flowchart of another micro-service invocation method provided in the embodiment of the present application.
As shown in fig. 5, the micro-service calling method includes:
step 501, when monitoring the state change of any service end, determining the service type of any service end.
In this embodiment, each server may provide one or more types of services, and when it is monitored that the state of any server changes, the service type of any server may be determined. The service type of any one service end may be one or multiple.
Step 502, updating a server list corresponding to the service type.
After the service type of any service end is determined, the service end list corresponding to the service type can be determined and updated according to the service type of any service end and the service type corresponding to each service end list. Here, the service type to which the server belongs may be considered as a service type that the server can provide.
For example, if the service types of the service end with a changed state are two types, i.e., S1 and S2, the service end list corresponding to the service type S1 is updated, and the service end list corresponding to the service type S2 is updated.
In this embodiment, the server list corresponding to the service type to which the server belongs is updated according to the service type to which the server whose state is changed belongs, so that the updating accuracy is improved.
Step 503, sending a server list change notification to the client, so that the client updates the local server list.
In this embodiment, step 503 is similar to step 402 and thus is not described herein again.
In the embodiment of the application, when the state of any service end is monitored to be changed and the service end list is updated, the service type of any service end can be determined, the service end list corresponding to the service type is updated, and a service end list change notification is sent to the client, so that the client updates the local service end list. Therefore, the server list corresponding to the service type is updated according to the service type to which the server with the changed state belongs, and the updating accuracy is improved.
The method for calling the micro service in the embodiment of the present application is further described below with reference to fig. 6, by taking a client implemented based on a Java language, a server implemented based on a Python language, and a zookeeper cluster as an example. Fig. 6 is a schematic process diagram of a micro service invocation according to an embodiment of the present application.
In fig. 6, 2 Java clients, 3 Python servers, and 1 zookeeper cluster are shown. As shown in fig. 6, step 1: the 3 Python server sides send registration requests to the zookeeper cluster, and the zookeeper cluster can determine that a newly added server side exists according to the registration requests; step 2: 2 Java client-sides send subscription requests to the zookeeper cluster; and 3, step 3: when monitoring that the state of the server is changed, the zookeeper cluster sends a server list change notification to the Java client; step 4, the Java client updates the local configuration file according to the change notification, specifically updates a locally stored server list; step 5, when the Java client needs to call the service, reading a local configuration file and acquiring a locally stored server list; step 6, the load balancer determines a target server by using a load balancing dual-computer hot standby scheme preset in the Java client; and 7, sending a service calling request to a Python server.
In order to implement the foregoing embodiments, an apparatus for invoking micro-services is further provided in the embodiments of the present application. Fig. 7 is a schematic structural diagram of a micro service invocation device according to an embodiment of the present application.
The micro-service calling device in the embodiment of the application can be configured in a client to realize service discovery and load balancing in micro-service calling.
As shown in fig. 7, the micro-service invocation apparatus 700 includes: a first obtaining module 710, a selecting module 720 and a sending module 730.
A first obtaining module 710, configured to obtain a locally stored server list;
a selecting module 720, for selecting a target server from the server list according to a preset load balancing rule;
the sending module 730 is configured to send a service invocation request to the target server.
In a possible implementation manner of the embodiment of the present application, the apparatus may further include:
the second acquisition module is used for acquiring a server side updating notice sent by the micro service center, wherein the updating notice comprises a server side list;
and the storage module is used for storing the server list.
In a possible implementation manner of the embodiment of the present application, the sending module 730 is further configured to send a server list subscription request to the micro service center.
In a possible implementation manner of the embodiment of the present application, there are a plurality of locally stored server lists, and service types corresponding to each server list are different, where the first obtaining module 710 is configured to:
determining a target service type to be acquired according to the type of the current source data to be processed;
and acquiring a locally stored target service end list corresponding to the target service type.
It should be noted that the above explanation of the embodiment of the client-side micro service invoking method is also applicable to the micro service invoking device of the embodiment, and therefore is not described herein again.
The micro-service calling device of the embodiment of the application selects the target server from the server list by acquiring the locally stored server list and according to the preset load balancing rule, and sends the service calling request to the target server. Therefore, through the locally stored server list, the client can efficiently and quickly acquire the available target server, and the target server is called through the preset load balancing rule, so that service discovery and load balancing in micro-service calling are realized.
In order to implement the foregoing embodiments, an apparatus for invoking micro-services is further provided in the embodiments of the present application. Fig. 8 is a schematic structural diagram of another microservice calling apparatus according to an embodiment of the present disclosure.
The micro-service calling device in the embodiment of the application can be configured in a micro-service center to realize service registration, dynamic monitoring and the like on the state of a server.
As shown in fig. 8, the micro-service invocation apparatus 800 includes: an update module 810 and a send module 820.
The updating module 810 is configured to update the server list when monitoring that any server state changes;
a sending module 820, configured to send a server list change notification to the client, so that the client updates the local server list.
In a possible implementation manner of the embodiment of the present application, monitoring that any service end is changed includes:
in a continuous period, the heartbeat packet of any server is not monitored;
or,
and acquiring a registration request sent by any server.
In a possible implementation manner of the embodiment of the present application, the updating module 820 is configured to:
determining the service type of any one server;
and updating a server list corresponding to the service type.
It should be noted that the above explanation of the embodiment of the method for invoking the micro-service at the micro-service center side is also applicable to the device for invoking the micro-service of the embodiment, and therefore, no further description is given here.
The micro-service calling device of the embodiment of the application updates the server list and sends the server list change notification to the client when monitoring the state change of any server, so that the client updates the local server list. Therefore, the change of the dynamic monitoring server side in the micro-service calling is realized.
In order to implement the foregoing embodiments, an electronic device is further provided in an embodiment of the present application, including a processor and a memory;
the processor reads the executable program code stored in the memory to run a program corresponding to the executable program code, so as to implement the micro-service calling method according to the embodiment.
In order to implement the foregoing embodiments, the present application further proposes a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements the micro-service calling method according to the foregoing embodiments.
In the description of the present specification, the terms "first", "second" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present application, "plurality" means at least two, e.g., two, three, etc., unless specifically limited otherwise.
Although embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application, and that variations, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present application.

Claims (16)

1. A method for invoking a micro-service, comprising:
acquiring a locally stored server list;
selecting a target server from the server list according to a preset load balancing rule;
and sending a service calling request to the target server.
2. The method of claim 1, wherein prior to said obtaining the locally stored server list, further comprising:
acquiring a server side updating notice sent by a micro service center, wherein the updating notice comprises the server side list;
and storing the server list.
3. The method of claim 2, wherein before the obtaining of the server update notification sent by the micro service center, further comprising:
and sending a server list subscription request to the micro service center.
4. The method according to any one of claims 1 to 3, wherein there are a plurality of locally stored server lists, and the service type corresponding to each server list is different, and the obtaining the locally stored server list includes:
determining a target service type to be acquired according to the type of the current source data to be processed;
and acquiring a locally stored target service end list corresponding to the target service type.
5. A method for invoking a micro-service, comprising:
updating a server list when the state of any server is monitored to be changed;
and sending a server list change notification to the client so that the client updates a local server list.
6. The method of claim 5, wherein the monitoring that any one of the servers has changed comprises:
in a continuous time interval, not monitoring the heartbeat packet of any server;
or,
and acquiring a registration request sent by any server.
7. The method of claim 5 or 6, wherein said updating the server list comprises:
determining the service type of any one server;
and updating a server list corresponding to the service type.
8. A microservice invocation device, comprising:
the first acquisition module is used for acquiring a locally stored server list;
the selecting module is used for selecting a target server from the server list according to a preset load balancing rule;
and the sending module is used for sending a service calling request to the target server.
9. The apparatus of claim 8, further comprising:
the second acquisition module is used for acquiring a server side updating notice sent by a micro service center, wherein the updating notice comprises the server side list;
and the storage module is used for storing the server list.
10. The apparatus of claim 9, wherein the sending module is further configured to send a server list subscription request to the microservice center.
11. The apparatus according to any one of claims 8-10, wherein there are multiple locally stored server lists, and a service type corresponding to each server list is different, and the first obtaining module is configured to:
determining a target service type to be acquired according to the type of the current source data to be processed;
and acquiring a locally stored target service end list corresponding to the target service type.
12. A microservice invocation device, comprising:
the updating module is used for updating the server list when monitoring the state change of any server;
and the sending module is used for sending a server list change notification to the client so that the client updates the local server list.
13. The apparatus of claim 12, wherein the monitoring that any server has changed comprises:
in a continuous time interval, not monitoring the heartbeat packet of any server;
or,
and acquiring a registration request sent by any server.
14. The apparatus of claim 12 or 13, wherein the update module is to:
determining the service type of any one server;
and updating a server list corresponding to the service type.
15. An electronic device comprising a processor and a memory;
wherein the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory for implementing the micro service call method according to any one of claims 1 to 4 or implementing the micro service call method according to any one of claims 5 to 7.
16. A non-transitory computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the micro-service invocation method according to any of claims 1-4 or implements the micro-service invocation method according to any of claims 5-7.
CN202011484237.3A 2020-12-15 2020-12-15 Micro-service calling method and device, electronic equipment and storage medium Pending CN112732456A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011484237.3A CN112732456A (en) 2020-12-15 2020-12-15 Micro-service calling method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011484237.3A CN112732456A (en) 2020-12-15 2020-12-15 Micro-service calling method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112732456A true CN112732456A (en) 2021-04-30

Family

ID=75602671

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011484237.3A Pending CN112732456A (en) 2020-12-15 2020-12-15 Micro-service calling method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112732456A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114650221A (en) * 2022-02-21 2022-06-21 福州汇思博信息技术有限公司 Method and system for quickly calling service interface
CN115022318A (en) * 2022-05-30 2022-09-06 在线途游(北京)科技有限公司 Message publishing method and system based on micro-service architecture
CN115150457A (en) * 2022-06-28 2022-10-04 亿咖通(湖北)技术有限公司 Micro-service management method, vehicle-mounted system and vehicle-mounted equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090282005A1 (en) * 2008-05-09 2009-11-12 Samsung Electronics Co. Ltd. Sip network-based content sharing method and system
US20180027080A1 (en) * 2016-07-22 2018-01-25 Cisco Technology, Inc. Scaling service discovery in a micro-service environment
CN109104483A (en) * 2018-08-10 2018-12-28 北京东软望海科技有限公司 A kind of method and device of the micro services dynamic load leveling based on event notice
CN109254845A (en) * 2018-07-27 2019-01-22 苏州橘猫网络科技有限公司 A kind of linear expansion implementation method calculating server-side applied to distributed communication
US20200326981A1 (en) * 2019-04-09 2020-10-15 Cisco Technology, Inc. Distributed object placement, replication, and retrieval for cloud-scale storage and data delivery
CN111800462A (en) * 2020-05-28 2020-10-20 中国平安财产保险股份有限公司 Micro-service instance processing method and device, computer equipment and storage medium
WO2020233206A1 (en) * 2019-05-20 2020-11-26 深圳前海微众银行股份有限公司 Method and device for processing code execution request

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090282005A1 (en) * 2008-05-09 2009-11-12 Samsung Electronics Co. Ltd. Sip network-based content sharing method and system
US20180027080A1 (en) * 2016-07-22 2018-01-25 Cisco Technology, Inc. Scaling service discovery in a micro-service environment
CN109254845A (en) * 2018-07-27 2019-01-22 苏州橘猫网络科技有限公司 A kind of linear expansion implementation method calculating server-side applied to distributed communication
CN109104483A (en) * 2018-08-10 2018-12-28 北京东软望海科技有限公司 A kind of method and device of the micro services dynamic load leveling based on event notice
US20200326981A1 (en) * 2019-04-09 2020-10-15 Cisco Technology, Inc. Distributed object placement, replication, and retrieval for cloud-scale storage and data delivery
WO2020233206A1 (en) * 2019-05-20 2020-11-26 深圳前海微众银行股份有限公司 Method and device for processing code execution request
CN111800462A (en) * 2020-05-28 2020-10-20 中国平安财产保险股份有限公司 Micro-service instance processing method and device, computer equipment and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114650221A (en) * 2022-02-21 2022-06-21 福州汇思博信息技术有限公司 Method and system for quickly calling service interface
CN115022318A (en) * 2022-05-30 2022-09-06 在线途游(北京)科技有限公司 Message publishing method and system based on micro-service architecture
CN115022318B (en) * 2022-05-30 2023-08-29 在线途游(北京)科技有限公司 Message publishing method and system based on micro-service architecture
CN115150457A (en) * 2022-06-28 2022-10-04 亿咖通(湖北)技术有限公司 Micro-service management method, vehicle-mounted system and vehicle-mounted equipment

Similar Documents

Publication Publication Date Title
CN110603837B (en) Method for associating network slice instances of a mobile radio communications network with network functions
CN112732456A (en) Micro-service calling method and device, electronic equipment and storage medium
US20220094761A1 (en) Server Invocation Method and Proxy Server
CN111226497B (en) Service registration in a communication network
JP7326443B2 (en) NF service consumer restart detection using direct signaling between NFs
WO2020070118A1 (en) Methods and apparatus for analytics function discovery
WO2009003385A1 (en) Methods, apparatus and systems for updating equipment
CN111414230A (en) Service management system, service management method, server, and storage medium
CN117397230A (en) Method, system and computer readable medium for distributing Network Function (NF) High Availability (HA) topology information in a core network
CN110505318B (en) Uniform resource locator addressing method and device, and network system
CN112351077B (en) Application service operation method, system, device and storage medium
KR20200118486A (en) How and device to update subscription information
CN112235378B (en) Data updating method and device, storage medium and electronic equipment
CN113645259B (en) Micro-service elastic expansion method, system and related equipment
US20240057033A1 (en) Methods, systems, and computer readable media for avoiding sending of duplicate notifications for overlapping subscriptions at network function (nf) repository function (nrf)
US20240298196A1 (en) Methods and Apparatuses for Enhanced 5GC Restoration When a Network Function (NF) Set is Deployed in the Network
CA2682063C (en) Network node for providing remote client deactivation
WO2019061400A1 (en) Enhanced service discovery for network function binding
EP2053829A1 (en) Method and devices for data context sharing
CN113542319A (en) Service providing entity change notification method, device and system used in Dubbo framework
CN114928635B (en) Micro-service calling method and related equipment
CN118175202B (en) Proxy connection method and device and related equipment
CN114978892B (en) Target node determining method and device
CN115361440B (en) Method and device for updating endpoint resources of multiple Kubernetes clusters and electronic equipment
US12075343B2 (en) Methods, systems, and computer readable media for network slice selection function recovery

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
CB02 Change of applicant information

Address after: Room 221, 2 / F, block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone, 100176

Applicant after: Jingdong Technology Holding Co.,Ltd.

Address before: Room 221, 2 / F, block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone, 100176

Applicant before: Jingdong Digital Technology Holding Co., Ltd

CB02 Change of applicant information