Synchronous communication method, device, equipment and program product
By using multiple data tables in the Redis server to process and deliver messages, the problem of easy loss when Redis forwards messages directly is solved, and reliable synchronous communication between publishers and subscribers is achieved.
Patent Information
- Application Number
- CN202510125215.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-04-29
AI Technical Summary
In the prior art, Redis is prone to lose messages when forwarding messages directly, resulting in low reliability of communication between publishers and subscribers.
By using multiple data tables in the Redis server, data from the publishing end is received and stored in the first data table, the subscription end that has been subscribed to the table in advance is determined, the data is sent to the subscription end, and the processing results are received through the second data table, the data is marked and sent to the publishing end.
It realizes synchronous communication between publishers and subscribers, improves the reliability of messaging, and allows data to be tracked to avoid message loss.
Smart Images

Figure CN119906720A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular to synchronous communication methods, devices, equipment and program products. Background Art
[0002] The publish-subscribe model is based on message queues or topics. Publishers publish messages to specific message queues or topics, and subscribers can subscribe to these message queues or topics to receive and process messages. The publish-subscribe model is a loosely coupled, asynchronous communication method that allows publishers and subscribers to communicate without knowing each other's existence.
[0003] In the design of the platform architecture, the Redis database is used to decouple each module, and the message interaction center of all modules of the platform is built using the Redis publish-subscribe mechanism, which can effectively reduce the coupling of the interaction between modules, allowing them to run and expand independently. However, when Redis directly forwards messages, messages are easily lost, which is not conducive to the reliability of communication between publishers and subscribers. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a synchronous communication method, apparatus, device and program product to solve the problem in the prior art that messages are easily lost during data communication, which is not conducive to the reliability of communication between publishers and subscribers.
[0005] A first aspect of an embodiment of the present application provides a synchronous communication method, which is applied to a Redis server, and includes:
[0006] Receive data requested to be published by a publisher, and store the data in a first data table of the Redis server;
[0007] Determine a subscriber that has subscribed to the first data table in advance, and send the data to the subscriber;
[0008] The processing result returned by the subscriber is received and stored via the second data table, the data is marked according to the processing result, and the processing result is sent to the publisher that has subscribed to the second data table in advance.
[0009] In combination with the first aspect, in a first possible implementation manner of the first aspect, marking the data according to the processing result includes:
[0010] When the processing result is successful, the data corresponding to the processing result is written into the third data table.
[0011] In combination with the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, after marking the data according to the processing result, the method further includes:
[0012] comparing the first data table and the third data table;
[0013] When the first data table and the third data table are the same, it is determined that the subscriber successfully processes the data and the data has been successfully written into the third data table;
[0014] When the first data table and the third data table are different, exception processing is performed according to the processing result in the second data table.
[0015] In combination with the second possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, performing exception processing according to the processing result in the second data table includes:
[0016] When the processing result in the second data table is successful, writing the data into the third data table;
[0017] When the processing result in the second data table is a processing failure, the data is sent to the subscriber for attempted processing according to a predetermined attempt strategy.
[0018] In combination with the first aspect, in a fourth possible implementation manner of the first aspect, sending the data to the subscriber includes:
[0019] Monitor the status of the key space in the Redis server;
[0020] When the key state of the key space changes due to the data being stored in the first data table, the data is sent to the subscriber end through a key space event notification mechanism according to the subscriber end that has subscribed to the key state in advance.
[0021] In combination with any one of the first aspect to the fourth possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, determining a subscriber that has subscribed to the first data table in advance, and sending the data to the subscriber includes:
[0022] Determining that the subscribers who have subscribed to the first data table in advance are more than one distributed subscribers;
[0023] The data is sent to each of the distributed subscribers.
[0024] In combination with any one of the first aspect to the fourth possible implementation manner of the first aspect, in a sixth possible implementation manner of the first aspect, receiving data requested to be published by a publisher, and storing the data in a first data table of the Redis server, includes:
[0025] Receive serialized data requested to be published by the publisher;
[0026] Converting the serialized data into a database format;
[0027] The data in the database format is written into a first data table of the Redis server, and a key space subscription notification corresponding to the first data table is generated.
[0028] A second aspect of an embodiment of the present application provides a synchronous communication device, which is applied to a Redis server, and includes:
[0029] A data receiving unit, configured to receive data requested to be published by a publishing end, and store the data in a first data table of the Redis server;
[0030] A data sending unit, used to determine a subscriber that has subscribed to the first data table in advance, and send the data to the subscriber;
[0031] The data marking unit is used to receive and store the processing result returned by the subscriber through the second data table, mark the data according to the processing result, and send the processing result to the publisher that has subscribed to the second data table in advance.
[0032] A third aspect of an embodiment of the present application provides a synchronous communication device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the synchronous communication device implements a method as described in any one of the first aspects.
[0033] A fourth aspect of the embodiments of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method in the first aspect or its various implementations.
[0034] A fifth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described in any one of the first aspects are implemented.
[0035] The sixth aspect of the embodiment of the present application provides a chip for implementing the methods in each implementation of the first aspect. Specifically, the chip includes: a processor for calling and running a computer program from a memory, so that a device equipped with the chip executes the method in the first aspect or its implementation.
[0036] Compared with the prior art, the embodiments of the present application have the following beneficial effects: the embodiments of the present application store the data of the publisher in the first data table through the Redis server, and send the data to the subscriber that has subscribed to the first data table in advance, store the processing result returned by the subscriber in the second data table, send the processing result to the publisher that has subscribed to the second data table in advance, and mark the data according to the processing result, so that the publisher and the subscriber can complete synchronous communication, and the synchronized data can be marked according to the processing result, so that the data can be tracked according to the first data table and the marked data, which is conducive to improving the reliability of synchronous communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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.
[0038] Figure 1 This is a schematic diagram of a publish-subscribe model based on a Redis server provided in an embodiment of the present application;
[0039] Figure 2 It is a schematic diagram of an implementation scenario of a synchronous communication method provided in an embodiment of the present application;
[0040] Figure 3 It is a schematic diagram of an implementation flow of a synchronous communication method provided in an embodiment of the present application;
[0041] Figure 4 It is a schematic diagram of an implementation flow of a synchronous communication method provided in an embodiment of the present application;
[0042] Figure 5 is a schematic diagram of an implementation process of writing first data provided by an embodiment of the present application;
[0043] Figure 6 This is a schematic diagram of an implementation process of sending a message to a subscriber provided in an embodiment of the present application;
[0044] Figure 7 This is a schematic diagram of an implementation flow of marking a processing result provided by an embodiment of the present application;
[0045] Figure 8 This is a schematic diagram of an implementation flow of returning a processing result to a publishing end provided in an embodiment of the present application;
[0046] Fig. 9 is a schematic diagram of a synchronous communication device provided in an embodiment of the present application;
[0047] Fig.10 It is a schematic diagram of a synchronous communication device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0049] In order to illustrate the technical solution described in this application, a specific embodiment is provided below for illustration.
[0050] The publish-subscribe model is based on message queues or topics. Publishers publish messages to specific message queues or topics, and subscribers can subscribe to these message queues or topics to receive and process messages. The publish-subscribe model is a loosely coupled, asynchronous communication method that allows publishers and subscribers to communicate without knowing each other's existence.
[0051] In the design of the platform architecture, the various modules are decoupled through the Redis database, and the message interaction center of all modules of the platform is built using the Redis publish-subscribe mechanism. This can effectively reduce the coupling of interactions between modules, allowing them to run and expand independently.
[0052] like Figure 1 The figure shows a schematic diagram of a publish-subscribe model based on a Redis (Remote Dictionary Server in English and Remote Dictionary Service in Chinese) server. The publish-subscribe model includes a publisher, a subscriber, and a Redis server.
[0053] Multiple channels can be set up in the Redis server. A channel is a channel for message transmission, or it can be described as a virtual channel for message transmission. Channels are distinguished by channel names. Each channel can transmit messages independently, and multiple channels do not affect each other. The Redis server can be used to maintain the life cycle of the channel and the distribution of messages.
[0054] The publisher, also known as the producer, is the sender of the message. The publisher is responsible for generating messages and sending them to the specified channel. Messages can be various types of data, such as order information, user operation records, system status updates, etc.
[0055] The subscriber, also known as the consumer, is the recipient of the message. The subscriber is responsible for subscribing to one or more channels in order to receive different types of messages for processing. For example, it can update the database and trigger business logic based on the message. After the processing is completed, the subscriber can send the processing results back to the publisher or perform other subsequent operations.
[0056] The publish-subscribe model based on the Redis server allows the publisher to send messages to the channel, but only one by one, and after the message is forwarded by the Redis server to the subscriber who subscribes to the channel, the Redis server deletes the message. If the subscriber goes offline, the message in the channel in the Redis server will be lost when the subscriber goes offline, which is not conducive to the reliability of communication between the publisher and the subscriber.
[0057] To solve the above problems, the present invention provides a synchronous communication method. Figure 2A schematic diagram of an implementation scenario of a synchronous communication method provided in an embodiment of the present application, the implementation scenario includes a publisher, a subscriber and a Redis server. Wherein, when the publisher needs to publish a request, the publisher constructs a first message of the request to publish according to the data requested to publish, and serializes the first message to obtain a first serialized message, sends the first serialized message to the Redis server, and waits for the second serialized message of the second data table in the Redis server. After receiving the first serialized message, the Redis server writes the first serialized message to the first data table, generates a key space notification according to the change of the first data table, and sends the first serialized message to the subscriber who subscribes to the change of the first data table. The subscriber deserializes the received first serialized message to obtain the first message requested to publish, parses the first message and processes it, including verification processing, calculation processing, etc. The processed result is constructed into a second message, and the second message is serialized to obtain a second serialized message and sent to the Redis server. After receiving the second serialized message, the Redis server stores it in the second data table and determines the processing result. When the processing result is successful, the first serialized data is stored in the third data table. When the processing result is a processing failure, the first serialized data is not stored in the third data table. The changes of the second data table are monitored through key space events. When the second data table changes, that is, the second serialized message is written, the second serialized message is sent to the publisher that subscribes to the second data table. According to the difference between the first data table and the third data table, it can be determined whether the processing result is abnormal, and the processing result of the abnormality can be determined according to the second data table. The method of abnormality handling can be determined.
[0058] Figure 3 A schematic diagram of a synchronous communication method implementation flow provided in an embodiment of the present application is provided. The method is applied to a Redis server. The method is described in detail as follows:
[0059] In S301, data requested to be published by a publisher is received, and the data is stored in a first data table of the Redis server.
[0060] Before sending the requested data to the Redis server, the publisher can construct a first message of the request based on the requested data, and serialize the first message, including JSON serialization or XML serialization, to obtain a first serialized message and send it to the Redis server.
[0061] The publisher is a name determined relative to the first message. Since the publisher will also subscribe to changes in the second data table, when receiving the second serialized message sent by the Redis server when the second data table changes, the publisher is also a subscriber to the second serialized message.
[0062] After receiving the first serialized message sent by the publisher, the Redis server converts the first serialized message into a message in a database format and writes the message in the database format into the first data table in the database. The first data table is used to store the first data received from the publisher during temporary communication. In addition, the first data table can be stored in any key in the key space of the Redis server, and the key can be subscribed to by the subscriber, that is, the change information of the first data table in the key is monitored. If the first data table in the key changes, the key space event notification mechanism is used to send the received first serialized message to the subscriber.
[0063] In S302, a subscriber that has subscribed to the first data table in advance is determined, and the data is sent to the subscriber.
[0064] When the Redis server receives and stores the first serialized message, it searches for the subscriber that has subscribed to the key according to the key in the key space in which the first serialized message is written. Since the first serialized message is written into the key, the key is changed, thereby triggering a notification to be sent to the subscriber. The notification can be used to send a message including the first data, that is, the first serialized message, to the subscriber.
[0065] The way the Redis server in the embodiment of the present application processes data is different from the traditional forwarding operation. In the traditional forwarding operation, after the first serialized data is forwarded, the first serialized data is deleted. If the first serialized message needs to be tracked later, the relevant information of the first serialized message cannot be found in the Redis server. After receiving the first serialized message, the embodiment of the present application stores the first serialized message in the first data table. The Redis server will only read the data in the first data table, and each subscriber can view the first data table, so that the messages (including data) published to the first data table in the Redis server will not be lost, which is conducive to tracking the data. The messages in the first data table can be viewed through Redis instructions, so that the messages in the first data table can be visualized.
[0066] The first data table may be a data table stored in any key in the key space. When data is written to the first data table, such as writing a first serialized message, a key space event notification of the key is triggered, and a subscription notification is sent to subscribers, including one or more subscribers, that have subscribed to the first data table, and the subscription notification includes the first serialized message.
[0067] When the Redis server sends a subscription notification to a subscriber, the subscriber may be more than one distributed subscriber, and the serialized data, that is, the first serialized message, is sent to each distributed subscriber. Since the distributed subscribers are not limited in number, the subscribers can be effectively horizontally expanded.
[0068] After receiving the first serialized message, the subscriber can deserialize the first serialized message to obtain a first deserialized message, that is, the first message constructed by the publisher. The first message is parsed and processed to obtain a processing result of the first message. The processing result can be serialized to obtain a second serialized message.
[0069] In S303, the processing result returned by the subscriber is received and stored in the second data table, the data is marked according to the processing result, and the processing result is sent to the publisher that has subscribed to the second data table in advance.
[0070] When the Redis server receives the second serialized message of the processing result returned by the subscriber, the second serialized message can be converted into a message in database format and stored in the second data table. The publisher can pre-subscribe to the second data table, that is, subscribe to the key of the key space where the second data table is located. When the key changes, such as when the second data table writes the second serialized message, a key space event notification can be generated, so that the publisher that subscribes to the second data table (actually the subscriber of the second data table) obtains the second serialized message including the processing result. The publisher can deserialize the second serialized message to obtain the processing result, and the processing result can be further processed by the publisher.
[0071] When receiving the second serialized message, the Redis server in the embodiment of the present application can obtain the processing result of the first serialized message by the subscriber, and based on the processing result, the first serialized message can be marked.
[0072] In the embodiment of the present application, when marking the first serialized message, a third data table may be set, and data for marking may be stored in the third data table. For example, the first serialized message with a processing result of successful processing may be stored in a predetermined third data table. The data successfully processed and published by the publishing end may be intuitively viewed through the third data table.
[0073] In the embodiment of the present application, when the processing is successful, when the first serialized message is stored in the third data table, the data stored in the first data table and the third data table can be compared to see if they are the same. If they are the same, it indicates that the data has been successfully processed, and the correct processing result can be returned to the publishing end.
[0074] If the first data table and the third data table are different, the different data can be tracked, for example, the abnormal processing results or the processing results of failed processing can be combined with the data in the second data table to perform exception processing.
[0075] In a possible implementation, within the determined comparison range, if the first data table and the third data table are different, it can be found that there are different data, that is, there are different first serialized messages, and the second serialized message corresponding to the message, that is, the processing result of the first serialized message, is found. When the processing result is successful, it means that the storage of the first serialized message to the third data table is abnormal, and the data, that is, the first serialized message, can be written into the third data table.
[0076] If the processing result of the first serialized message is a processing failure, the data can be resent to the subscriber for processing according to a predetermined attempt strategy, such as determining the number of attempts based on the importance of the data, or the data can be corrected and the corrected data can be resent to the subscriber for processing. When the number of resends reaches the set number, or the corrected data still cannot meet the requirements for successful processing, such as the returned second serialized message is a processing failure, or the processing result returned by the subscriber is not received, the data can be marked as abnormally processed data. Data that has been marked as abnormally processed, or data that has been compared and processed, does not need to be compared and judged repeatedly in the subsequent comparison process of the first data table and the third data table.
[0077] It is understandable that the messages stored in the first data table and the third data table may include multiple messages. When tracking the processing results, the messages within the currently set time range can be tracked, that is, the messages in the first data table and the third data table within the set time range are compared to determine whether the messages within the time range are the same. If one or more messages are different, the corresponding processing results can be searched in the second data table according to the different messages, and exception processing can be performed based on the processing results.
[0078] Figure 4 A schematic diagram of an implementation flow of a synchronous communication method based on a Redis server provided in an embodiment of the present application is described in detail as follows:
[0079] 1. The publisher writes the requested first data into the first data table of the Redis server and waits for the message of the subscribed second data table.
[0080] Among them, the publishing end in the embodiment of the present application can be understood as the publishing end of the first data. Since the publishing end subscribes to the second data table, the publishing end is actually also the subscriber of the second data.
[0081] The specific process of writing the first data to the Redis server can be as follows: Figure 5 As shown, including:
[0082] In S501, first data requested to be published is determined.
[0083] When the publishing end needs to send data to the subscribing end so that the subscribing end processes the data, the data can be determined as the first data requested to be published. For example, when the monitoring end detects an abnormality, it sends monitoring data to multiple monitoring terminals and requests any monitoring terminal to process the data, including confirmation of the abnormal information.
[0084] In S502, a first message for request is constructed according to the first data.
[0085] The publisher constructs a specific first message based on the data model negotiated with the subscriber, and the first message may contain all necessary information that the subscriber needs to process.
[0086] In S503, the first message is serialized to obtain a first serialized message.
[0087] In order to store the first message in the Redis database, the publisher needs to serialize the constructed first message. Serialization is the process of converting a data structure or object state into a storable or transmittable format so that it can be correctly written to the database later.
[0088] In S504, the first serialized message is written into the first data table.
[0089] The first serialized message after serialization is written into the first data table in the Redis database. This first data table can be used to store and transmit the first message of the request, which can facilitate subsequent message backtracking and searching.
[0090] In S505, after sending the first data, the publisher waits for a message from the second data table.
[0091] After writing the first message of the request to the first data table, since the publisher has pre-subscribed to the second data table and is waiting for the message of the processing result written by the subscriber after processing the request, the publisher needs to wait for the subscriber to complete the message processing and receive the processing result returned by the subscriber before continuing the subsequent operations.
[0092] 2. The first data table of the Redis server writes data, triggers a notification, and sends the first data to the subscriber that has subscribed to the first data table.
[0093] When the Redis server writes the first data (including the first serialized message of the first data) into the first data table, the Redis server sends a notification to the subscriber who has subscribed to the first data table through the key space event notification mechanism, and sends the first serialized message to the subscriber for deserialization and data processing. The specific process can be as follows: Figure 6 As shown, including:
[0094] In S601, the subscriber obtains a first serialized message according to the key space event notification.
[0095] When the first serialized message is written into the first data table, the subscriber that has subscribed to the event notification of the key where the first data table is located will receive a notification, and the notification includes the first serialized message currently being written.
[0096] In S602, the first serialized message is deserialized to obtain a first message.
[0097] Due to the need for data transmission, the first serialized message is serialized data, and the first message can be obtained through deserialization.
[0098] In S603, the first message is parsed to obtain the first data requested to be published by the publisher.
[0099] According to the construction method of the first message, the first message is parsed to obtain the first data.
[0100] In S604, the first data is processed.
[0101] After the subscriber obtains the first data through parsing, the subscriber can process the first data according to the processing logic of the subscriber to obtain a processing result.
[0102] 3. The subscriber receives the first data, processes the first data according to a predetermined processing logic, returns the processing result to the Redis server, and writes the second data including the processing result into the second data table.
[0103] After processing the first data, the subscriber can generate a processing result. At this time, the subscriber can serve as a publisher of the processing result and send the processing result to the Redis server. Specifically, Figure 7 As shown, including:
[0104] In S701, a second message is constructed according to the processing result.
[0105] After the subscriber processes the first data, the processing result of the first data can be obtained. The processing result is the data that the subscriber needs to publish. At this time, the second data including the processing result can be constructed as a second message, and the second message is published to the Redis server.
[0106] In S702, serialization processing is performed on the second message to obtain a second serialized message.
[0107] In order to store the second message in the Redis database, the publisher needs to serialize the constructed second message. Serialization is the process of converting a data structure or object state into a storable or transmittable format so that it can be correctly written to the database later.
[0108] In S703, the second serialized message is written into the second data table.
[0109] To facilitate subsequent data tracking, the second serialized message including the processing result is written into the second data table, so that when an abnormality occurs in the data, the abnormality can be analyzed and processed according to the processing result stored in the second data table.
[0110] 4. When the processing result is successful, the first data is written into the third data table; if the processing result is failed, the first data is not written into the third data table.
[0111] When the processing result is successful, the first serialized data is stored in the third data table. When the processing result is failed, the first serialized data is not stored in the third data table. According to the difference between the first data table and the third data table, it can be determined whether the processing result is abnormal, and the abnormal processing result can be determined according to the second data table.
[0112] Within the data range that needs to be compared, if the data in the first data table and the data in the third data table are the same, it indicates that the data have been successfully processed and the correct processing result can be returned to the publishing end.
[0113] If the first data table and the third data table are different, the different data can be tracked, for example, the abnormal processing results or the processing results of failed processing can be combined with the data in the second data table to perform exception processing.
[0114] For example, when handling exceptions, you can find different data, that is, different first serialized messages, and find the second serialized message corresponding to the message, that is, the processing result of the first serialized message. When the processing result is successful, it means that the first serialized message is stored in the third data table abnormally, and you can write the data, that is, the first serialized message, into the third data table.
[0115] If the processing result of the first serialized message is a processing failure, the data can be resent to the subscriber for processing according to a predetermined attempt strategy, such as determining the number of attempts based on the importance of the data, or the data can be corrected and the corrected data can be resent to the subscriber for processing. When the number of resends reaches the set number, or the corrected data still cannot meet the requirements for successful processing, such as the returned second serialized message is a processing failure, or the processing result returned by the subscriber is not received, the data can be marked as abnormally processed data. Data that has been marked as abnormally processed, or data that has been compared and processed, does not need to be compared and judged repeatedly in the subsequent comparison process of the first data table and the third data table.
[0116] 5. The Redis server writes the second data table, triggering the sending of a message including the second data to the publisher that has subscribed to the second data table.
[0117] The changes of the second data table are monitored through key space events. When the second data table changes, that is, the second serialized message is written, the second serialized message is sent to the publisher who subscribes to the second data table. The specific implementation process is as follows Figure 8 As shown, including:
[0118] In S801, the changes of the second data table subscribed by the publisher are monitored.
[0119] The publisher has pre-subscribed to the key of the second data table. When the key changes, including writing data, deleting data, or modifying data, a notification will be sent to the publisher.
[0120] In S802, when the second serialized message is written into the second data table, the second serialized message is sent to the publishing end.
[0121] When the second serialized message is written into the second data table, the key trigger notification of the second data table is monitored, and the second serialized message is sent to the publishing end.
[0122] In S803, the second serialized message is deserialized to obtain a second message.
[0123] In order to obtain the processing result, the publisher needs to deserialize the received second serialized message to obtain the second message.
[0124] In S804, the second message is parsed to obtain a processing result.
[0125] By parsing the second message, the processing result included in the second message can be obtained to complete the data notification with the subscriber.
[0126] The embodiment of the present application expands the publish-subscribe function of the Redis server and transmits data according to the key space event notification of the Redis server, so that the publisher and the subscriber can effectively complete the synchronous communication of data, and can track and restore the historical communication data, which is beneficial to improving the reliability of data communication.
[0127] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0128] Fig. 9 A schematic diagram of a synchronous communication device provided in an embodiment of the present application, wherein the synchronous communication device is applied to a Redis server, and the device includes:
[0129] A data receiving unit 901 is used to receive data requested to be published by a publisher, and store the data in a first data table of the Redis server;
[0130] The data sending unit 902 is used to determine a subscriber that has subscribed to the first data table in advance, and send the data to the subscriber;
[0131] The data marking unit 903 is used to receive and store the processing result returned by the subscriber through the second data table, mark the data according to the processing result, and send the processing result to the publisher that has subscribed to the second data table in advance.
[0132] Fig. 9 The synchronous communication device shown is Figure 3 Corresponding to the synchronous communication method shown.
[0133] Fig.10 Schematic diagram of a synchronous communication device provided in an embodiment of the present application. Fig.10 As shown, the synchronous communication device 10 of this embodiment includes: a processor 100, a memory 101, and a computer program 102 stored in the memory 101 and executable on the processor 100, such as a synchronous communication program. When the processor 100 executes the computer program 102, the steps in the above-mentioned various synchronous communication method embodiments are implemented. Alternatively, when the processor 100 executes the computer program 102, the functions of each module / unit in the above-mentioned various device embodiments are implemented.
[0134] Exemplarily, the computer program 102 may be divided into one or more modules / units, which are stored in the memory 101 and executed by the processor 100 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 102 in the synchronous communication device 10.
[0135] The synchronous communication device 10 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server with a Redis database. The synchronous communication device may include, but is not limited to, a processor 100 and a memory 101. Those skilled in the art will appreciate that Fig.10 It is only an example of a synchronous communication device 10 and does not constitute a limitation of the synchronous communication device 10. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the synchronous communication device may also include input and output devices, network access devices, buses, etc.
[0136] The processor 100 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0137] The memory 101 may be an internal storage unit of the synchronous communication device 10, such as a hard disk or memory of the synchronous communication device 10. The memory 101 may also be an external storage device of the synchronous communication device 10, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the synchronous communication device 10. Further, the memory 101 may also include both an internal storage unit of the synchronous communication device 10 and an external storage device. The memory 101 is used to store the computer program and other programs and data required by the synchronous communication device. The memory 101 may also be used to temporarily store data that has been output or is to be output.
[0138] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0139] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0140] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0141] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0142] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0143] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0144] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by hardware related to computer program instructions. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0145] In addition, an embodiment of the present application also provides a computer program product, which, when executed on a computer, enables the computer to execute the methods in the above-mentioned implementation modes.
[0146] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A synchronous communication method, characterized in that: The synchronous communication method is applied to a Redis server, and the method comprises: Receive data requested to be published by a publisher, and store the data in a first data table of the Redis server; Determine a subscriber that has subscribed to the first data table in advance, and send the data to the subscriber; The processing result returned by the subscriber is received and stored via the second data table, the data is marked according to the processing result, and the processing result is sent to the publisher that has subscribed to the second data table in advance.
2. The method according to claim 1, characterized in that: Marking the data according to the processing result includes: When the processing result is successful, the data corresponding to the processing result is written into the third data table.
3. The method according to claim 2, characterized in that After marking the data according to the processing result, the method further includes: comparing the first data table and the third data table; When the first data table and the third data table are the same, it is determined that the subscriber successfully processes the data and the data has been successfully written into the third data table; When the first data table and the third data table are different, exception processing is performed according to the processing result in the second data table.
4. The method according to claim 3, characterized in that Performing exception processing according to the processing result in the second data table includes: When the processing result in the second data table is successful, writing the data into the third data table; When the processing result in the second data table is a processing failure, the data is sent to the subscriber for attempted processing according to a predetermined attempt strategy.
5. The method according to claim 1, characterized in that Sending the data to the subscriber includes: Monitor the status of the key space in the Redis server; When the key state of the key space changes due to the data being stored in the first data table, the data is sent to the subscriber end through a key space event notification mechanism according to the subscriber end that has subscribed to the key state in advance.
6. The method according to any one of claims 1 to 5, characterized in that: Determining a subscriber that has subscribed to the first data table in advance, and sending the data to the subscriber, includes: Determining that the subscribers who have subscribed to the first data table in advance are more than one distributed subscribers; The data is sent to each of the distributed subscribers.
7. The method according to any one of claims 1 to 5, characterized in that Receiving data requested to be published by a publisher, and storing the data in a first data table of the Redis server, including: Receive serialized data requested to be published by the publisher; Converting the serialized data into a database format; The data in the database format is written into a first data table of the Redis server, and a key space subscription notification corresponding to the first data table is generated.
8. A synchronous communication device, characterized in that: The synchronous communication device is applied to a Redis server, and the device comprises: A data receiving unit, configured to receive data requested to be published by a publishing end, and store the data in a first data table of the Redis server; A data sending unit, used to determine a subscriber that has subscribed to the first data table in advance, and send the data to the subscriber; The data marking unit is used to receive and store the processing result returned by the subscriber through the second data table, mark the data according to the processing result, and send the processing result to the publisher that has subscribed to the second data table in advance.
9. A synchronous communication device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the synchronous communication device implements the method according to any one of claims 1 to 7.
10. A computer program product comprising computer program instructions, characterized in that When the computer program is executed, the method according to any one of claims 1 to 7 is performed.