Event driving device and method

By introducing an event mapping module into the event driver device, and automatically mapping pending events using the event mapping rule set, the inefficiency problem caused by the difference in the message formats of events and message queues in microservice technology is solved, and efficient event driving is achieved.

CN119396604APending Publication Date: 2025-02-07NEUSOFT CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411441658.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

In the field of microservice technology, there are differences in the message formats of events and message queues, which leads to developers need to manually map events, reducing event-driven efficiency.

Method used

An event driving device is provided, including an event sending module, an event subscription module and an event mapping module. Through the event mapping module, the pending events are automatically mapped into pending messages that can be sent to a message queue based on the event mapping rule set.

Benefits of technology

Automatic mapping of pending events is realized, reducing the difficulty of developers to get started, improving event-driven efficiency, and avoiding the confusion of event-driven logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396604A_ABST
    Figure CN119396604A_ABST
Patent Text Reader

Abstract

The invention discloses an event driving device and method. The event sending module is used for sending a to-be-processed event submitted by the client to the event mapping module; the event subscription module is used for sending to-be-processed messages subscribed from the target message queue to the event mapping module and sending to-be-processed events corresponding to the to-be-processed messages returned by the event mapping module to the event consumption end, so that the event consumption end executes event processing operation on the to-be-processed events; the event mapping module is used for carrying out mapping processing on the to-be-processed event based on the event mapping rule set to obtain a to-be-processed message corresponding to the to-be-processed event returned to the event sending module, and carrying out mapping processing on the to-be-processed message based on the event mapping rule set to obtain a to-be-processed message corresponding to the to-be-processed event; and obtaining a to-be-processed event corresponding to the to-be-processed message returned to the event subscription module. Therefore, automatic mapping of the to-be-processed event is realized, and the starting difficulty of developers is reduced, so that the event driving efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of microservice technology, and in particular to an event-driven device and method. Background Art

[0002] In the field of microservice technology, multi-party interaction is usually achieved based on an event-driven architecture, and multi-party interaction usually requires the propagation of events under the action of a message queue. Since there are differences in the format of events and messages that message queues need to receive, in related technologies, developers usually map events by themselves so that the mapped events can be sent to message queues to achieve multi-party interaction. In this way, since each event needs to be mapped by the developer, the event-driven efficiency will be low.

[0003] Therefore, how to improve the efficiency of event-driven operation is a key issue that technicians in this field are concerned about. Summary of the invention

[0004] Based on the above problems, the present application provides an event-driven device and method to improve event-driven efficiency.

[0005] The embodiments of the present application disclose the following technical solutions:

[0006] In a first aspect, the present application provides an event-driven device. The event-driven device includes an event sending module, an event subscription module, and an event mapping module;

[0007] The event sending module is used to send the pending event submitted by the client to the event mapping module, and send the pending message corresponding to the pending event returned by the event mapping module to the target message queue;

[0008] The event subscription module is used to send the pending message subscribed from the target message queue to the event mapping module, and send the pending event corresponding to the pending message returned by the event mapping module to the event consumer end, so that the event consumer end performs event processing operations on the pending event;

[0009] The event mapping module is used to map the pending events based on the event mapping rule set to obtain the pending messages corresponding to the pending events returned to the event sending module, and to map the pending messages based on the event mapping rule set to obtain the pending events corresponding to the pending messages returned to the event subscription module.

[0010] In an achievable implementation, the event sending module is specifically used to send the message queue type and the pending events submitted by the client to the event mapping module, wherein the message queue type is used to indicate the message queue type that will send the pending events to the message queue, and the message queue type includes RabbitMq message queue and Kafaka message queue.

[0011] In an achievable implementation, the event mapping module includes an event identification unit, a rule extraction unit and an event mapping unit;

[0012] The event identification unit is used to perform event identification on the event to be processed and obtain an event base class corresponding to the event to be processed;

[0013] The rule extraction unit is used to extract rules from the event mapping rule set according to the event base class, and obtain the target event mapping rule corresponding to the event base class in the event mapping rule set;

[0014] The event mapping unit is used to map the pending event based on the target event mapping rule to obtain the pending message corresponding to the pending event returned to the event sending module, and is used to map the pending message based on the target event mapping rule to obtain the pending event corresponding to the pending message returned to the event subscription module.

