CN117931325A - Method for automatically discovering java bean resources by micro-service system - Google Patents
Method for automatically discovering java bean resources by micro-service system Download PDFInfo
- Publication number
- CN117931325A CN117931325A CN202410331486.0A CN202410331486A CN117931325A CN 117931325 A CN117931325 A CN 117931325A CN 202410331486 A CN202410331486 A CN 202410331486A CN 117931325 A CN117931325 A CN 117931325A
- Authority
- CN
- China
- Prior art keywords
- resource
- service
- server
- resource center
- discovery
- 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.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4482—Procedural
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
- G06F9/4451—User profiles; Roaming
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method for automatically discovering Java bean resources by a micro-service system, which comprises the steps of constructing a resource center server and a resource discovery server, and carrying out resource configuration; starting a resource center server, and pulling up a resource discovery thread to perform resource discovery by pulling up two built-in daemon threads; and starting the resource discovery server, and pulling up the resource discovery thread to perform resource discovery by pulling up the two built-in daemon threads. The method solves the problems by utilizing a resource center and a resource discovery mode, effectively avoids project resource waste, reduces the difficulty of resource migration in a development stage, a testing stage and a production stage, reduces the problem of difficult server migration by adopting a file persistent storage mode, and furthest reduces the integrated workload of development.
Description
Technical Field
The invention relates to the technical field of computer resource allocation, in particular to a method for automatically discovering java bean resources by a micro-service system.
Background
The business logic which is required to be flexibly changed is frequently encountered in the business scene, the logic is compiled into the language which can be read and understood by the java virtual machine for deployment after the logic is compiled in a conventional programming mode, the business scene which is required to be flexibly changed is encountered in the conventional programming mode, so that a lot of troubles are brought to an online business system, and a lot of development resources are wasted in each logic change of the business scene.
Currently open-source engine technologies such as flow engines and rule engines help developers to cope with complex and changeable scenes, and the engine technologies can be expressed as follows: under certain conditions, executing certain tasks, and although an engine technology formulates a forwarding standard to abstract changeable business logic, the method must reach a configuration effect under the condition that all resources are sufficient, and the resource configuration is a JAVA bean depending on a business module, wherein the JAVA bean is a reusable component written in JAVA language; if the resources are manually input, more than tens of java beans of one service module are fewer, at least more than ten attributes exist in one java bean, and the online of one system needs to be subjected to development environment, test environment, gray test environment and production environment, so that huge troubles are brought to input work, and manual input is easy to make mistakes.
Disclosure of Invention
Aiming at the defects in the prior art, the invention provides a method for automatically discovering java bean resources by a micro-service system.
In order to achieve the aim of the invention, the invention adopts the following technical scheme:
a method for automatically discovering Java bean resources by a micro-service system comprises the following steps:
constructing a resource center server and a resource discovery server, and carrying out resource allocation;
Starting a resource center service end, reading service switch attributes of resource root labels in a resource catalog of the resource center service end by pulling up two built-in daemon threads, judging the service switch attributes to pull up a resource discovery thread, and writing all java bean resources of the resource center service end into service resource data labels under the resource root labels in the resource catalog of the resource center service end for persistence;
Starting a resource discovery service end, reading service switch attributes of resource root labels in a resource catalog of the resource discovery service end by pulling up two built-in daemon threads, judging the service switch attributes to pull up the resource discovery thread, and writing all java bean resources which are transmitted into the resource discovery service end through a resource center service address in resource center service of the resource root labels sign in the resource catalog of the resource discovery service end into service resource data labels under the resource root labels in the resource catalog of the resource center service end for persistence.
Optionally, the resource center server adds a resource center server storage file in the resource center server resource directory configuration, and sets a resource center server resource discovery thread, a resource center server first daemon thread and a resource center server second daemon thread.
Optionally, the first daemon thread of the resource center server is configured with a first daemon task, a second daemon task and a third daemon task;
the first daemon is specifically to check the service switch attribute of the resource root tag in the resource catalog of the resource center server side and judge whether the service switch attribute is on or not; if yes, checking whether the resource discovery thread of the resource center server dies, and if so, restarting; otherwise, checking whether the resource discovery thread of the resource center server runs or not, and if so, terminating the resource discovery thread of the resource center server;
the second daemon is specifically to check the state of a second daemon thread of the resource center; if the dead, the device is pulled up again;
The third daemon is specifically to acquire the ip address, the service port and the service context of the resource center server, send the ip address, the service port and the service context to the resource daemon, and store the ip address, the service port and the service context in a resource center Wipe list tag under a resource root tag under a resource center server storage file of a resource center server.
Optionally, the resource discovery server adds a resource discovery server storage file in a resource discovery server resource directory configuration, and sets a resource discovery server resource discovery thread, a resource discovery server first daemon thread and a resource discovery server second daemon thread.
Optionally, the first daemon thread of the resource discovery server is configured with a first daemon task, a second daemon task and a third daemon task;
The first daemon is specifically to check the service switch attribute of the resource root tag in the resource directory of the resource discovery server, and judge whether the service switch attribute is on or not; if yes, checking whether the resource discovery thread of the resource discovery server dies, and if so, restarting; otherwise, checking whether the resource discovery thread of the resource discovery server runs or not, and if so, terminating the resource discovery thread of the resource discovery server;
the second daemon is specifically to check the state of a second daemon thread of the resource discovery server; if the dead, the device is pulled up again;
The third daemon is specifically to obtain the ip address, the service port and the service context of the resource discovery server, send the ip address, the service port and the service context to the resource daemon, and store the ip address, the service port and the service context in a resource-root label Wipe list label under a resource-discovery server storage file of a resource directory of the resource discovery server through the resource daemon.
Optionally, the resource guard is configured to intercept a request that the resource preservation interface of the resource center server does not configure the whitelist.
Optionally, the resource discovery thread writes all the java bean resources of the resource center server into the service resource data tag under the resource root tag in the resource directory of the resource center server for persistent storage, and specifically includes the following steps:
A1, acquiring a resource center server side storage file under a resource directory of a resource center server side, reading a service switch attribute of a resource root tag in the resource center server side storage file, and judging whether the service switch attribute is on or not; if yes, executing the step A2; otherwise, ending the flow;
A2, acquiring a resource center server side storage file under a resource directory of a resource center server side, reading a service type attribute of a resource root tag in the resource center server side storage file, and judging whether the service type attribute is the resource center server side or not; if yes, executing the step A3; otherwise, executing the step A5 for the server for resource discovery;
a3, obtaining all java classes with @ table annotation of the resource center server through java reflection, converting the java classes with @ table annotation into Map objects, storing an array of List types as new waiting resource data, and then obtaining the IP address, the server port and the server context of the current service through the resource center server to form a new unique grouping identifier;
A4, reading a resource data json character string under a persistent storage resource data label of a resource root label sign in a resource center server side storage file, converting the resource data json character string into a Map type data format, finding out an old unique group label and resource data which are equal to a new unique group label in A3 from the Map type data format, covering the old unique group label and the resource data by using the new unique group label in A3 and the new resource data to be saved, if the unique group label which is equal to the new unique group label in A3 is not found out from the Map type data format, directly storing the new unique group label in A3 and the new resource data to be saved into the Map type data format, converting the Map type data format into the json character string, and storing the json character string into the persistent storage resource data label of the resource root label sign in the resource center server side storage file in a covering mode, and ending the flow;
a5, defining a time acquisition Boolean variable, acquiring the system time of the current resource center server, and checking whether the current system time is within a set time period; if yes, assigning true to the time acquisition Boolean variable, and executing the step A6; otherwise, assigning false to the time acquisition Boolean variable, and executing the step A6;
A6, reading character strings in a permanent storage resource center service address label of a resource root mark sign in a resource center service end storage file, separating Fu Cafen character strings in the permanent storage resource center service address label by commas to obtain a source resource center service address array, defining a new resource center service address array, and judging that the time acquisition Boolean variable in A5 is true or false; if true, replacing a separator @ _ @0 in a character string in a persistent storage resource center service address label of a resource root mark sign in a resource center service end storage file with @ _ @1, and then storing all the resource center service addresses in a source resource center service address array into a new resource center service address array to execute the step A7; if false, circularly judging whether the value of each resource center service address @ _ @ divider in the source resource center service address array character string variables is 1, if yes, storing all the resource center service addresses in the source resource center service address array into a new resource center service address array, otherwise, outputting abnormal resource center service addresses into a log file;
A7, judging whether the length of the service address array of the new resource center in the A6 is smaller than 1; if yes, ending the flow; otherwise, executing the step A8;
A8, obtaining all java classes with @ table annotation of the resource center server through java reflection, converting the java classes with @ table annotation into Map objects, storing an array of List types as new waiting resource data, and then obtaining the IP address, the server port and the server context of the current service through the resource center server to form a new unique grouping identifier; the new unique grouping identification and the new resource data to be saved form new Map format data;
A9, defining a Map type storage rollback information object, circularly acquiring a new resource center service address array in A6, circularly acquiring a first resource center service address in the new resource center service address array in A6 as a rollback identifier for the first time, carrying a rollback identifier to request to acquire a resource interface, and forming a new data storage rollback information object by a json array returned by the acquired resource interface and the rollback identifier;
A10, requesting the new Map format data transmitted into A8 by the resource center service address as a storage parameter, intercepting the request of the resource storage interface by using the resource guard of the resource center service end, acquiring the Ip address of the request end, the service end port and the service end context, and splicing the Ip address, the service end port and the service end context into a current unique packet identifier; then, acquiring a white list configuration in a resource guard Wipe list configuration label under a resource root label in a resource center server-side storage file, and judging whether the white list configuration contains a current unique grouping identifier or not; if yes, executing the step A11; otherwise, intercepting the request, returning a failure ending mark, and executing the step A13;
A11, calling a resource preservation interface to acquire an input preservation parameter, acquiring json character string content in a persistent storage resource data tag of a resource root mark sign in a resource storage file under a resource target of a resource center server, converting the input and output of the preservation parameter into the Map type object, converting the Map type object into json character string, and storing the json character string in a service resource data tag under the resource root mark in the resource center server storage file in a covering mode;
A12, judging whether the executing process of the step A11 is abnormal or not; if yes, the resource saving interface returns a failure ending mark, and the step A13 is executed; otherwise, the resource saving interface returns a successful continuing identification, and the step A14 is executed;
A13, receiving a return result of the resource center service, and judging whether the return result value is equal to a failure ending mark; if yes, interrupting the circulation of the new resource center service address array in the A6, circulating the storage rollback information object in the A9, transmitting json array parameters to the json array parameters by using the json array stored in the storage rollback information object and the rollback identification request resource storage interface each time, executing the resource center service rollback operation, then acquiring the service times of the abnormal occurrence of the resource center service address in the current service memory by using the rollback identification, judging whether the abnormal service times are greater than the set number, and if yes, adding the abnormal identification to the abnormal resource center address in the resource center service label under the resource root label of the resource center service end resource catalog; otherwise, adding one abnormal service frequency to the current service memory for recording;
a14, judging whether the new resource center service address array in the A6 is circularly completed or not; if yes, ending the flow; otherwise, the next resource center service address in the new resource center service address array variable in the A6 is acquired in the next cycle, and the step A9 is returned.
The invention has the following beneficial effects:
The method solves the problems by utilizing a resource center and a resource discovery mode, effectively avoids project resource waste, reduces the difficulty of resource migration in a development stage, a testing stage and a production stage, reduces the problem of difficult server migration by adopting a file persistent storage mode, and furthest reduces the integrated workload of development.
Drawings
FIG. 1 is a flow chart of a method for automatically discovering Java Bean resources by a micro-service system according to the present invention.
Detailed Description
The following description of the embodiments of the present invention is provided to facilitate understanding of the present invention by those skilled in the art, but it should be understood that the present invention is not limited to the scope of the embodiments, and all the inventions which make use of the inventive concept are protected by the spirit and scope of the present invention as defined and defined in the appended claims to those skilled in the art.
As shown in fig. 1, the embodiment of the present invention provides a method for automatically discovering java bean resources by a micro service system, which includes the following steps S1 to S3:
s1, constructing a resource center server and a resource discovery server, and carrying out resource allocation;
S2, starting a resource center service end, reading service switch attributes of resource root labels in a resource catalog of the resource center service end by pulling up two built-in daemon threads, judging the service switch attributes to pull up a resource discovery thread, and writing all java bean resources of the resource center service end into service resource data labels under the resource root labels in the resource catalog of the resource center service end for persistence;
And S3, starting the resource discovery service end, reading service switch attributes of resource root labels in a resource catalog of the resource discovery service end by pulling up two built-in daemon threads, judging the service switch attributes to pull up the resource discovery thread, and writing all java bean resources which are transmitted into the resource discovery service end through a resource center service address in a resource center service of a resource root label sign in the resource catalog of the resource discovery service end into service resource data labels under the resource root label in the resource catalog of the resource center service end for persistence storage.
In an optional embodiment of the present invention, the present invention integrates the independent jar package into the service end based on spring in a java jar package integration manner, the service end integrating the java jar package can be used as a resource center service end and also can be used as a service end for resource discovery, whether the service end is used as a resource center service end or a resource discovery service end, an xml format resource file for data persistence storage must be added in a resource directory configuration of the service end, and the initial content of the xml format resource file is:
< root service type attribute= "core/find" service switch attribute "close/open" >
< Resource center service Address Label > </resource center service Address Label >
< Resource data tag > </resource data tag >
< Resource conservation Wipe List Label > </resource conservation Wipe List Label >
Root-
The value of the service type attribute of the root tag is equal to core and represents that the service is a resource center service, the value of the service type attribute is equal to find and represents that the service is a resource discovery service, the value of the service switch attribute of the root tag is equal to open and represents that the resource discovery thread is opened, the value of the service switch attribute is equal to close and represents that the resource discovery thread is closed, the < resource center service address tag > tag is used for configuring a resource center service address, the < resource data tag > tag is used for permanently storing resource data, and the < resource guard Wipe list tag > tag is used for white list configuration of resource guard.
In the invention, a resource file < root service type attribute= "core" service switch attribute= "open" > tag < resource center service address tag > tag under the resource center service end does not configure any content, and the resource center service end provides a resource acquisition interface (api interface/RESTful interface), a resource storage interface (api interface/RESTful interface), an api interface (introduction access mode) and a RESTful interface (remote access mode). The resource acquisition interface is not referred to, and returns all resource data information (request mode POST during remote access). Resource preservation interface parameters: the type of the parameter character string is transmitted, the parameter name is resource, and the parameter character string is used for transmitting and storing resources (POST in a remote access request mode).
Resource parameter example:
{
the service end IP_service end port_service end context [ { class path_class name: { attribute name: attribute type }, { class path_class name: { attribute name: attribute type })
}
Content example of < resource data tag > tag under resource file root tag of server-side resource directory xml format:
{
Service side 1 IP_service side 1 port_service side 1 context [ { class Path_class name: { attribute name: attribute type }, { class path_class name: { attribute name: attribute type } ],
Service side 2 IP_service side 2 port_service side 2 context [ { class path_class name: { attribute name: attribute type }, { class path_class name: { attribute name: attribute type })
}
After receiving the parameters, the interface executes the first coverage update according to the unique identifier of the character string (the context of the port_requester of the requester).
In the invention, a resource discovery server must configure a resource center service address in a < resource center service address label > label under a server resource catalog xml format resource file < root service type attribute= "find" service switch attribute= "open" >, the resource center service address is configured with at least one, a plurality of commas for segmentation are configured, each address is spliced with a number (0 represents an address exception, 1 represents an address normal) by using an @ _ @ segmenter, and the configuration content is as follows: < root > < resource center service address tag > http:// service side 1IP address: port of service side 1/context of service side 1@ 1, http:// service side 2IP address: port of service side 2/context of service side 2@ 0 </resource center service address tag > </root >.
Specifically, the developer integrates the java jar package into the a server and the B server (for example, the IP address of the a server is 172.3.0.1, the context of the a server is rompConsoleA, the port of the a server is 8803, the a server has a java bean named Person, the Person class path is com.romp, the Person has a string type attribute named name, the IP address of the B server is 172.3.0.161, the context of the B server is rompConsoleB, the port of the B server is 8804, the B server has a java bean named Role, the rule class path is com.romp, and the Person has a string type attribute named name.
A developer creates a logic directory in a resource directory of the A server, adds an xml-format resource file under the logic directory, and the initial content of the xml-format resource file:
< root service type attribute= "core" service switch attribute= "open" >
< Resource center service Address Label > </resource center service Address Label >
< Resource data tag > </resource data tag >
< Resource conservation Wipe List Label > </resource conservation Wipe List Label >
</Root >.
A developer creates a logic directory in a resource directory of the server B, adds an xml-format resource file under the logic directory, and the initial content of the xml-format resource file:
< root service type attribute= "find" service switch attribute= "open" >
< Resource center service Address Label > http://172.3.0.1:8803/rompConsoleA @_ @1 </resource center service Address Label >
< Resource data tag > </resource data tag >
< Resource conservation Wipe List Label > </resource conservation Wipe List Label >
</Root >.
In an optional embodiment of the present invention, the resource center server of the present invention adds a resource center server storage file in a resource center server resource directory configuration, and sets a resource center server resource discovery thread, a resource center server first daemon thread, and a resource center server second daemon thread.
The first daemon thread of the resource center server is configured with a first daemon task, a second daemon task and a third daemon task;
the first daemon is specifically to check the service switch attribute of the resource root tag in the resource catalog of the resource center server side and judge whether the service switch attribute is on or not; if yes, checking whether the resource discovery thread of the resource center server dies, and if so, restarting; otherwise, checking whether the resource discovery thread of the resource center server runs or not, and if so, terminating the resource discovery thread of the resource center server;
the second daemon is specifically to check the state of a second daemon thread of the resource center; if the dead, the device is pulled up again;
The third daemon is specifically to acquire the ip address, the service port and the service context of the resource center server, send the ip address, the service port and the service context to the resource daemon, and store the ip address, the service port and the service context in a resource center Wipe list tag under a resource root tag under a resource center server storage file of a resource center server.
The resource discovery server adds a resource discovery server storage file in the resource discovery server resource catalog configuration, and sets a resource discovery server resource discovery thread, a resource discovery server first daemon thread and a resource discovery server second daemon thread.
Optionally, the first daemon thread of the resource discovery server is configured with a first daemon task, a second daemon task and a third daemon task;
The first daemon is specifically to check the service switch attribute of the resource root tag in the resource directory of the resource discovery server, and judge whether the service switch attribute is on or not; if yes, checking whether the resource discovery thread of the resource discovery server dies, and if so, restarting; otherwise, checking whether the resource discovery thread of the resource discovery server runs or not, and if so, terminating the resource discovery thread of the resource discovery server;
the second daemon is specifically to check the state of a second daemon thread of the resource discovery server; if the dead, the device is pulled up again;
The third daemon is specifically to obtain the ip address, the service port and the service context of the resource discovery server, send the ip address, the service port and the service context to the resource daemon, and store the ip address, the service port and the service context in a resource-root label Wipe list label under a resource-discovery server storage file of a resource directory of the resource discovery server through the resource daemon.
Specifically, the resource discovery server and the resource center server can both start the resource discovery thread, and the resource discovery thread is mainly used for discovering that the java bean resource of the current server (the resource discovery server/the resource center server) is transmitted to the resource center server for persistent storage (stored in the < resource data label > under the resource file root label in the xml format of the resource directory of the resource center server).
The guard thread has two total, three tasks, the first task checks the service switch attribute value of the current service end (resource discovery service end/resource center service end) resource directory root tag to judge whether the open check resource discovery thread dies, if the open check resource discovery thread dies, the close check resource discovery thread is restarted, if the open check resource discovery thread is stopped in operation, the second task checks whether the other guard thread dies, if the open check resource discovery thread dies, the restart is performed, the third task is to acquire the ip address service port service context of the current service, send the service context to the resource guard, and the resource guard can store the contents in the < resource guard Wipe list tag > tag under the root tag under the xml format resource file of the current service: < resource guard Wipe list tag > ip address service Port service context of service, ip address service 1 Port service 1 context of service 1 > resource guard Wipe list tag >.
The resource guard is mainly used for intercepting a request that a white list is not configured on a resource preservation interface of a resource center server.
After the configuration of the developer is completed, the A server and the B server are started.
The method comprises the steps that A server side starting is completed, two built-in daemons are pulled up, the two daemons read service switch attributes of root tags in an A server side xml format resource file, service switch attribute values are judged to be equal to open, a resource discovery thread is pulled up, and a resource discovery thread execution task writes all java bean resources of the A server side into < resource data tags > tags under the root tags in the A server side xml format resource file.
The content of the xml format resource file of the A server is as follows:
< root service type attribute= "core" service switch attribute= "open" >
< Resource center service Address Label > </resource center service Address Label >
< Resource data tag >
{
172.3.0.1_8803_rompConsoleA:[{com.romp_Person:{name:string}}]
}
Resource data tag)
< Resource conservation Wipe List Label > </resource conservation Wipe List Label >
Root-
The starting of the server B is completed by pulling up two built-in daemons, the two daemons read service switch attributes of a root tag in an xml format resource file of the server B, the service switch attribute value is judged to be equal to open, a resource discovery thread is pulled up, and a resource discovery thread execution task transmits all java bean resources of the server B to the < resource data tag > tag under the root tag in the xml format resource file through the http://172.3.0.1:8803/rompConsoleA @1 address in the < resource center service address tag > tag under the root tag in the xml format resource file of the server B.
The content of the xml format resource file of the A server is as follows:
< root service type attribute= "core" service switch attribute= "open" >
< Resource center service Address Label > </resource center service Address Label >
< Resource data tag >
{
172.3.0.1_8803_rompConsoleA:[{com.romp_Person:{name:string}}],
172.3.0.161_8804_rompConsoleB:[{com.romp_Role:{name:string}}]
}
Resource data tag)
< Resource conservation Wipe List Label > </resource conservation Wipe List Label >
Root-
From there the whole operation is completed.
In an alternative embodiment of the present invention, the present invention sets the resource discovery thread to execute a task every 5 minutes, where the execution process is:
A1, acquiring a resource center server storage file under a resource directory of a resource center server, wherein the resource storage file specifically refers to an xml format resource file of the server, and the xml format resource file data structure is as follows: the XML data comprises a data structure in JSON format; reading a service switch attribute of a resource root tag in a resource center server side storage file, wherein a value of the service switch attribute is equal to open a resource discovery thread, and a value of the service switch attribute is equal to close the resource discovery thread; judging whether the service switch attribute is on or not; if yes, executing the step A2; otherwise, ending the flow;
A2, acquiring a resource center service end storage file under a resource directory of a resource center service end, reading a service type attribute of a resource root tag in the resource center service end storage file, wherein the value of the service type attribute is equal to core to represent the resource center service end, and the value of the service type attribute is equal to find to represent the service end of resource discovery; judging whether the service type attribute is core; if yes, the server is the resource center server, and the step A3 is executed; otherwise, executing the step A5 for the service end of resource discovery;
A3, obtaining all java classes with @ table annotations of the resource center server through java reflection, converting the java classes with @ table annotations into Map objects (for example, { class path_class names { attribute names: attribute types }) and storing an array of List types (for example, [ { class path_class names { attribute names: attribute types }, { class path_class names { attribute names: attribute types }) ]) as new waiting for storing resource data, and then obtaining the IP address, the server port and the server context of the current service through the resource center server to form a new unique grouping identifier;
A4, reading a resource data json character string under a persistent storage resource data label of a resource root label sign in a resource center server side storage file, converting the resource data json character string into a Map type data format, finding out an old unique group label and resource data which are equal to a new unique group label in A3 from the Map type data format, covering the old unique group label and the resource data by using the new unique group label in A3 and the new resource data to be saved, if the unique group label which is equal to the new unique group label in A3 is not found out from the Map type data format, directly storing the new unique group label in A3 and the new resource data to be saved into the Map type data format, converting the Map type data format into the json character string, and storing the json character string into the persistent storage resource data label of the resource root label sign in the resource center server side storage file in a covering mode, and ending the flow;
A5, defining a time acquisition Boolean variable, acquiring the system time of the current resource center server, and checking whether the current system time is within a set time period, for example, checking whether the current system time is within 00:00 to 00: between 10; if yes, assigning true to the time acquisition Boolean variable, and executing the step A6; otherwise, assigning false to the time acquisition Boolean variable, and executing the step A6;
A6, reading a character string in a persistent storage resource center service address resource center service of a resource root mark sign in a resource center service end storage file, separating the character string in a Fu Cafen persistent storage resource center service address label by using a comma to obtain a source resource center service address array, defining a new resource center service address array, and judging that the time acquisition Boolean variable in A5 is true or false; if true, replacing a separator @ _ @0 in a character string in a persistent storage resource center service address label of a resource root mark sign in a resource center service end storage file with @ _ @1, and then storing all the resource center service addresses in a source resource center service address array into a new resource center service address array to execute the step A7; if false, circularly judging that the value of each resource center service address @ _ @ divider in the source resource center service address array is 1 or 0, if 1, storing all the resource center service addresses in the source resource center service address array into a new resource center service address array, and if 0, outputting an abnormal resource center service address into a log file;
A7, judging whether the length of the service address array of the new resource center in the A6 is smaller than 1; if yes, ending the flow; otherwise, executing the step A8;
A8, obtaining all java classes with @ table annotation of the resource center server through java reflection, converting the java classes with @ table annotation into Map objects, storing an array of List types as new waiting resource data, and then obtaining the IP address, the server port and the server context of the current service through the resource center server to form a new unique grouping identifier; the new unique grouping identification and the new waiting resource data are formed into new Map format data (for example, { service end IP_service end port_service end context: [ { class path_class name: { attribute type }, { class path_class name: { attribute name: attribute type } }) };
A9, defining a Map type storage rollback information object, circularly acquiring a new resource center service address array in A6, circularly acquiring a first resource center service address in the new resource center service address array in A6 as a rollback identifier for the first time, carrying a rollback identifier to request to acquire a resource interface, and forming a new data storage rollback information object by a json array returned by the acquired resource interface and the rollback identifier;
A10, requesting the new Map format data transmitted into A8 by the resource center service address as a storage parameter, intercepting the request of the resource storage interface by using the resource guard of the resource center service end, acquiring the Ip address of the request end, the service end port and the service end context, and splicing the Ip address, the service end port and the service end context into a current unique packet identifier; then, acquiring a white list configuration in a resource guard Wipe list configuration label under a resource root label in a resource center server-side storage file, and judging whether the white list configuration contains a current unique grouping identifier or not; if yes, executing the step A11; otherwise, intercepting the request, returning a failure ending mark, and executing the step A13;
A11, calling a resource preservation interface to acquire an input preservation parameter, acquiring json character string content in a persistent storage resource data tag of a resource root mark sign in a resource storage file under a resource target of a resource center server, converting the input and output of the preservation parameter into the Map type object, converting the Map type object into json character string, and storing the json character string in a service resource data tag under the resource root mark in the resource center server storage file in a covering mode;
A12, judging whether the executing process of the step A11 is abnormal or not; if yes, the resource saving interface returns a failure ending mark, and the step A13 is executed; otherwise, the resource saving interface returns a successful continuing identification, and the step A14 is executed;
A13, receiving a return result of the resource center service, and judging whether the return result value is equal to a failure ending mark; if yes, interrupting the circulation of the new resource center service address array in A6, circulating the storage rollback information object in A9, transmitting json array parameters to a json array parameter by using a json array stored in the storage rollback information object and a rollback identification request resource storage interface each time, executing resource center service rollback operation, then acquiring the service times of the abnormal occurrence of the resource center service address in the current service memory by using the rollback identification, judging whether the abnormal service times are greater than the set number, if yes, adding an abnormal identification (http:// server 2IP address: the port of the server 2/the context @0 of the server 2) to the abnormal resource center address in the resource center service label under the resource root label of the resource center server; otherwise, adding one abnormal service frequency to the current service memory for recording;
a14, judging whether the new resource center service address array in the A6 is circularly completed or not; if yes, ending the flow; otherwise, the next resource center service address in the new resource center service address array in the A6 is acquired in the next cycle, and the step A9 is returned.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The principles and embodiments of the present invention have been described in detail with reference to specific examples, which are provided to facilitate understanding of the method and core ideas of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.
Those of ordinary skill in the art will recognize that the embodiments described herein are for the purpose of aiding the reader in understanding the principles of the present invention and should be understood that the scope of the invention is not limited to such specific statements and embodiments. Those of ordinary skill in the art can make various other specific modifications and combinations from the teachings of the present disclosure without departing from the spirit thereof, and such modifications and combinations remain within the scope of the present disclosure.
Claims (7)
1. The method for automatically discovering the java bean resources by the micro-service system is characterized by comprising the following steps:
constructing a resource center server and a resource discovery server, and carrying out resource allocation;
Starting a resource center service end, reading service switch attributes of resource root labels in a resource catalog of the resource center service end by pulling up two built-in daemon threads, judging the service switch attributes to pull up a resource discovery thread, and writing all java bean resources of the resource center service end into service resource data labels under the resource root labels in the resource catalog of the resource center service end for persistence;
Starting a resource discovery service end, reading service switch attributes of resource root labels in a resource catalog of the resource discovery service end by pulling up two built-in daemon threads, judging the service switch attributes to pull up the resource discovery thread, and writing all java bean resources which are transmitted into the resource discovery service end through a resource center service address in a resource center service label of a resource root label sign in the resource catalog of the resource discovery service end into service resource data labels under the resource root label in the resource catalog of the resource center service end for persistence.
2. The method for automatically discovering java bean resources by a micro service system according to claim 1, wherein the resource center server adds a resource center server storage file in a resource center server resource directory configuration, and sets a resource center server resource discovery thread, a resource center server first daemon thread and a resource center server second daemon thread.
3. The method for automatically discovering java bean resources by a micro-service system according to claim 2, wherein the first daemon thread of the resource center server is configured with a first daemon task, a second daemon task and a third daemon task;
the first daemon is specifically to check the service switch attribute of the resource root tag in the resource catalog of the resource center server side and judge whether the service switch attribute is on or not; if yes, checking whether the resource discovery thread of the resource center server dies, and if so, restarting; otherwise, checking whether the resource discovery thread of the resource center server runs or not, and if so, terminating the resource discovery thread of the resource center server;
the second daemon is specifically to check the state of a second daemon thread of the resource center; if the dead, the device is pulled up again;
The third daemon is specifically to acquire the ip address, the service port and the service context of the resource center server, send the ip address, the service port and the service context to the resource daemon, and store the ip address, the service port and the service context in a resource center Wipe list tag under a resource root tag under a resource center server storage file of a resource center server.
4. The method for automatically discovering java bean resources by a microservice system according to claim 3, wherein the resource guard is used for intercepting a request that a white list is not configured on a resource preservation interface of a resource center server.
5. The method for automatically discovering java bean resources by a micro service system according to claim 1, wherein the resource discovery server adds a resource discovery server storage file in a resource discovery server resource directory configuration, and sets a resource discovery server resource discovery thread, a resource discovery server first daemon thread and a resource discovery server second daemon thread.
6. The method for automatically discovering java bean resources by a micro-service system according to claim 5, wherein the first daemon thread of the resource discovery server is configured with a first daemon task, a second daemon task and a third daemon task;
The first daemon is specifically to check the service switch attribute of the resource root tag in the resource directory of the resource discovery server, and judge whether the service switch attribute is on or not; if yes, checking whether the resource discovery thread of the resource discovery server dies, and if so, restarting; otherwise, checking whether the resource discovery thread of the resource discovery server runs or not, and if so, terminating the resource discovery thread of the resource discovery server;
the second daemon is specifically to check the state of a second daemon thread of the resource discovery server; if the dead, the device is pulled up again;
The third daemon is specifically to obtain the ip address, the service port and the service context of the resource discovery server, send the ip address, the service port and the service context to the resource daemon, and store the ip address, the service port and the service context in a resource-root label Wipe list label under a resource-discovery server storage file of a resource directory of the resource discovery server through the resource daemon.
7. The method for automatically discovering the java bean resources by the micro service system according to claim 1, wherein the resource discovery thread writes all the java bean resources of the resource center server into the service resource data tags under the resource root tags in the resource center server resource directory for persistence, and specifically comprises the following sub-steps:
A1, acquiring a resource center server side storage file under a resource directory of a resource center server side, reading a service switch attribute of a resource root tag in the resource center server side storage file, and judging whether the service switch attribute is on or not; if yes, executing the step A2; otherwise, ending the flow;
A2, acquiring a resource center server side storage file under a resource directory of a resource center server side, reading a service type attribute of a resource root tag in the resource center server side storage file, and judging whether the service type attribute is the resource center server side or not; if yes, executing the step A3; otherwise, executing the step A5 for the server for resource discovery;
a3, obtaining all java classes with @ table annotation of the resource center server through java reflection, converting the java classes with @ table annotation into Map objects, storing an array of List types as new waiting resource data, and then obtaining the IP address, the server port and the server context of the current service through the resource center server to form a new unique grouping identifier;
A4, reading a resource data json character string under a persistent storage resource data label of a resource root label sign in a resource center server side storage file, converting the resource data json character string into a Map type data format, finding out an old unique group label and resource data which are equal to a new unique group label in A3 from the Map type data format, covering the old unique group label and the resource data by using the new unique group label in A3 and the new resource data to be saved, if the unique group label which is equal to the new unique group label in A3 is not found out from the Map type data format, directly storing the new unique group label in A3 and the new resource data to be saved into the Map type data format, converting the Map type data format into the json character string, and storing the json character string into the persistent storage resource data label of the resource root label sign in the resource center server side storage file in a covering mode, and ending the flow;
a5, defining a time acquisition Boolean variable, acquiring the system time of the current resource center server, and checking whether the current system time is within a set time period; if yes, assigning true to the time acquisition Boolean variable, and executing the step A6; otherwise, assigning false to the time acquisition Boolean variable, and executing the step A6;
A6, reading character strings in a permanent storage resource center service address label of a resource root mark sign in a resource center service end storage file, separating Fu Cafen character strings in the permanent storage resource center service address label by commas to obtain a source resource center service address array, defining a new resource center service address array, and judging that the time acquisition Boolean variable in A5 is true or false; if true, replacing a separator @ _ @0 in a character string in a persistent storage resource center service address label of a resource root mark sign in a resource center service end storage file with @ _ @1, and then storing all the resource center service addresses in a source resource center service address array into a new resource center service address array to execute the step A7; if false, circularly judging whether the value of each resource center service address @ _ @ divider in the source resource center service address array character string variables is 1, if yes, storing all the resource center service addresses in the source resource center service address array into a new resource center service address array, otherwise, outputting abnormal resource center service addresses into a log file;
A7, judging whether the length of the service address array of the new resource center in the A6 is smaller than 1; if yes, ending the flow; otherwise, executing the step A8;
A8, obtaining all java classes with @ table annotation of the resource center server through java reflection, converting the java classes with @ table annotation into Map objects, storing an array of List types as new waiting resource data, and then obtaining the IP address, the server port and the server context of the current service through the resource center server to form a new unique grouping identifier; the new unique grouping identification and the new resource data to be saved form new Map format data;
A9, defining a Map type storage rollback information object, circularly acquiring a new resource center service address array in A6, circularly acquiring a first resource center service address in the new resource center service address array in A6 as a rollback identifier for the first time, carrying a rollback identifier to request to acquire a resource interface, and forming a new data storage rollback information object by a json array returned by the acquired resource interface and the rollback identifier;
A10, requesting the new Map format data transmitted into A8 by the resource center service address as a storage parameter, intercepting the request of the resource storage interface by using the resource guard of the resource center service end, acquiring the Ip address of the request end, the service end port and the service end context, and splicing the Ip address, the service end port and the service end context into a current unique packet identifier; then, acquiring a white list configuration in a resource guard Wipe list configuration label under a resource root label in a resource center server-side storage file, and judging whether the white list configuration contains a current unique grouping identifier or not; if yes, executing the step A11; otherwise, intercepting the request, returning a failure ending mark, and executing the step A13;
A11, calling a resource preservation interface to acquire an input preservation parameter, acquiring json character string content in a persistent storage resource data tag of a resource root mark sign in a resource storage file under a resource target of a resource center server, converting the input and output of the preservation parameter into the Map type object, converting the Map type object into json character string, and storing the json character string in a service resource data tag under the resource root mark in the resource center server storage file in a covering mode;
A12, judging whether the executing process of the step A11 is abnormal or not; if yes, the resource saving interface returns a failure ending mark, and the step A13 is executed; otherwise, the resource saving interface returns a successful continuing identification, and the step A14 is executed;
A13, receiving a return result of the resource center service, and judging whether the return result value is equal to a failure ending mark; if yes, interrupting the circulation of the new resource center service address array in the A6, circulating the storage rollback information object in the A9, transmitting json array parameters to the json array parameters by using the json array stored in the storage rollback information object and the rollback identification request resource storage interface each time, executing the resource center service rollback operation, then acquiring the service times of the abnormal occurrence of the resource center service address in the current service memory by using the rollback identification, judging whether the abnormal service times are greater than the set number, and if yes, adding the abnormal identification to the abnormal resource center address in the resource center service label under the resource root label of the resource center service end resource catalog; otherwise, adding one abnormal service frequency to the current service memory for recording;
a14, judging whether the new resource center service address array in the A6 is circularly completed or not; if yes, ending the flow; otherwise, the next resource center service address in the new resource center service address array variable in the A6 is acquired in the next cycle, and the step A9 is returned.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410331486.0A CN117931325B (en) | 2024-03-22 | 2024-03-22 | Method for automatically discovering java bean resources by micro-service system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410331486.0A CN117931325B (en) | 2024-03-22 | 2024-03-22 | Method for automatically discovering java bean resources by micro-service system |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN117931325A true CN117931325A (en) | 2024-04-26 |
| CN117931325B CN117931325B (en) | 2024-06-11 |
Family
ID=90766919
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410331486.0A Active CN117931325B (en) | 2024-03-22 | 2024-03-22 | Method for automatically discovering java bean resources by micro-service system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN117931325B (en) |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7912930B1 (en) * | 2002-02-21 | 2011-03-22 | Oracle International Corporation | System and method for resource provisioning |
| US10810110B1 (en) * | 2018-01-25 | 2020-10-20 | Intuit Inc. | Methods, systems, and articles of manufacture for testing web services using a behavior-driven development domain specific language framework |
| CN115658109A (en) * | 2022-10-28 | 2023-01-31 | 远光软件股份有限公司 | Microservice hot deployment method, system, electronic device and storage medium |
| CN116996575A (en) * | 2022-10-18 | 2023-11-03 | 广州腾讯科技有限公司 | Resource access method, device, equipment and storage medium |
| CN117478725A (en) * | 2023-10-30 | 2024-01-30 | 之江实验室 | A management method, device, media and electronic equipment for microservice API |
-
2024
- 2024-03-22 CN CN202410331486.0A patent/CN117931325B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7912930B1 (en) * | 2002-02-21 | 2011-03-22 | Oracle International Corporation | System and method for resource provisioning |
| US10810110B1 (en) * | 2018-01-25 | 2020-10-20 | Intuit Inc. | Methods, systems, and articles of manufacture for testing web services using a behavior-driven development domain specific language framework |
| CN116996575A (en) * | 2022-10-18 | 2023-11-03 | 广州腾讯科技有限公司 | Resource access method, device, equipment and storage medium |
| CN115658109A (en) * | 2022-10-28 | 2023-01-31 | 远光软件股份有限公司 | Microservice hot deployment method, system, electronic device and storage medium |
| CN117478725A (en) * | 2023-10-30 | 2024-01-30 | 之江实验室 | A management method, device, media and electronic equipment for microservice API |
Non-Patent Citations (1)
| Title |
|---|
| 王渊;怀自国;罗怡桂;: "基于Ext+Spring+Hibernate的Web系统开发架构的研究与应用", 计算机与现代化, no. 12, 15 December 2009 (2009-12-15) * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN117931325B (en) | 2024-06-11 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108108297B (en) | Method and device for automatic testing | |
| CN110908859B (en) | Application service processing method, device, terminal and storage medium | |
| CN108920365B (en) | A docker-based automated testing method for WebUI | |
| US8661418B2 (en) | Setting program, workflow creating method, and work flow creating apparatus | |
| CN105512044B (en) | Update method and system for the library of object of keyword driving test | |
| CN109302522A (en) | Test method, device and computer system and medium | |
| JPH07146844A (en) | Integrated automation development system and method for controlling and adjusting manufacturing device | |
| CN112559525B (en) | Data checking system, method, device and server | |
| CN111752838A (en) | Question checking method and device, server and storage medium | |
| WO2017044069A1 (en) | Automatic regression identification | |
| CN112579461A (en) | Assertion processing method, system and storage medium | |
| CN114911707A (en) | Container-based automatic testing method and device | |
| CN108399095B (en) | Method, system, device and storage medium for supporting dynamic management of timed tasks | |
| CN110928777A (en) | Test case processing method, device, equipment and storage medium | |
| US7277827B2 (en) | Device testing framework for creating device-centric scenario-based automated tests | |
| CN114691519B (en) | Interface automated testing method, device, equipment and storage medium | |
| CN116756016A (en) | Multi-browser testing methods, apparatus, equipment, media and program products | |
| WO2016190869A1 (en) | Determining potential test actions | |
| EP4293498A1 (en) | Application modification method, and system, cluster, medium and program product | |
| CN117931325B (en) | Method for automatically discovering java bean resources by micro-service system | |
| CN114185555A (en) | Server deployment method and device and electronic equipment | |
| CN112328602A (en) | Method, device and equipment for writing data into Kafka | |
| CN117170640A (en) | A component management method, device and readable storage medium for a low-code platform | |
| CN115328799B (en) | Database operation test method, device, storage medium and computer equipment | |
| CN119621175A (en) | Plug-in loading method, information processing method and device for plug-in loading |
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 |