CN112015523B - Event loss prevention method and device, electronic equipment and storage medium - Google Patents

Event loss prevention method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112015523B
CN112015523B CN202010766766.6A CN202010766766A CN112015523B CN 112015523 B CN112015523 B CN 112015523B CN 202010766766 A CN202010766766 A CN 202010766766A CN 112015523 B CN112015523 B CN 112015523B
Authority
CN
China
Prior art keywords
event
service
thread pool
target
target event
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010766766.6A
Other languages
Chinese (zh)
Other versions
CN112015523A (en
Inventor
宋超
艾国信
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202010766766.6A priority Critical patent/CN112015523B/en
Publication of CN112015523A publication Critical patent/CN112015523A/en
Application granted granted Critical
Publication of CN112015523B publication Critical patent/CN112015523B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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/466Transaction processing
    • 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/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the invention provides an event loss prevention method, an event loss prevention device, electronic equipment and a storage medium, wherein the method comprises the following steps: under the condition that the service is determined to receive a starting instruction for starting, loading a preset event processing method; the method for executing the preset event processing specifically comprises the following steps: monitoring whether the service receives a closing instruction or not; if yes, acquiring a target event from a thread pool corresponding to the event bus assembly, and storing the target event; searching the stored target event when the service is restarted; adding the stored target event to the thread pool so that the thread in the thread pool continues to process the target event.

Description

Event loss prevention method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a method and apparatus for preventing an event from being lost, an electronic device, and a storage medium.
Background
Guava is an open source-based Java library, and EventBus in Guava is a publish/subscribe event bus for Android. The EventBus component can be used for packaging and delivering some events, a publisher publishes the events through the EventBus component, and a subscriber subscribes to the events through the EventBus component. The event processing mechanism of the EventBus component is an elegant implementation of an observer mode in a design mode, supports the release and subscription of events and a synchronous and asynchronous mechanism of event processing, and realizes the processing of all events by maintaining a group of thread pools.
In the related art, with the gradual increase of the service QPS (query-per-second), events in the thread pool of the EventBus component may have backlog, that is, the number of threads in the thread pool is limited, and then the capability of processing the events is limited, some events are not processed in time, and the corresponding subscribers do not receive the events in time, so that the events in the thread pool of the EventBus component are backlog. If the service is restarted at this time, backlogged events in the EventBus component thread pool are lost, so that corresponding functions are not executed, and the consistency of data between the publisher and the subscriber is not guaranteed.
Disclosure of Invention
The embodiment of the invention aims to provide an event loss prevention method, an event loss prevention device, electronic equipment and a storage medium, so as to prevent event loss in the restarting process of service, ensure that corresponding functions can be executed and ensure the consistency of data between publishers and subscribers.
In a first aspect of the embodiment of the present invention, there is first provided an event loss prevention method, including:
under the condition that the service is determined to receive a starting instruction for starting, loading a preset event processing method;
the method for executing the preset event processing specifically comprises the following steps:
monitoring whether the service receives a closing instruction or not;
if yes, acquiring a target event from a thread pool corresponding to the event bus assembly, and storing the target event;
searching the stored target event when the service is restarted;
adding the stored target event to the thread pool so that the thread in the thread pool continues to process the target event.
In an optional embodiment, the monitoring whether the service receives a shutdown instruction includes:
determining whether a service shut down event is triggered;
if the service closing event is triggered, determining that the service receives a closing instruction;
if yes, acquiring a target event from a thread pool corresponding to the event bus component, including:
if yes, closing an external request receiving interface corresponding to the service, so that the service stops receiving the external request;
and after the external request receiving interface corresponding to the service is closed, acquiring a target event from the thread pool corresponding to the event bus component.
In an optional embodiment, the acquiring the target event from the thread pool corresponding to the event bus component includes:
determining an event bus component corresponding to a service according to a preset corresponding relation between the service and the event bus component;
acquiring a target event from a thread pool corresponding to the event bus component, and establishing an index between the service and the target event;
and searching the stored target event under the condition that the service is restarted, wherein the method comprises the following steps:
and searching the stored target event according to an index established between the service and the target event when the service is restarted.
In an optional embodiment, the acquiring the target event from the thread pool corresponding to the event bus component includes:
judging whether backlog events exist in a thread pool corresponding to the event bus component;
and if the backlogged event exists in the thread pool corresponding to the event bus component, acquiring the backlogged event from the thread pool corresponding to the event bus component as a target event.
In an alternative embodiment, the adding the stored target event to the thread pool to enable the thread in the thread pool to continue processing the target event includes:
sorting the stored target events based on the time of generation of the events;
and adding the stored target events into the thread pool according to the arrangement sequence of the target events so as to enable the threads in the thread pool to continue to process the target events.
In an alternative embodiment, the storing the target event includes:
extracting keywords carried in the target event;
establishing a storage queue corresponding to the keywords, wherein the keywords are in one-to-one correspondence with the storage queue;
storing the generation time of the target event based on the event into the storage queue corresponding to the keyword carried in the target event;
and under the condition that the service is determined to receive a starting instruction to start again, searching the stored target event, wherein the method comprises the following steps:
under the condition that the service receives a starting instruction to start again, searching the stored target event from the storage queue;
the adding the stored target event to the thread pool to enable threads in the thread pool to continue processing the target event, comprising:
and acquiring the stored target event from the storage queue in parallel, and adding the target event into the thread pool so as to enable the thread in the thread pool to continue to process the target event.
In a second aspect of the embodiment of the present invention, there is also provided an event loss prevention apparatus, the apparatus including:
the method loading module is used for loading a preset event processing method under the condition that the service is determined to receive a starting instruction for starting;
the method execution module is used for executing the preset event processing method, and specifically comprises the following steps: the service monitoring sub-module is used for monitoring whether the service receives a closing instruction or not; the event acquisition sub-module is used for acquiring a target event from a thread pool corresponding to the event bus component if the event is detected; the event storage sub-module is used for storing the target event; an event searching sub-module, configured to search the stored target event when the service is restarted; and the event adding sub-module is used for adding the stored target event into the thread pool so as to enable the thread in the thread pool to continue to process the target event.
In an alternative embodiment, the service listening submodule is specifically configured to:
determining whether a service shut down event is triggered;
if the service closing event is triggered, determining that the service receives a closing instruction;
the event acquisition submodule is specifically configured to:
if yes, closing an external request receiving interface corresponding to the service, so that the service stops receiving the external request;
and after the external request receiving interface corresponding to the service is closed, acquiring a target event from the thread pool corresponding to the event bus component.
In a third aspect of the embodiment of the present invention, there is also provided an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the event loss prevention method in any one of the first aspects when executing the program stored in the memory.
In a fourth aspect of embodiments of the present invention, there is also provided a storage medium having stored therein instructions that, when executed on a computer, cause the computer to perform the event loss prevention method of any of the first aspects described above.
In a fifth aspect of embodiments of the present invention, there is also provided a computer program product comprising instructions which, when run on a computer, cause the computer to perform the event loss prevention method of any of the first aspects described above.
The technical scheme provided by the embodiment of the invention loads a preset event processing method and executes the preset event processing method under the condition that the service is determined to receive a starting instruction for starting, and specifically comprises the following steps: whether the monitoring service receives a closing instruction or not, if so, acquiring a target event from a thread pool corresponding to the event bus component, and storing the target event; searching for the stored target event in case that the service is restarted is monitored; the stored target event is added to the thread pool so that the thread in the thread pool continues to process the target event. The event is stored under the condition that the service receives the closing instruction to close, and the event is added to the thread pool under the condition that the service receives the starting instruction to restart, so that the event can be prevented from being lost in the restarting process of the service, the corresponding function can be executed, and the consistency of data between a publisher and a subscriber is ensured.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the invention or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
Fig. 1 is a schematic flow chart of an implementation of an event loss prevention method according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart of an embodiment of a method for executing preset event processing according to the present invention;
fig. 3 is a schematic diagram of a correspondence between a service and an EventBus component in an embodiment of the present invention;
FIG. 4 is a schematic diagram of an implementation flow chart for performing persistent storage on backlogged events in a thread pool corresponding to an EventBus component according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of an implementation flow for re-adding backlogged events to a thread pool corresponding to an EventBus component according to an embodiment of the present invention;
FIG. 6 is a flowchart illustrating another embodiment of a method for performing preset event processing according to the present invention;
FIG. 7 is a flowchart illustrating another embodiment of a method for performing preset event processing according to the present invention;
fig. 8 is a schematic structural diagram of an event loss prevention device according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
As shown in fig. 1, a schematic implementation flow chart of an event loss prevention method according to an embodiment of the present invention may specifically include the following steps:
s101, loading a preset event processing method under the condition that the service is determined to receive a starting instruction for starting.
In the embodiment of the invention, the service can receive the starting instruction to start, and the preset event processing method is loaded (by the container or the processor) under the condition that the service is determined to receive the starting instruction to start.
S102, executing the preset event processing method.
In the embodiment of the invention, the event processing method is executed, the event can be stored under the condition that the service is determined to receive the closing instruction to close, and the event is added into the thread pool under the condition that the service is determined to receive the starting instruction to restart, so that the event is prevented from being lost in the restarting process of the service, the corresponding function can be executed, and the consistency of data between a publisher and a subscriber is ensured.
As shown in fig. 2, a schematic implementation flow chart of a method for executing preset event processing according to an embodiment of the present invention may specifically include the following steps:
s201, monitoring whether the service receives a closing instruction.
When the service receives the closing instruction to close, a service closing event is triggered, so that whether the service receives the closing instruction or not can be monitored by the following modes:
and determining whether a service closing event is triggered, if the service closing event is triggered, determining that the service receives a closing instruction, and if the service closing event is not triggered, determining that the service does not receive the closing instruction.
S202, if yes, acquiring a target event from a thread pool corresponding to the event bus component, and storing the target event.
In the embodiment of the invention, the EventBus (event bus) component can be used for packaging and delivering some events, a publisher publishes the events through the EventBus component, and a subscriber subscribes to the events through the EventBus component. Wherein the event is generated by the service when the external request is processed.
For a target event, namely an event backlogged in a thread pool corresponding to the EventBus component, if the number of threads in the thread pool is limited, the capability of processing the event is limited, and some events are not processed in time (namely not timely delivered to subscribers), so that the event backlogged in the thread pool corresponding to the EventBus component is caused.
Therefore, in order to prevent the backlog event in the thread pool corresponding to the EventBus component from being lost in the service restarting process, the external request receiving interface corresponding to the service can be closed under the condition that the service receives the closing instruction, and the service stops receiving the external request, so that the service is prevented from processing the external request to generate a new event.
For example, under the condition that the service A receives the closing instruction, the external request receiving interface corresponding to the service A is closed, and the service A stops receiving the external request, so that the service A can be prevented from processing the external request to generate a new event, and only backlogged events in a thread pool corresponding to the EventBus component can be stored subsequently, storage resources can be saved, and workload can be reduced.
After the external request receiving interface corresponding to the service is closed, a target event (i.e. backlog event) is acquired from the event bus component, i.e. the thread pool corresponding to the EventBus component, and the target event is stored, wherein the following manner may be specifically adopted to store the target event.
1. And carrying out persistent storage on the target event. And performing persistent storage on the target event, namely storing the target event into a permanent storage tool such as a database, a disk and the like.
After the external request receiving interface corresponding to the service is closed, determining an event bus component corresponding to the service according to a preset corresponding relation between the service and the event bus component, and acquiring a target event from a thread pool corresponding to the event bus component, wherein in the embodiment of the invention, the event bus components are in one-to-one correspondence with the service, and the event bus components in one-to-one correspondence exist in the local service, as shown in fig. 3.
In the process of carrying out persistence storage on the target event, an index in the form of Key-Value can be established based on the identification of the service and the identification of the event, namely, an index between the service and the target event is established, so that the target event can be conveniently searched subsequently. The identifier of the service may be an ID, a name, etc. of the service, and the identifier of the event may be an ID, a name, etc. of the event, which is not limited in the embodiment of the present invention.
For example, after the external request receiving interface corresponding to the service is closed, a backlog event is obtained from the thread pool corresponding to the EventBus component: event 1, event 2, event 3, … …, and store the backlogged event to a database, as shown in fig. 4, wherein an index in the form of Key-Value is established based on the identity of the service, and the identity of the event, as shown in table 1 below.
Identification of services Identification of backlogged events
A A 1、A 2、A 3、……
B B1、B2、B3、……
TABLE 1
2. In order to increase the storage speed and the consumption speed of the event, after an external request receiving interface corresponding to the service is closed, acquiring a target event (i.e. backlogged event) from a thread pool corresponding to an event bus component, namely an event bus component, extracting keywords carried in the target event, removing repeated keywords in the keywords, and establishing a storage queue corresponding to the keywords, wherein the keywords are in one-to-one correspondence with the storage queue, and storing the target event into the storage queue corresponding to the keywords carried in the target event based on the generation time of the event.
For example, for a Key word Key carried in a target event, the Key is a user UID, the user UID carried in the target event is extracted, and since the user UID carried in the target event may be repeated (meaning that a plurality of target events belong to the same user), the repeated user UID in the user UID may be removed, and 10 redisson priority storage queues are allocated based on the remaining user UID: queue 0, queue 1, queues 2, … …, queue 9, wherein the remaining user UIDs are in one-to-one correspondence with the storage queues.
Storing the generation time of the target event based on the event into a storage queue corresponding to the keyword carried in the target event: the user IDs carried in the target event 1, the target event 2 and the target event 3 are consistent and can be stored in a storage queue 0 corresponding to the user ID, wherein the earlier the generation time of the event is, the more the event is preferentially stored in the storage queue 0 for the target event 1, the target event 2 and the target event 3; the user IDs carried in the target event 4, the target event 5 and the target event 6 are consistent and can be stored in a storage queue 1 corresponding to the user ID, wherein the earlier the generation time of the event is, the priority is stored in the storage queue 1; and so on, the target events belonging to the same user can be stored in the same storage queue, and are stored in order based on the generation time of the events, as shown in the following table 2.
Store queue Target event
Queue 0 Target event 1, target event 2, target event 3
Queue 1 Target event 4, target event 5, target event 6
…… ……
Queue 9 Target event 20, target event 21
TABLE 2
And S203, searching the stored target event under the condition that the service is restarted.
S204, adding the stored target event into the thread pool so as to enable threads in the thread pool to continue to process the target event.
After the service is closed, the backlogged event in the thread pool corresponding to the EventBus component is stored, so that event loss can be prevented, and the stored backlogged event can be searched under the condition that the service is restarted, and then the backlogged event can be added into the thread pool corresponding to the EventBus component, so that the thread in the thread pool corresponding to the EventBus component can continue to process the backlogged event. And under the condition that the service is determined to receive a starting instruction to start again, searching the stored target event according to an index established between the service and the target event.
For example, under the condition that the service a receives the start instruction to restart, according to the index in the form of Key-Value established in the above table 1, the event backlogged in the thread pool of the EventBus component corresponding to the service a can be searched from the database, and the event backlogged in the thread pool corresponding to the EventBus component is re-added to the thread pool corresponding to the EventBus component, so that the thread in the thread pool corresponding to the EventBus component can continue to process the event backlogged, as shown in fig. 5. The multiple threads in the thread pool corresponding to the EventBus component can continue to process the backlog event in parallel, which is not limited by the embodiment of the present invention.
Or under the condition that the service is monitored to be started again, searching the stored target event from the storage queue, acquiring the stored target event from the storage queue in parallel, and adding the target event into the thread pool so as to enable the thread in the thread pool to continue to process the target event. The target events stored in the parallel acquisition storage queue are added into the thread pool, so that threads in the thread pool can consume the target events rapidly, and the consumption speed of the events is improved. And under the condition that the service receives a starting instruction to start again, searching the stored target event from the storage queue according to the index established between the service and the target event.
In the process of parallelly acquiring the target events stored in the storage queues, corresponding threads exist for each storage queue, the stored target events are sequentially added into the thread pool according to the first-in first-out principle for the target events stored in each storage queue, and the threads corresponding to the storage queues continue to process the target events according to the sequence. Thus, for the target events stored in each storage queue, the corresponding threads continue to process the target events according to the sequence, and from the dimension of the storage queue, the target events stored in each storage queue are consumed in sequence, so that the order of event consumption is ensured.
For example, when it is determined that the service a receives the start instruction to restart, according to the index in the form of Key-Value established in table 1, the event backlogged in the thread pool of the EventBus component corresponding to the service a is searched from the storage queue 0, the storage queues 1 and … … and the storage queue 9, the event backlogged in the thread pool of the EventBus component corresponding to the service a is obtained in parallel from the storage queue 0, the storage queues 1 and … … and the storage queue 9, and is added to the thread pool, so that the thread in the thread pool continues to process the target event.
In the process of continuing to process the target event through the threads in the thread pool, corresponding threads are respectively allocated to the storage queue 0, the storage queues 1, … … and the storage queue 9, as shown in the following table 3, so that corresponding threads exist for each storage queue.
Store queue Thread(s)
Queue 0 Thread 1
Queue 1 Thread 2
…… ……
Queue 9 Thread 10
TABLE 3 Table 3
The method comprises the steps of sequentially storing target events stored in a storage queue 0 based on generation moments of events, sequentially adding the stored target events into a thread pool according to a first-in first-out principle, processing the target events stored in the storage queue 0 by a thread 1 in the thread pool, sequentially storing the target events stored in the storage queue 1 based on generation moments of the events, sequentially adding the stored target events into the thread pool according to a first-out principle, and processing the target events stored in the storage queue 1 by a thread 2 in the thread pool, wherein for other storage queues, similar steps are not repeated herein. From the dimension of the storage queues, the target events stored in each storage queue are consumed sequentially, the order of event consumption is guaranteed, and the target events stored in a plurality of storage queues can be consumed in parallel, so that the consumption speed of the events is improved.
Through the above description of the technical solution provided by the embodiments of the present invention, when determining that a service receives a start instruction to start, loading a preset event processing method, and executing the preset event processing method, where the method specifically includes: whether the monitoring service receives a closing instruction or not, if so, acquiring a target event from a thread pool corresponding to the event bus component, and storing the target event; searching for the stored target event in case that the service is restarted is monitored; the stored target event is added to the thread pool so that the thread in the thread pool continues to process the target event.
The event is stored under the condition that the service receives the closing instruction to close, and the event is added to the thread pool under the condition that the service receives the starting instruction to restart, so that the event can be prevented from being lost in the restarting process of the service, the corresponding function can be executed, and the consistency of data between a publisher and a subscriber is ensured.
As shown in fig. 6, a schematic implementation flow chart of another method for executing preset event processing according to an embodiment of the present invention may specifically include the following steps:
s601, monitoring whether the service receives a closing instruction.
In the embodiment of the present invention, the step is similar to the step S201, and the embodiment of the present invention is not described here again.
And S602, if yes, closing an external request receiving interface corresponding to the service so as to stop the service from receiving the external request.
In the embodiment of the present invention, the step is similar to the step S202 described above, and the embodiment of the present invention is not described here again.
S603, after the external request receiving interface corresponding to the service is closed, judging whether backlog events exist in the thread pool corresponding to the event bus component.
S604, if a backlog event exists in a thread pool corresponding to the event bus component, acquiring the backlog event from the thread pool corresponding to the event bus component as a target event, and storing the target event;
after the external request receiving interface corresponding to the service is closed, the embodiment of the invention can judge whether the backlogged event exists in the thread pool corresponding to the EventBus component, if the backlogged event exists in the thread pool corresponding to the EventBus component, the backlogged event is obtained from the thread pool corresponding to the EventBus component as a target event, the target event is stored, and if the backlogged event does not exist in the thread pool corresponding to the EventBus component, no processing can be performed, and the program is directly ended.
And S605, searching the stored target event when the service is restarted.
S606, adding the stored target event into the thread pool so as to enable threads in the thread pool to continue to process the target event.
And under the condition that the service is restarted, searching the stored backlogged event, and adding the stored backlogged event into a thread pool corresponding to the EventBus component, so that the thread in the thread pool corresponding to the EventBus component continues to process the backlogged event, as shown in FIG. 7.
In order to determine that the target event is processed in time, the event feedback efficiency is improved, the stored target events are ordered based on the generation time of the event, the target events are added into a thread pool corresponding to the EventBus component according to the order of the targets, so that the thread in the thread pool corresponding to the EventBus component continues to process the target event, and the processing of the target event is preferentially ensured.
In the embodiment of the invention, the application based on the Spring Boot provides the service which uses the embedded container as the bottom support of the Web service, namely the Web service needs to depend on the container.
The Spring Boot supports a currently mainstream servlet container, including Tomcat, jetty, undertow and the like. For example, the application based on Spring Boot provides services using its embedded Tomcat container as the underlying support for Web services.
When the service-dependent container is closed, the loaded preset event processing method is removed from the service-dependent container, so that after the service-dependent container is started, under the condition that the service is determined to receive a starting instruction for starting, the service-dependent container needs to load the preset event processing method, the preset event processing method is executed, and the backlog event in a thread pool corresponding to the EventBus component is prevented from being lost in the restarting process of the service.
Corresponding to the above method embodiment, the embodiment of the present invention further provides an event loss prevention device, as shown in fig. 8, where the event loss prevention device may include: the method loading module 810 and the method executing module 820, wherein the method executing module 820 specifically includes: service listening sub-module 821, event acquisition sub-module 822, event storage sub-module 823, event lookup sub-module 824, event addition sub-module 825.
The method loading module 810 is configured to load a preset event processing method when the service is determined to receive a start instruction for starting;
the method execution module 820 is configured to execute the preset event processing method, and specifically includes: a service monitor sub-module 821, configured to monitor whether the service receives a shutdown instruction; an event obtaining sub-module 822, configured to obtain, if yes, a target event from a thread pool corresponding to the event bus component; an event storage sub-module 823, configured to store the target event; an event lookup sub-module 824 for looking up the stored target event if the service is monitored to be restarted; an event adding sub-module 825 is configured to add the stored target event to the thread pool, so that the thread in the thread pool continues to process the target event.
The embodiment of the invention also provides an electronic device, as shown in fig. 9, which comprises a processor 91, a communication interface 92, a memory 93 and a communication bus 94, wherein the processor 91, the communication interface 92 and the memory 93 complete communication with each other through the communication bus 94,
a memory 93 for storing a computer program;
the processor 91 is configured to execute the program stored in the memory 93, and implement the following steps:
under the condition that the service is determined to receive a starting instruction for starting, loading a preset event processing method; the method for executing the preset event processing specifically comprises the following steps: monitoring whether the service receives a closing instruction or not; if yes, acquiring a target event from a thread pool corresponding to the event bus assembly, and storing the target event; searching the stored target event when the service is restarted; adding the stored target event to the thread pool so that the thread in the thread pool continues to process the target event.
The communication bus mentioned by the above electronic device may be a peripheral component interconnect standard (Peripheral Component Interconnect, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, or the like. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The memory may include random access memory (Random Access Memory, RAM) or non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processing, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a storage medium is provided, where instructions are stored that, when executed on a computer, cause the computer to perform the event loss prevention method according to any of the above embodiments.
In yet another embodiment of the present invention, a computer program product containing instructions that, when run on a computer, cause the computer to perform the event loss prevention method of any of the above embodiments is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in a storage medium or transmitted from one storage medium to another, for example, from one website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The storage media may be any available media that can be accessed by a computer or a data storage device such as a server, data center, or the like that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (7)

1. A method of event loss prevention, the method comprising:
under the condition that the service is determined to receive a starting instruction for starting, loading a preset event processing method;
the method for executing the preset event processing specifically comprises the following steps:
monitoring whether the service receives a closing instruction comprises the following steps: determining whether a service shut down event is triggered; if the service closing event is triggered, determining that the service receives a closing instruction;
if yes, acquiring a target event from a thread pool corresponding to the event bus assembly, and storing the target event; if yes, acquiring a target event from a thread pool corresponding to the event bus component, including: if yes, closing an external request receiving interface corresponding to the service, so that the service stops receiving the external request; after the external request receiving interface corresponding to the service is closed, acquiring a target event from a thread pool corresponding to the event bus component;
the obtaining the target event from the thread pool corresponding to the event bus component comprises the following steps: judging whether backlog events exist in a thread pool corresponding to the event bus component; if the backlogged event exists in the thread pool corresponding to the event bus component, acquiring the backlogged event from the thread pool corresponding to the event bus component as a target event;
searching the stored target event when the service is restarted;
adding the stored target event to the thread pool so that the thread in the thread pool continues to process the target event.
2. The method of claim 1, wherein the obtaining the target event from the thread pool corresponding to the event bus component comprises:
determining an event bus component corresponding to a service according to a preset corresponding relation between the service and the event bus component;
acquiring a target event from a thread pool corresponding to the event bus component, and establishing an index between the service and the target event;
and searching the stored target event under the condition that the service is restarted, wherein the method comprises the following steps:
and searching the stored target event according to an index established between the service and the target event when the service is restarted.
3. The method of claim 1, wherein the adding the stored target event to the thread pool to cause the thread in the thread pool to continue processing the target event comprises:
sorting the stored target events based on the time of generation of the events;
and adding the stored target events into the thread pool according to the arrangement sequence of the target events so as to enable the threads in the thread pool to continue to process the target events.
4. The method of claim 1, wherein storing the target event comprises:
extracting keywords carried in the target event;
establishing a storage queue corresponding to the keywords, wherein the keywords are in one-to-one correspondence with the storage queue;
storing the generation time of the target event based on the event into the storage queue corresponding to the keyword carried in the target event;
and under the condition that the service is determined to receive a starting instruction to start again, searching the stored target event, wherein the method comprises the following steps:
under the condition that the service receives a starting instruction to start again, searching the stored target event from the storage queue;
the adding the stored target event to the thread pool to enable threads in the thread pool to continue processing the target event, comprising:
and acquiring the stored target event from the storage queue in parallel, and adding the target event into the thread pool so as to enable the thread in the thread pool to continue to process the target event.
5. An event loss prevention device, the device comprising:
the method loading module is used for loading a preset event processing method under the condition that the service is determined to receive a starting instruction for starting;
the method execution module is used for executing the preset event processing method, and specifically comprises the following steps: the service monitoring sub-module is used for monitoring whether the service receives a closing instruction or not; the event acquisition sub-module is used for acquiring a target event from a thread pool corresponding to the event bus component if the event is detected; the event storage sub-module is used for storing the target event; an event searching sub-module, configured to search the stored target event when the service is restarted; an event adding sub-module, configured to add the stored target event to the thread pool, so that a thread in the thread pool continues to process the target event;
the service monitoring submodule is specifically used for: determining whether a service shut down event is triggered; if the service closing event is triggered, determining that the service receives a closing instruction;
the event acquisition submodule is specifically configured to: if yes, closing an external request receiving interface corresponding to the service, so that the service stops receiving the external request; after the external request receiving interface corresponding to the service is closed, acquiring a target event from a thread pool corresponding to the event bus component;
the obtaining the target event from the thread pool corresponding to the event bus component comprises the following steps: judging whether backlog events exist in a thread pool corresponding to the event bus component; and if the backlogged event exists in the thread pool corresponding to the event bus component, acquiring the backlogged event from the thread pool corresponding to the event bus component as a target event.
6. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1-4 when executing a program stored on a memory.
7. A storage medium having stored thereon a computer program, which when executed by a processor, implements the method of any of claims 1-4.
CN202010766766.6A 2020-08-03 2020-08-03 Event loss prevention method and device, electronic equipment and storage medium Active CN112015523B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010766766.6A CN112015523B (en) 2020-08-03 2020-08-03 Event loss prevention method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010766766.6A CN112015523B (en) 2020-08-03 2020-08-03 Event loss prevention method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112015523A CN112015523A (en) 2020-12-01
CN112015523B true CN112015523B (en) 2023-09-01

Family

ID=73500109

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010766766.6A Active CN112015523B (en) 2020-08-03 2020-08-03 Event loss prevention method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112015523B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6829770B1 (en) * 1999-02-23 2004-12-07 Microsoft Corporation Object connectivity through loosely coupled publish and subscribe events
CN102664934A (en) * 2012-04-06 2012-09-12 北京华夏电通科技股份有限公司 Multi-thread control method and system for adaptive self-feedback of server
CN103209214A (en) * 2013-04-03 2013-07-17 蓝盾信息安全技术股份有限公司 Not only structured query language (NoSQL)-based method for realizing message-oriented middleware
CN103870337A (en) * 2014-02-28 2014-06-18 浪潮集团山东通用软件有限公司 ESB assembly realization method based on SEDA
WO2017049912A1 (en) * 2015-09-25 2017-03-30 中兴通讯股份有限公司 Service processing method adopted by jslee container and system utilizing same
CN107783849A (en) * 2017-09-27 2018-03-09 武汉斗鱼网络科技有限公司 Event-handling method and client
CN109582472A (en) * 2018-10-19 2019-04-05 华为技术有限公司 A kind of micro services processing method and equipment

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9727621B2 (en) * 2015-03-31 2017-08-08 Change Healthcare Llc Systems and methods for servicing database events
US20180091449A1 (en) * 2016-09-26 2018-03-29 Telefonaktiebolaget Lm Ericsson (Publ) Event-driven policy-based distributed container management system
US20200150972A1 (en) * 2018-11-09 2020-05-14 Microsoft Technology Licensing, Llc Performing actions opportunistically in connection with reboot events in a cloud computing system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6829770B1 (en) * 1999-02-23 2004-12-07 Microsoft Corporation Object connectivity through loosely coupled publish and subscribe events
CN102664934A (en) * 2012-04-06 2012-09-12 北京华夏电通科技股份有限公司 Multi-thread control method and system for adaptive self-feedback of server
CN103209214A (en) * 2013-04-03 2013-07-17 蓝盾信息安全技术股份有限公司 Not only structured query language (NoSQL)-based method for realizing message-oriented middleware
CN103870337A (en) * 2014-02-28 2014-06-18 浪潮集团山东通用软件有限公司 ESB assembly realization method based on SEDA
WO2017049912A1 (en) * 2015-09-25 2017-03-30 中兴通讯股份有限公司 Service processing method adopted by jslee container and system utilizing same
CN107783849A (en) * 2017-09-27 2018-03-09 武汉斗鱼网络科技有限公司 Event-handling method and client
CN109582472A (en) * 2018-10-19 2019-04-05 华为技术有限公司 A kind of micro services processing method and equipment

Also Published As

Publication number Publication date
CN112015523A (en) 2020-12-01

Similar Documents

Publication Publication Date Title
US10515326B2 (en) Database systems and related queue management methods
US20080313502A1 (en) Systems, methods and computer products for trace capability per work unit
CN105117289A (en) Task allocation method, device and system based on cloud testing platform
CN108255620B (en) Service logic processing method, device, service server and system
CN105279017A (en) Cloud test platform based task distribution method, apparatus and system
CN112579692B (en) Data synchronization method, device, system, equipment and storage medium
CN105183564A (en) Equipment scheduling method, device and system based on cloud testing platform
CN110711390A (en) Virtual article issuing method and device and server
CN112015523B (en) Event loss prevention method and device, electronic equipment and storage medium
CN111399999B (en) Computer resource processing method, device, readable storage medium and computer equipment
US20120102168A1 (en) Communication And Coordination Between Web Services In A Cloud-Based Computing Environment
CN116701020A (en) Message delay processing method, device, equipment, medium and program product
CN110912949B (en) Method and device for submitting sites
CN112965782A (en) Intelligent monitoring method and device for Docker container, storage medium and electronic equipment
CN114756362A (en) Resource quota management method and system, intelligent terminal and storage medium
CN110806967A (en) Unit testing method and device
CN110609707A (en) Online data processing system generation method, device and equipment
CN111221847B (en) Monitoring data storage method, device and computer readable storage medium
CN111176959A (en) Early warning method, system and storage medium for cross-domain application server
CN116090382B (en) Time sequence report generation method and device
CN117632416A (en) Method, device, medium and equipment for scheduling tasks of flow engine trigger
CN117573351A (en) Cluster resource recovery method, device, equipment, storage medium and program product
CN106886449B (en) System operation monitoring method and device
CN113421163A (en) Account checking method, account checking application cluster and related client
CN116405543A (en) Method, device, equipment and medium for dynamic scheduling of micro-services

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