[0015] In an achievable implementation, the event mapping rule set includes a first mapping rule subset for the RabbitMq message queue and a second mapping rule subset for the Kafaka message queue;

[0016] The rule extraction unit is specifically configured to extract rules from the first mapping rule subset according to the event base class to obtain a target event mapping rule corresponding to the event base class in the first mapping rule subset if the type of the message queue that sends the event to be processed to the message queue is the RabbitMq message queue;

[0017] Or the rule extraction unit is specifically used to extract rules from the second mapping rule subset according to the event base class if the type of the message queue that will send the event to be processed to the message queue is the Kafaka message queue, and obtain the target event mapping rule corresponding to the event base class in the second mapping rule subset.

[0018] In an achievable implementation manner, the event sending module is further used to register the queue resource information according to the message to be processed to obtain the registered queue resource information.

[0019] In an achievable implementation, the event subscription module is specifically configured to subscribe to the pending message from the target message queue based on an event subscription annotation, and send the pending message to the event mapping module.

[0020] In an achievable implementation, the event sending module is further used to store the event to be processed in a first database corresponding to the event sending module;

[0021] The event subscription module is further used to store the to-be-processed event in a second database corresponding to the event subscription module.

[0022] In an achievable implementation, the event-driven device further includes an event cleaning module;

[0023] The event cleaning module is used to delete the pending events in the first database within a preset period of time, and to delete the pending events in the second database within the preset period of time.

[0024] In an achievable implementation, the event sending module is specifically used to send the pending events submitted by the client to the event mapping module in real time based on a sending synchronizer, and to send the pending message compensation corresponding to the pending events returned by the event mapping module to the message queue based on a sending compensator.

[0025] The second aspect of the present application provides an event-driven method. The event-driven method is applied to the event-driven device described in the first aspect, the event-driven device includes an event sending module, an event subscription module and an event mapping module, and the event-driven method includes:

[0026] Sending the pending event submitted by the client to the event mapping module through the event sending module, and sending the pending message corresponding to the pending event returned by the event mapping module to the target message queue;

[0027] The event subscription module sends the pending message subscribed from the target message queue to the event mapping module, and sends the pending event corresponding to the pending message returned by the event mapping module to the event consumer, so that the event consumer performs event processing operations on the pending event;

[0028] The event mapping module is used to map the pending event based on the event mapping rule set to obtain the pending message corresponding to the pending event returned to the event sending module, and is used to map the pending message based on the event mapping rule set to obtain the pending event corresponding to the pending message returned to the event subscription module.

[0029] Compared with the prior art, this application has the following beneficial effects:

[0030] The event-driven device proposed in the present application includes an event sending module, an event subscription module and an event mapping module. Specifically, the event sending module is used to send the pending events submitted by the client to the event mapping module, and send the pending messages corresponding to the pending events returned by the event mapping module to the target message queue; the event subscription module is used to send the pending messages subscribed from the target message queue to the event mapping module, and send the pending events corresponding to the pending messages returned by the event mapping module to the event consumer end, so that the event consumer end performs event processing operations on the pending events; the event mapping module is used to map the pending events based on the event mapping rule set to obtain the pending messages corresponding to the pending events returned to the event sending module, and to map the pending messages based on the event mapping rule set to obtain the pending events corresponding to the pending messages returned to the event subscription module.

[0031] It can be seen that in this application, before sending the pending event, the event sending module can send the pending event to the event mapping module in advance, so that the event mapping module can automatically map the pending event to a pending message that can be sent to the message queue under the action of the event mapping rule set, and the event subscription module can subscribe to the pending message from the message queue, and can obtain the pending event under the action of the event mapping module, thereby completing the event drive, and also enabling the subsequent event consumer end to process the pending event. In this way, the automatic mapping of pending events is achieved, which reduces the difficulty of developers to get started, thereby improving the efficiency of event drive. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0033] Figure 1 A schematic diagram of an event-driven device provided in an embodiment of the present application;

[0034] Figure 2 A schematic diagram of driving an event sending module in an event driven device provided in an embodiment of the present application;

[0035] Figure 3 A schematic diagram of an event mapping module in an event-driven device provided in an embodiment of the present application;

[0036] Figure 4 A schematic diagram of driving an event subscription module in an event-driven device provided in an embodiment of the present application;

[0037] Figure 5 A schematic diagram of driving an event cleaning module in an event-driven device provided in an embodiment of the present application;

[0038] Figure 6 A flowchart of an event-driven method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0039] As described above, in the field of microservice technology, multi-party interaction is usually achieved based on an event-driven architecture, and multi-party interaction usually requires the propagation of events under the action of a message queue. It can be understood that Party A can propagate event A to a message queue, and the message queue then propagates event A to Party B, thereby achieving interactive communication between Party A and Party B.

[0040] Since there are differences in the formats of events and messages that message queues need to receive, that is, message queues can only accept data in the format that message queues understand, events need to be mapped in a certain way before the mapped events can be sent to message queues. Therefore, in the related art, developers usually map events by themselves so that the mapped events can be sent to message queues to achieve multi-party interaction. In this way, since each event requires developers to map, event-driven efficiency will be low. Therefore, how to improve event-driven efficiency is a key issue that technicians in this field are concerned about.

[0041] In view of the above problems, a solution is provided in the embodiment of the present application, and an event-driven device and method are proposed, aiming to improve the efficiency of event-driven. The event-driven device proposed in the technical solution of the present application includes an event sending module, an event subscription module and an event mapping module. Among them, the event sending module is used to send the pending events submitted by the client to the event mapping module, and send the pending messages corresponding to the pending events returned by the event mapping module to the target message queue; the event subscription module is used to send the pending messages subscribed from the target message queue to the event mapping module, and send the pending events corresponding to the pending messages returned by the event mapping module to the event consumer end, so that the event consumer end performs event processing operations on the pending events; the event mapping module is used to map the pending events based on the event mapping rule set to obtain the pending messages corresponding to the pending events returned to the event sending module, and to map the pending messages based on the event mapping rule set to obtain the pending events corresponding to the pending messages returned to the event subscription module.

[0042] It can be seen that in the present application, before sending the pending event, the event sending module can first send the pending event to the event mapping module, so that the event mapping module can automatically map the pending event to a pending message that can be sent to the message queue under the action of the event mapping rule set, and the event subscription module can subscribe to the pending message from the message queue, and can obtain the pending event under the action of the event mapping module, so as to complete the event-driven, and also enable the subsequent processing of the pending event by the event consumer end. In this way, the automatic mapping of pending events is realized, which reduces the difficulty of developers to get started, thereby improving the efficiency of event-driven. And the present application can also encapsulate the underlying commands into modules to realize the interaction between events, which can avoid the logical confusion of event-driven to a certain extent.

[0043] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0044] Next, the technical terms that may appear in this application are explained.

[0045] Event Driven Architecture: Event Driven Architecture, EDA, is a responsive system design pattern based on events and messages.

[0046] See also Figure 1 , which is a schematic diagram of an event-driven device provided in an embodiment of the present application. Figure 1 As shown:

[0047] exist Figure 1 The event-driven device 100 in the embodiment includes an event sending module 101, an event subscription module 102 and an event mapping module 103. Specifically, the event sending module 101 can be used to send the pending events submitted by the client to the event mapping module, wherein the pending events can be understood as events submitted by the object at the client, for example, the pending events can be events generated when the object clicks the "Details" page in the shopping system, and the pending events can also be events generated when the object clicks the "Login" control after entering information in the login system.

[0048] The event sending module 101 can be used to send the pending message corresponding to the pending event returned by the event mapping module 103 to the target message queue, wherein the pending message corresponding to the pending event can be understood as a message that can be received by the target message queue, and the message format of the pending message can be understood by the target message queue.

[0049] The event subscription module 102 can be used to send the pending messages subscribed from the target message queue to the event mapping module. It can be understood that the event subscription module 102 can support subscription to the pending messages from the target message queue, so as to ensure that the messages will not be lost and to increase the message subscription speed. The event subscription module 102 can be used to send the pending events corresponding to the pending messages returned by the event mapping module to the event consumer end, so that the event consumer end performs event processing operations on the pending events, such as the event consumer end can display the "Details" page in the shopping system to the object, and the event consumer end can also determine whether to allow the object to log in to the system.

[0050] The event mapping module 103 is a shared module of the event sending module 101 and the event subscription module 102. The event mapping module 103 can provide mapping services between events and messages for the event sending module 101 and the event subscription module 102, thereby realizing automatic mapping of events and improving event-driven efficiency.

[0051] Specifically, the event mapping module 103 can be used to map the pending event based on the event mapping rule set to obtain the pending message corresponding to the pending event, and return the pending message corresponding to the pending event to the event sending module 101; and the event mapping module 103 can be used to map the pending message based on the event mapping rule set to obtain the pending event corresponding to the pending message, and return the pending event corresponding to the pending message to the event subscription module 102. The event mapping rule set is pre-generated, so that the event mapping module 103 can be directly called in the event-driven process to realize automatic mapping of events.

[0052] Next, the event sending module 101, the event subscription module 102 and the event mapping module 103 in this application are introduced one by one. The event sending module 101 is introduced as follows:

[0053] In an achievable implementation, the event sending module 101 is specifically used to send the pending events submitted by the client to the event mapping module 103 in real time based on the sending synchronizer, wherein the sending synchronizer includes the Spring TransactionSynchronizationManager transaction synchronizer. It can be understood that the event sending module 101 in the present application has a unified event bus sending class EventBus, and the event bus sending class can support client calls so that the pending events can be sent to the event mapping module 103 in real time, thereby realizing the real-time sending of the pending events under the sending synchronizer, which can improve the quality of the event-driven device to a certain extent.

[0054] And the event sending module 101 is specifically used to send the pending message corresponding to the pending event returned by the event mapping module to the message queue based on the sending compensator, wherein the sending compensator includes the Spring Scheduling framework and the distributed lock Shedlock, and in this application, the delayed sending interval and the sending cycle can be configured to realize the compensatory sending of the pending message. In this way, under the action of the Spring Scheduling framework in the sending compensator, it can be ensured that after the message queue fails temporarily, the pending message can be compensated and sent to the message queue again, so as to ensure that the event will not be lost, and under the action of the distributed lock Shedlock in the sending compensator, it can be ensured that the pending message is avoided from being sent repeatedly.

[0055] In another achievable implementation, since the event bus sending class EventBus can support the event outbox mode, the event sending module 101 can also be used to store the pending events submitted by the object on the client to the first database corresponding to the event sending module 101 under the action of the event outbox mode, wherein the first database includes a first event data table, and the first event data table includes an event name, an aggregate root name, an event type, an event content, an event status, an event creation time, and an event modification time, and the event name and the aggregate root name can uniquely identify the pending event. This can avoid event loss to a certain extent and improve the quality of the event-driven device.

[0056] In another achievable implementation, the event sending module 101 is specifically used to send the message queue type and the pending event submitted by the client to the event mapping module 103, wherein the event sending module 101 can know the message queue type in advance, and the message queue type includes the message queue type indicating that the pending event will be sent to the message queue, and the message queue type includes the RabbitMq message queue and the Kafaka message queue, that is, it can be known according to the message queue type to which message queue the pending event is sent. Since the queue types of the RabbitMq message queue and the Kafaka message queue are different, the message formats understood by the RabbitMq message queue and the Kafaka message queue are also different. At this time, the message queue type is sent to the event mapping module 103 together with the pending event, so that the event mapping module 103 can determine which message queue type the message queue receiving the pending event is, which is convenient for the subsequent event mapping module 103 to automatically map the event, so as to ensure the correctness of the event mapping.

[0057] It should be noted that, in the related technical solution, before the mapped event needs to be sent to the message queue, the developer needs to manually configure the queue resource information so that the mapped event can be accurately sent to the message queue. Therefore, in another achievable implementation of the present application, the event sending module 101 can also be used to register the queue resource information according to the pending message to obtain the registered queue resource information, wherein the registered queue resource information is located in the event sending module 101, and the registered queue resource information can ensure that the pending message is accurately sent to the target message queue to a certain extent, and realize the automatic registration of the queue resource information.

[0058] Specifically, since the message to be processed can be determined under the effect of the message queue type, the message to be processed carries the message queue type information to a certain extent. At this time, the event sending module 101 can register and process the queue resource information based on the message queue type information carried by the message to be processed to obtain the queue resource information after registration. For example: if the message queue type information carried by the message to be processed indicates that the message queue type carried by the message to be processed is a RabbitMq message queue, the queue resource information after registration can be exchange, routingkey, queue in RabbitMq; if the message queue type information carried by the message to be processed indicates that the message queue type carried by the message to be processed is a Kafaka message queue, the queue resource information after registration can be topic, group, etc. in Kafaka.

[0059] In addition, the event sending module 101 in the present application has an event sending interface DomainEventPublisher, which is used to connect to the message queue through the event sending interface to send the pending message to the message queue. This also realizes the decoupling between modules in the event-driven device to a certain extent, and improves the scalability and maintainability of the event-driven device.

[0060] like Figure 2 As shown, Figure 2 A schematic diagram of driving an event sending module in an event driven device provided in an embodiment of the present application, in Figure 2 In the embodiment, the event sending module 101 can send the pending events submitted by the client to the event mapping module 103, and the event sending module 101 can receive the pending messages corresponding to the pending events returned by the event mapping module 103, and can register the queue resource information to obtain the registered queue resource information, and can send the pending events to the first database corresponding to the event sending module 101, so that the first database can store the pending events.

[0061] The event mapping module 103 is introduced as follows. Figure 3 As shown, Figure 3 A schematic diagram of an event mapping module in an event-driven device provided in an embodiment of the present application, in Figure 3 The event mapping module 103 includes an event identification unit 31 , a rule extraction unit 32 and an event mapping unit 33 .

[0062] Specifically, the event identification unit 31 can be used to identify the pending events sent by the event sending module 101 to obtain the event base class corresponding to the pending events, and send the event base class to the rule extraction unit 32. The event base class includes DomainEvent (eventId, aggregateRootId, createTime), the eventId represents the event name, the aggregateRootId represents the aggregate root ID (used to identify the event subject), and the createTime represents the event creation time. It should be noted that this application does not limit the specific type of the event base class, and other specific types of event base classes can also be extended in actual application.

[0063] Furthermore, the rule extraction unit 32 can be used to extract rules from the event mapping rule set according to the event base class, and obtain the target event mapping rules corresponding to the event base class in the event mapping rule set, wherein the event mapping rule set includes event mapping rules corresponding to multiple different event base classes, so as to facilitate determining the event mapping rules related to the event based on the event base class of the event during the event mapping process, thereby realizing automatic mapping of events.

[0064] The event mapping rule set includes a first mapping rule subset for the RabbitMq message queue and a second mapping rule subset for the Kafaka message queue. Specifically, the rule extraction unit 32 in the present application can also be specifically used for extracting rules from the first mapping rule subset according to the event base class if the type of the message queue that sends pending events to the message queue is the RabbitMq message queue, and obtaining the target event mapping rule corresponding to the event base class in the first mapping rule subset. The rule extraction unit 32 in the present application can also be specifically used for extracting rules from the second mapping rule subset according to the event base class if the type of the message queue that sends pending events to the message queue is the Kafaka message queue, and obtaining the target event mapping rule corresponding to the event base class in the second mapping rule subset. In this way, the present application has corresponding mapping rules for message queues of different message queue types, so as to ensure the accuracy of event mapping.

[0065] Furthermore, the event mapping unit 33 is used to perform event mapping on the pending event based on the target event mapping rule, obtain the pending message corresponding to the pending event, and send the pending message corresponding to the pending event to the event sending module 101. The event mapping unit 33 is used to perform message mapping on the pending message based on the target event mapping rule, obtain the pending event corresponding to the pending message, and send the pending event corresponding to the pending message to the event subscription module 102.

[0066] In another achievable implementation, the event identification unit 31 in the present application can also be used to perform event identification on the pending event sent by the event sending module 101 to obtain the event annotation corresponding to the pending event, and send the event annotation to the rule extraction unit 32. The event annotation includes @DomainEventConfig(destination, partitionNum, replicaNum), the event annotation is located on the pending event, and if the event identification unit 31 identifies that the event annotation exists in the pending event, then in the subsequent process, the rule extraction unit 32 is required to extract rules from the event mapping rule set according to the event annotation to obtain the target event mapping rule corresponding to the event annotation in the event mapping rule set.

[0067] In some examples, if the event annotation of the pending event is @DomainEventConfig.destination(), and if the message queue type to send the pending event to the message queue is RabbitMq message queue, the pending event can be mapped to exchangeName(pending message) according to the target event mapping rule. If there is no event annotation in the pending event, and if the message queue type to send the pending event to the message queue is RabbitMq message queue, the pending event can be mapped to the pending message according to the target event mapping rule corresponding to the event base class.

[0068] In other examples, if the event annotation of the pending event is @DomainEventConfig.destination(), and if the message queue type that sends the pending event to the message queue is a Kafaka message queue, the pending event can be mapped to topic (pending message) according to the target event mapping rule; if the event annotation of the pending event is @DomainEventConfig.partitionNum(), and if the message queue type that sends the pending event to the message queue is a Kafaka message queue, the pending event can be mapped to partitionNum (pending message) according to the target event mapping rule; if the event annotation of the pending event is @DomainEventConfig.replicaNum(), and if the message queue type that sends the pending event to the message queue is a Kafaka message queue, the pending event can be mapped to replicaNum (pending message) according to the target event mapping rule.

[0069] And if there is no event annotation in the pending event, and if the message queue type that sends the pending event to the message queue is a Kafaka message queue, the pending event can be mapped to a pending message according to the target event mapping rule corresponding to the event base class. It should be noted that if it is identified that there are both event annotations and event base classes in the pending event, the target event mapping rule can be determined based on the event annotation. It should also be noted that the above examples mentioned in this application are only partial examples and are not specifically limited here.

[0070] The event subscription module 102 is introduced as follows:

[0071] In an achievable implementation, the event subscription module 102 is specifically used to subscribe to pending messages from the target message queue based on the event subscription annotation, and send the pending messages to the event mapping module 103, wherein the event subscription annotation includes @DomainEventListener. It is understandable that since the event-driven device in the present application is intended to interact with the underlying data, and only pending events are running on the front end, it is necessary to call the event subscription module 102 to obtain the event base class corresponding to the pending event based on the event subscription annotation, and then send the event base class to the event mapping module 103, so as to obtain the pending message corresponding to the pending event through the event mapping module 103.

[0072] After that, the pending message corresponding to the pending event is subscribed from the target message queue according to the pending message, so that the correct pending message is successfully subscribed from the target message queue. Finally, the pending message is mapped by the message mapping module 103 to obtain the pending event corresponding to the pending message. In this way, automatic mapping of events is realized, and event-driven efficiency can be improved.

[0073] The event subscription module 102 obtains the code of the event base class corresponding to the event to be processed based on the event subscription annotation as follows:

[0074]

[0075]

[0076] It should be noted that the event subscription module 102 in the present application can also be used to register and process the queue resource information according to the pending message returned by the event mapping module 103 to obtain the registered queue resource information, wherein the registered queue resource information is also located in the event subscription module 102, and the registered queue resource information can ensure to a certain extent that the event subscription module 102 accurately subscribes to the pending message from the target message queue, and realizes the automatic registration of the queue resource information. It should also be noted that the registration process of the queue resource information of the event subscription module 102 in the present application is similar to the registration process of the queue resource information of the event sending module 101, and will not be described in detail here. And there are multiple event subscribers in the event subscription module 102 in the present application, and the multiple event subscribers are connected to different message queues, which can improve the scalability and maintainability of the event-driven device.

[0077] It should also be noted that the event subscription module in the present application is also used to store the events to be processed in a second database corresponding to the event subscription module, wherein the second database includes a second event data table, a third event data table and a fourth event data table, the second event data table includes the event name, aggregate root name, event type, event content, event creation time and the number of event processing failures, the third event data table includes the event name and event processing events, and the fourth event data table includes the event name and the number of event processing failures.

[0078] Specifically, in the present application, the pending events can be stored in the second database corresponding to the event subscription module based on Spring AOP, and the present application can avoid repeatedly sending the pending events to consumers based on the event name, and the present application can determine the number of event processing failures corresponding to the pending events based on the event name, so as to avoid sending pending events with too many event failures to other consumers, thereby ensuring the normal operation of the event-driven device and improving the quality of the event-driven device.

[0079] like Figure 4 As shown, Figure 4 A schematic diagram of driving an event subscription module in an event-driven device provided in an embodiment of the present application, in Figure 4 In the example, the event subscription module 102 can subscribe to the pending message from the target message queue, and can receive the pending event corresponding to the pending message returned by the event mapping module 103, and can send the pending event to the consumer. In addition, the queue resource information can be registered to obtain the registered queue resource information, and the pending event can be sent to the second database corresponding to the event subscription module 102, so that the second database can store the pending event.

[0080] In addition, the event-driven device in the present application also includes an event cleaning module, which is used to delete pending events in the first database within a preset period, and to delete pending events in the second database within a preset period. The preset period is preset in advance, and the preset period can be 00:00 on January 1, 2024-00:00 on January 10, 2024, that is, the pending events in the first database and the second database within the preset period can be cleared. It should be noted that the present application does not limit the preset period, and it can also be determined in actual applications.

[0081] like Figure 5 As shown, Figure 5 A schematic diagram of driving an event cleaning module in an event-driven device provided in an embodiment of the present application, wherein Figure 5In the present application, the event cleaning module can clean up the events of the first database and the second database, so as to avoid the backlog of a large number of expired events stored in the database. And in the present application, the event cleaning module can further clean up the events of the first database and the second database regularly through the Spring Scheduling framework and the distributed lock Shedlock.

[0082] It can be seen that in this optional solution, the present application proposes that the event sending module can send the pending event to the event mapping module before sending the pending event, so that the event mapping module can automatically map the pending event to a pending message that can be sent to the message queue under the action of the event mapping rule set, and the event subscription module can subscribe to the pending message from the message queue, and can obtain the pending event under the action of the event mapping module, so as to complete the event drive, and also enable the subsequent event consumer end to process the pending event. In this way, the automatic mapping of the pending event is realized, and the decoupling of the event and the message queue is realized, which reduces the difficulty of developers to get started, thereby improving the event drive efficiency. And the present application can also encapsulate the underlying command into a module to realize the interaction between events, which can avoid the logical confusion of event drive to a certain extent, and improve the quality of the event drive device.

[0083] The event-driven method provided by the present application is described below through another embodiment.

[0084] See also Figure 6 , which is a flow chart of an event-driven method provided by an embodiment of the present application, such as Figure 6 As shown, the method is applied to the above-mentioned event-driven device, which includes an event sending module, an event subscription module and an event mapping module. The method may include:

[0085] S601: Sending the pending event submitted by the client to the event mapping module through the event sending module, and sending the pending message corresponding to the pending event returned by the event mapping module to the target message queue.

[0086] It should be noted that the event-driven process of the event sending module in step S601 is similar to the event-driven process of the event sending module in the above-mentioned event-driven device, and will not be described in detail here.

[0087] S602: The event subscription module sends the pending message subscribed from the target message queue to the event mapping module, and sends the pending event corresponding to the pending message returned by the event mapping module to the event consumer, so that the event consumer performs event processing operations on the pending event.

[0088] It should be noted that the event-driven process of the event subscription module in step S602 is similar to the event-driven process of the event subscription module in the above-mentioned event-driven device, and will not be described in detail here.

[0089] S603: Mapping the pending event based on the event mapping rule set through the event mapping module to obtain the pending message corresponding to the pending event returned to the event sending module, and mapping the pending message based on the event mapping rule set to obtain the pending event corresponding to the pending message returned to the event subscription module.

[0090] It should be noted that the event-driven process of the event mapping module in step S603 is similar to the event-driven process of the event mapping module in the above-mentioned event-driven device, and will not be described in detail here.

[0091] In summary, in this embodiment, event-driven processing can be realized under the action of the event sending module, the event subscription module and the event mapping module. The event sending module, the event subscription module and the event mapping module are independent of each other, and the event sending module, the event subscription module and the event mapping module have different capabilities, which can realize automatic mapping of events in the event-driven process, thereby improving the efficiency of event-driven processing.

[0092] In addition, the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0093] It should be noted that the "first" and "second" (if any) in the names such as "first" and "second" mentioned in the embodiments of the present application are only used as name identifiers and do not represent the first or second in order.

[0094] The above is a detailed introduction to an event-driven device and method provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application, and the description of the above embodiments is only used to help understand the method and its core idea of ​​the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

Claims

1. An event-driven device, characterized in that: The event-driven device includes an event sending module, an event subscription module and an event mapping module; The event sending module is used to send the pending event submitted by the client to the event mapping module, and send the pending message corresponding to the pending event returned by the event mapping module to the target message queue; The event subscription module is used to send the pending message subscribed from the target message queue to the event mapping module, and send the pending event corresponding to the pending message returned by the event mapping module to the event consumer end, so that the event consumer end performs event processing operations on the pending event; The event mapping module is used to map the pending events based on the event mapping rule set to obtain the pending messages corresponding to the pending events returned to the event sending module, and to map the pending messages based on the event mapping rule set to obtain the pending events corresponding to the pending messages returned to the event subscription module.

2. The device according to claim 1, characterized in that The event sending module is specifically used to send the message queue type and the pending events submitted by the client to the event mapping module, wherein the message queue type includes a message queue type indicating that the pending events will be sent to the message queue, and the message queue type includes RabbitMq message queue and Kafaka message queue.

3. The device according to claim 2, characterized in that The event mapping module includes an event identification unit, a rule extraction unit and an event mapping unit; The event identification unit is used to perform event identification on the event to be processed and obtain an event base class corresponding to the event to be processed; The rule extraction unit is used to extract rules from the event mapping rule set according to the event base class, and obtain the target event mapping rule corresponding to the event base class in the event mapping rule set; The event mapping unit is used to map the pending event based on the target event mapping rule to obtain the pending message corresponding to the pending event returned to the event sending module, and is used to map the pending message based on the target event mapping rule to obtain the pending event corresponding to the pending message returned to the event subscription module.

4. The device according to claim 3, characterized in that The event mapping rule set includes a first mapping rule subset for the RabbitMq message queue and a second mapping rule subset for the Kafaka message queue; The rule extraction unit is specifically configured to extract rules from the first mapping rule subset according to the event base class to obtain a target event mapping rule corresponding to the event base class in the first mapping rule subset if the type of the message queue that sends the event to be processed to the message queue is the RabbitMq message queue; Or the rule extraction unit is specifically used to extract rules from the second mapping rule subset according to the event base class if the type of the message queue that will send the event to be processed to the message queue is the Kafaka message queue, and obtain the target event mapping rule corresponding to the event base class in the second mapping rule subset.

5. The device according to claim 4, characterized in that The event sending module is further used to register the queue resource information according to the message to be processed to obtain the registered queue resource information.

6. The device according to claim 1, characterized in that The event subscription module is specifically used to subscribe to the pending message from the target message queue based on the event subscription annotation, and send the pending message to the event mapping module.

7. The device according to claim 1, characterized in that The event sending module is further used to store the event to be processed in a first database corresponding to the event sending module; The event subscription module is further used to store the event to be processed in a second database corresponding to the event subscription module.

8. The device according to claim 7, characterized in that The event-driven device also includes an event cleaning module; The event cleaning module is used to delete the pending events in the first database within a preset period of time, and to delete the pending events in the second database within the preset period of time.

9. The device according to claim 1, characterized in that The event sending module is specifically used to send the pending events submitted by the client to the event mapping module in real time based on the sending synchronizer, and to send the pending message compensation corresponding to the pending events returned by the event mapping module to the message queue based on the sending compensator.

10. An event-driven method, characterized in that: The event-driven method is applied to the event-driven device according to any one of claims 1 to 9, wherein the event-driven device comprises an event sending module, an event subscription module and an event mapping module, and the event-driven method comprises: Sending the pending event submitted by the client to the event mapping module through the event sending module, and sending the pending message corresponding to the pending event returned by the event mapping module to the target message queue; The event subscription module sends the pending message subscribed from the target message queue to the event mapping module, and sends the pending event corresponding to the pending message returned by the event mapping module to the event consumer, so that the event consumer performs event processing operations on the pending event; The event mapping module is used to map the pending event based on the event mapping rule set to obtain the pending message corresponding to the pending event returned to the event sending module, and is used to map the pending message based on the event mapping rule set to obtain the pending event corresponding to the pending message returned to the event subscription module.