Method and device for message transmission between components, storage medium and electronic device
By recording the mapping relationship between message identification and memory address in the subscription table, and directly searching and passing the target message, the problem of large storage resource occupancy in message delivery between components is solved, and information acquisition efficiency is improved.
Patent Information
- Application Number
- CN202211349243.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-31
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2042-10-31
AI Technical Summary
In the prior art, the message delivery method between components is low due to the large storage resources occupied by the subscription table.
By recording the mapping relationship between the message identification of the subscribed message and the memory address of the corresponding information storage unit in the subscription table, only the memory address of the target storage unit corresponding to the target message identification is found in the subscription table, and it is directly passed to the message subscription component corresponding to the subscription information stored by the target storage unit.
It reduces the storage resources occupied by the subscription table, improves the efficiency of information acquisition, and solves the problem of low information acquisition efficiency.
Smart Images

Figure CN115766314B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of smart home / intelligent home technology, and more specifically, to a method and device for message transmission between components, a storage medium, and an electronic device. Background Art
[0002] In the embedded system field, to facilitate message transmission between different components within the system, message distribution and delivery can be carried out based on a subscription-based publishing approach. Message subscribers (i.e., message receivers, components that receive messages) can subscribe to messages using message identifiers, and multiple message subscribers can subscribe to messages identified by the same message identifier.
[0003] In related technologies, subscription information corresponding to message subscribers can be stored in a subscription table. The subscription table records a message identifier and the subscription information corresponding to the message subscriber that subscribed to the message identified by the message identifier. However, this method of storing subscription information consumes a large amount of memory resources. When messaging between components, it is necessary to traverse all subscription information in the subscription table to determine the required subscription information, resulting in low information acquisition efficiency.
[0004] It can be seen that the message transmission method between components in the related art has the problem of low efficiency in information acquisition due to the large storage resources occupied by the subscription table. Summary of the Invention
[0005] The embodiments of the present application provide a method and device for message transmission between components, a storage medium and an electronic device, so as to at least solve the problem of low efficiency of information acquisition caused by the large storage resources occupied by the subscription table in the message transmission method between components in the related art.
[0006] According to one aspect of an embodiment of the present application, a method for message delivery between components is provided, comprising: acquiring a target message published by a message publishing component of a target device through a message delivery component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier; in response to the acquired target message, searching a subscription table according to the target message identifier, wherein the subscription table is used to record a mapping relationship between a message identifier of a subscribed message and a memory address of an information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store subscription information corresponding to the message subscription component of the subscribed message; when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, delivering the target message to the message subscription component corresponding to the subscription information stored in the target storage unit.
[0007] According to another aspect of an embodiment of the present application, a message delivery device between components is also provided, including: a first acquisition unit, used to acquire a target message published by a message publishing component of a target device through a message delivery component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier; a search unit, used to search a subscription table according to the target message identifier in response to the acquired target message, wherein the subscription table is used to record a mapping relationship between a message identifier of a subscribed message and a memory address of an information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store subscription information corresponding to the message subscription component of the subscribed message; a delivery unit, used to deliver the target message to the message subscription component corresponding to the subscription information stored in the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table.
[0008] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the above-mentioned message passing method between components during runtime.
[0009] According to another aspect of an embodiment of the present application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above-mentioned method of message transmission between components through the computer program.
[0010] In an embodiment of the present application, a method of recording the mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit of the corresponding component information in the subscription table is adopted, and the target message published by the message publishing component of the target device is obtained through the message transmission component of the target device, wherein the message transmission component is used to transmit messages between different components of the target device, and the target message is a message identified by the target message identifier; in response to the obtained target message, the subscription table is searched according to the target message identifier, wherein the subscription table is used to record the mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store the subscription information corresponding to the message subscription component of the subscribed message; the target message is found in the subscription table In the case of the memory address of the target storage unit corresponding to the target message identifier, the target message is passed to the message subscription component corresponding to the subscription information stored in the target storage unit. Since the information stored in the subscription table is only the mapping relationship between the memory address of the storage unit of the component information of the subscription message and the message identifier of the subscribed message, the storage resources occupied by the subscription table are relatively small. Before distributing the message, the memory address of the storage unit corresponding to the message identifier can be found through the mapping relationship stored in the subscription table, so as to determine whether there is a component that has subscribed to the published message. The purpose of reducing the storage resources occupied by the subscription table can be achieved, and the technical effect of improving the efficiency of information acquisition is achieved, thereby solving the problem of low efficiency of information acquisition caused by the large storage resources occupied by the subscription table in the message transmission method between components in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0012] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0013] Figure 1 1 is a schematic diagram of a hardware environment for a method for message transmission between components according to an embodiment of the present application;
[0014] Figure 2 This is a flow chart of an optional method for message transmission between components according to an embodiment of the present application;
[0015] Figure 3 is a flowchart of another optional method for message transmission between components according to an embodiment of the present application;
[0016] Figure 4 This is a structural block diagram of an optional inter-component message transmission device according to an embodiment of the present application;
[0017] Figure 5 This is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0018] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0019] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0020] According to one aspect of the embodiment of the present application, a method for message transmission between components is provided. The message transmission method between components is widely used in smart home (Smart Home), smart home, smart home device ecology, smart residential (Intelligence House) ecology and other whole-house intelligent digital control application scenarios. Optionally, in this embodiment, the message transmission method between components can be applied to Figure 1 In the hardware environment shown in FIG. 1 , which is composed of a terminal device 102 and a server 104. Figure 1 As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or the client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.
[0021] The aforementioned network may include, but is not limited to, at least one of the following: a wired network and a wireless network. The aforementioned wired network may include, but is not limited to, at least one of the following: a wide area network, a metropolitan area network, and a local area network. The aforementioned wireless network may include, but is not limited to, at least one of the following: Wi-Fi (Wireless Fidelity) and Bluetooth. The terminal device 102 may be, but is not limited to, a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart range hood, a smart refrigerator, a smart oven, a smart stove, a smart washing machine, a smart water heater, a smart washing machine, a smart dishwasher, a smart projection device, a smart TV, a smart clothes drying rack, smart curtains, smart audio and video, a smart socket, a smart speaker, a smart fresh air device, smart kitchen and bathroom equipment, smart bathroom equipment, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purifier, a smart steamer, a smart microwave oven, a smart kitchen treasure, a smart purifier, a smart water dispenser, a smart door lock, or other voice-activated devices capable of voice interaction.
[0022] The inter-component message transmission method of the embodiment of the present application can be executed by the server 104, or by the terminal device 102, or jointly by the server 104 and the terminal device 102. The inter-component message transmission method of the embodiment of the present application can also be executed by the client installed on the terminal device 102.
[0023] Taking the method for transmitting messages between components in this embodiment executed by the terminal device 102 as an example, Figure 2 FIG. 1 is a flow chart of an optional method for transmitting messages between components according to an embodiment of the present application, such as Figure 2 As shown, the process of the method may include the following steps:
[0024] Step S202: obtaining a target message published by a message publishing component of the target device through a message delivery component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier.
[0025] The inter-component messaging method in this embodiment can be applied to a scenario where the internal messaging component of the target device completes message distribution through a subscription table. The operating system running on the target device here can be an operating system in the field of embedded systems, for example, an ecological operating system for smart homes in the field of smart homes. An embedded system can include hardware and software parts. The operating system in the embedded system can have the core functions of a general operating system and be responsible for allocating hardware and software resources of the embedded system, scheduling work control, and coordinating concurrent activities. The target device can be a smart home device or other types of terminal devices.
[0026] In the field of embedded systems, to enable message delivery between a message sender and a message receiver within a target device, a message agent can be set up. This agent can retrieve messages sent (i.e., published) by the message publisher and pass the retrieved messages to the message receiver. The message sender and the message receiver can only focus on the interface corresponding to the message agent. Here, the message agent can distribute and deliver messages based on a subscription and publish method. The message agent can retrieve messages published by the message sender and distribute the retrieved messages to the message receiver that has subscribed to the message. Correspondingly, the message sender can be a message publisher of a specific message type and can be referred to as a message publishing component, publisher, publisher, etc. The message receiver can be a subscriber of a specific message type and can be referred to as a message subscription component, subscriber, subscriber, etc. The message agent is also called a messaging component, a publish-subscribe component, etc.
[0027] It should be noted that the message receiver can be an independent component or a component that relies on an RTE (Run-Time Environment). The RTE environment refers to a specific, independent context in which a piece of code is about to be executed, equivalent to an independent thread. The messaging component is a component distinct from the message publisher and message receiver. When a message is published by a message broker, upon receiving a message published to the messaging component, the messaging component can retrieve the message type and send it to the RTE environment for execution. If an RTE environment is not available, the callback function registered by the message receiver can be directly executed. When subscribing to messages, the message subscriber can use the message subscription interface provided by the publish-subscribe component to subscribe to specific messages. When distributing messages within the system, the message publisher can publish the message by calling the message publishing interface provided by the publish-subscribe component, publishing the message to be published to the messaging component, which then completes the distribution and message delivery process.
[0028] In this embodiment, in the target device, after the message publishing component, as the message publishing end, publishes the target message to the message passing component, the target message published by the message publishing component can be obtained through the message passing component. The target message can be published to the message passing component by the message publishing component by calling the message publishing interface of the message passing component. Here, the target message can be identified by a target message identifier, which can be a message of a specific message type published by the message publishing component, and can be used to trigger the message receiving component to execute the corresponding business. The target message identifier can be the message ID (Identity document) of the target message, and the message ID can be a message event number (message identifier, msg_id) defined according to the specific business logic needs, which can be defined according to the specific business logic needs. Here, the message passing component can be used to transmit messages between different components of the target device.
[0029] Step S204: In response to the acquired target message, the subscription table is searched according to the target message identifier, wherein the subscription table is used to record the mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store the subscription information corresponding to the message subscription component of the subscribed message.
[0030] The message subscription component of the target device can ensure timely receipt of messages by subscribing to messages in advance using message identifiers. Different message subscription components can use the same message identifier to subscribe to the same message identified by the message identifier, and the same message subscription component can subscribe to different messages using different message identifiers or different subscription parameters. The subscription information corresponding to the message subscription component can be stored in the form of a subscription table. The subscription table can be used to record the mapping relationship between the message identifier of the subscribed message and the subscription information corresponding to the message subscription component that has subscribed to the subscribed message. The subscription table can be stored in memory, so that the subscription information can be stored and managed by directly operating the memory. Compared with storing and managing subscription information through a database, the subscription information can be obtained faster and with less resources.
[0031] If a message identified by a message identifier has only one message subscription component, the subscription table can be recorded and managed using a simple kv (key-value) data management method, where the key is the message identifier (i.e., msg_id) and the value is the memory address of the subscription information corresponding to the message subscription component. However, the target device generally has multiple messages and multiple message subscription components. A message identified by a message identifier is typically not a single message subscription component, but rather multiple message subscription components. Moreover, the same message subscription component may subscribe to multiple messages through one or more message identifiers. If the same message subscription component subscribes to multiple messages, or the same message is subscribed to by multiple message subscription components, the subscription table of the target device occupies a large amount of storage resources using the above subscription information storage method. When messages are transmitted between components, all subscription information in the subscription table must be traversed to determine all subscription information. Using this database storage and management method for subscription information, when the subscription information is large and complex, the subscription table requires a large amount of memory, and the efficiency of information acquisition is also low.
[0032] For example, the same msg_id may be subscribed to by one or more subscribers. If there is only one subscriber, this can be managed using a simple key-value data management approach, where the key is the msg_id and the value is the memory address of the subscriber information. However, the subscriber of a msg_id is usually not a single subscriber.
[0033] In order to at least partially solve the above problem, in this embodiment, the subscription information corresponding to the message subscription component of the subscribed message can be stored in an information storage unit outside the subscription table. The subscription table only records the mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the memory resources occupied by the subscription table are relatively small. When messages are transmitted between components, it is not necessary to spend a long time traversing the subscription table to determine whether there is a message subscription component that has subscribed to the current message; if so, the required subscription information can be found in the memory address of the information storage unit corresponding to the message identifier. Here, the information storage unit can be a storage structure of the type of information linked list. The information linked list can be a non-continuous, non-sequential storage structure in a physical storage space, and can be composed of a series of nodes (each element in the linked list is called a node or a node), and the nodes can be dynamically generated at runtime.
[0034] Optionally, the mapping relationship recorded in the subscription table can be a relationship obtained by mapping the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message. The mapping here can be a hash map, which can use one object to retrieve another object, with the first object being the key and the second object being the value. In this embodiment, Figure 3 As shown, you can use the message identifier as the key and the memory address of the information storage unit as the value. If there is only one message subscription component for a message, you can use Figure 3 The kv data management method on the right side of the middle is used to manage subscription information. If there are multiple message subscription components for the same message, you can use Figure 3 The information storage unit on the left manages subscription information to record subscription information.
[0035] In this embodiment, in response to a received target message, the messaging component can determine the target message identifier corresponding to the target message and search the subscription table according to the target message identifier. If the subscription table records a mapping relationship between the target message identifier and the memory address of the information storage unit corresponding to the target message identifier, the memory address of the information storage unit corresponding to the target message identifier recorded in the subscription table can be determined. If the subscription table does not record a mapping relationship between the target message identifier and the memory address of the information storage unit corresponding to the target message identifier, it can be determined that no message subscription component has subscribed to the target message.
[0036] Step S206: When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit.
[0037] In this embodiment, if a mapping relationship between a target message identifier and the memory address of the information storage unit corresponding to the target message identifier is found in the subscription table, the information storage unit corresponding to the target message identifier can be located based on the found memory address. Since the information storage unit corresponding to the target message identifier only stores subscription information corresponding to the message subscription component that subscribes to the target message, the target message can be directly delivered to the message subscription component corresponding to the subscription information stored in the target storage unit based on the subscription information in the information storage unit corresponding to the target message identifier. Here, the target storage unit may store subscription information corresponding to the message subscription component that subscribes to the target message.
[0038] If multiple message subscription components have subscribed to the target message, the message delivery component can deliver the target message to each message subscription component separately. The process of delivering the target message to different message subscription components can be performed in parallel or serially (i.e., the target message is delivered to each message subscription component in sequence). This embodiment does not limit the distribution method (i.e., delivery method) of the target message.
[0039] Optionally, if the memory address of the target storage unit corresponding to the target message identifier is not found in the subscription table, it can be determined that the target message has not been subscribed to by any message subscription component, and the messaging component can end the distribution operation of the target message.
[0040] It should be noted that during message delivery, the message broker can pass the pending message (e.g., the target message) to the message subscriber by executing a callback function registered by the message subscriber. The callback function can be a message processing function, which can be registered by the message subscriber when subscribing to a message. The completion of the message processing function call indicates that the message subscriber has received and processed the message. When publishing a message, the message broker calls this message processing function, passing the message content as parameters to the function. The function's internal processing implements the message and performs the corresponding business logic processing (equivalent to performing business processing on the message according to the needs of the message subscriber, thus achieving message delivery). Furthermore, the message subscriber can define parameters for the message processing function and pass them in when subscribing to a message, so that the messaging component can call it when delivering the message, meeting the specific needs of the message subscriber.
[0041] Through the above steps S202 to S206, the message delivery component of the target device obtains the target message published by the message publishing component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by the target message identifier; in response to the acquired target message, the subscription table is searched according to the target message identifier, wherein the subscription table is used to record the mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store the subscription information corresponding to the message subscription component of the subscribed message; when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit, thereby solving the problem of low efficiency of information acquisition due to the large storage resources occupied by the subscription table in the message delivery method between components in the related art, thereby improving the efficiency of information acquisition.
[0042] In an exemplary embodiment, when a memory address of a target storage unit corresponding to a target message identifier is found in a subscription table, delivering the target message to a message subscription component corresponding to subscription information stored in the target storage unit includes:
[0043] S11, when a header address of a target information linked list corresponding to the target message identifier is found in the subscription table, each linked list node in the target information linked list is traversed according to the header address of the target information linked list, wherein each linked list node stores subscription information corresponding to a message subscription component of the message identified by the target message identifier;
[0044] S12: Deliver the target message to the message subscription component corresponding to the subscription information stored in each traversed linked list node.
[0045] If the information storage unit storing subscription information is an information linked list, the mapping relationship recorded in the subscription table may be a mapping relationship between the message identifiers of the subscribed messages and the header addresses of the information linked list corresponding to the message identifiers of the subscribed messages, and the memory address of the information storage unit may be the header address of the information linked list. The information linked list may be a bidirectional circular linked list, and the header of the information linked list may be a head node.
[0046] In this embodiment, the target storage unit may be a target information linked list, and the memory address of the target storage unit is the header address of the target information linked list. When the header address of the target information linked list corresponding to the target message identifier is found in the subscription table, each linked list node in the target information linked list may be traversed according to the header address of the target information linked list. Here, each linked list node may store subscription information corresponding to a message subscription component of the message identified by the target message identifier.
[0047] Optionally, an information linked list can be used to record the subscription information corresponding to all message subscription components of the message identified by the same message identifier (for example, msg_id). Each linked list node in the information linked list stores the subscription information corresponding to a message subscription component of the message identified by the message identifier. The memory address of the linked list header of the information linked list is used as the value and the message identifier for hash mapping, and the obtained mapping relationship is stored in the subscription table.
[0048] For each linked list node in the traversed target information linked list, the target message can be delivered to the message subscription component corresponding to the subscription information stored in each traversed information linked list node according to the subscription information stored therein. The target message can be delivered after the target information linked list is traversed, or after each linked list node is traversed. The distribution process can be the same as in the previous embodiment and will not be described in detail in this embodiment.
[0049] For example, to solve the problem of multiple subscribers subscribing to the same msg_id, the subscriber information for multiple subscribers with the same msg_id (i.e., the subscription information described above) can be managed using a linked list. That is, all subscriber information with the same msg_id is placed in the same linked list. Then, the address of the linked list header is used as the value and hashed with the msg_id, and the resulting mapping is stored in the subscription table.
[0050] When publishing a msg_id, the subscription table can be searched for a linked list header mapping based on the msg_id. If so, the linked list is traversed and the message is distributed to each subscriber. If a message is delivered, the message can be passed as a parameter to the message processing function to implement the message delivery function. Here, the message processing function can be called by the message delivery component to perform the corresponding business logic processing. The parameters of the message processing function can be customized by the message subscription component.
[0051] According to this embodiment, the message subscription component information of the target message is determined by traversing the linked list storing subscription information, thereby improving the speed of obtaining subscription information.
[0052] In an exemplary embodiment, the method further includes:
[0053] S21, obtaining a message subscription request of a first component of a target device, wherein the message subscription request is used to request subscription to a message identified by a target message identifier in a message published to a messaging component of the target device;
[0054] S22, in response to the obtained message subscription request, determining first subscription information corresponding to the first component;
[0055] S23: When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and there is no subscription information matching the first subscription information in the subscription information stored in the target storage unit, the first subscription information is added to the target storage unit.
[0056] For a component that has a message subscription requirement (i.e., a message subscription component), the subscription to the message can be completed by passing a message subscription request to the messaging component. If a first component in a target device has a message subscription requirement identified by a target message identifier, the message subscription request can be passed to the messaging component. The message subscription request can include the target message identifier and the component identifier of the first component, and can be used to request a subscription to the message published to the messaging component, the message identified by the target message identifier, for example, the target message.
[0057] Here, the messaging component may be configured with a message subscription interface for message subscription. The message subscription component may send the information required for message subscription (equivalent to an incoming message subscription request) to the messaging component by calling the message subscription interface to implement message subscription. For example, the first component may call the message subscription interface of the messaging component and pass in a target message identifier and other information for subscribing to the message identified by the target message identifier to implement subscription to the message identified by the target message identifier.
[0058] After receiving a message subscription request from a first component, the messaging component may determine that the first component has a subscription requirement for the message identified by the target message identifier. In response to the received message subscription request, the messaging component may determine first subscription information corresponding to the first component. Here, the first subscription information may be used to indicate a subscription relationship between the message identified by the target message identifier and the first component. The first subscription information may be carried in the message subscription request or generated based on information carried in the message subscription request.
[0059] Optionally, the messaging component may store the first subscription information, for example, in a requested memory segment. For example, the messaging component may request a node and cache the first subscription information in the requested node. The first subscription information may be temporarily stored in the messaging component or in a memory resource external to the messaging component. However, the address information of the corresponding memory resource may be stored in the messaging component to ensure that the messaging component can readily retrieve the stored subscription information.
[0060] Since the first component may subscribe to the target message repeatedly, in order to avoid excessive waste of memory resources for storing subscription information due to repeated subscriptions, and repeated distribution of messages due to storing repeated subscription information, it is possible to determine whether the first subscription information is a repeated subscription to the message identified by the target message identifier based on all stored subscription information corresponding to the target message identifier.
[0061] The above-mentioned step of determining whether it is a duplicate subscription may be: searching the subscription table for a memory address of a storage unit corresponding to the target message identifier according to the target message identifier. If the memory address is not found, it indicates that the message identified by the target message identifier has not been subscribed to and there is no duplicate subscription. If the memory address of the target storage unit corresponding to the target message identifier is found, but subscription information matching the first subscription information does not exist in the target storage unit, it indicates that there is no duplicate subscription. If the memory address of the target storage unit corresponding to the target message identifier is found, and subscription information matching the first subscription information exists in the target storage unit, it indicates that there is a duplicate subscription.
[0062] It should be noted that a subscription message can contain multiple subscription parameters. A duplicate subscription is considered a duplicate only if all subscription parameters are the same. Otherwise, it is not a duplicate subscription. Furthermore, multiple subscription parameters may include, but are not limited to, at least one of the following: a message identifier, a component identifier, an RTE runtime environment, a message processing function, and the like.
[0063] In this embodiment, when the memory address of the target storage unit corresponding to the target message identifier is found from the subscription table and there is no subscription information matching the first subscription information in the subscription information stored in the target storage unit, the first subscription information can be added to the target storage unit.
[0064] Through this embodiment, the components within the device request to subscribe to the message identified by a certain message identifier through a subscription request, and when the message transmission component determines that it is not a repeated subscription, it adds the corresponding subscription information to the information storage unit, which can ensure the success rate of the component's subscription to the message and avoid resource waste caused by repeated subscription.
[0065] In an exemplary embodiment, after determining the first subscription information corresponding to the first component in response to the acquired message subscription request, the method further includes:
[0066] S31, when the memory address of the information storage unit corresponding to the target message identifier is not found in the subscription table, creating an information storage unit to obtain a target storage unit;
[0067] S32: Add a mapping relationship between the target message identifier and the memory address of the target storage unit in the subscription table, and add the first subscription information to the target storage unit.
[0068] In this embodiment, if the memory address of the information storage unit corresponding to the target message identifier is not found in the subscription table, it indicates that the message identified by the target message identifier has not been subscribed to by any message subscription component. In this case, a new information storage unit can be created to cache the subscription information corresponding to the message subscription component that has subscribed to the message identified by the target message identifier. The created information storage unit is the target storage unit. After the information storage unit is created, the memory address of the target storage unit can be obtained.
[0069] According to the memory address of the created target storage unit, a mapping calculation can be performed between the target message identifier and the memory address of the target storage unit, and a mapping relationship between the target message identifier and the memory address of the target storage unit is added to the subscription table. For the first subscription information, it can be added to the created target storage unit.
[0070] Through this embodiment, if there is no memory address of the information storage unit corresponding to the target message identifier in the subscription table, a new information storage unit is created, the subscription information is stored in the created information storage unit, and the new mapping relationship is recorded in the subscription table at the same time, which can ensure the success rate of component subscription messages.
[0071] In an exemplary embodiment, when a memory address of an information storage unit corresponding to a target message identifier is not found in a subscription table, creating an information storage unit to obtain a target storage unit includes:
[0072] S41: When the header address of the information linked list corresponding to the target message identifier is not found in the subscription table, an information linked list is created to obtain a target information linked list.
[0073] In the case where the information storage unit is an information linked list and the memory address of the information storage unit is the header address of the information linked list, if the header address of the information linked list corresponding to the target message identifier is not found in the subscription table, a new information linked list can be created to obtain the header address of the target information linked list. Here, the created information linked list is the target information linked list, which can be used to store the first subscription information and other subscription information corresponding to the target message identifier.
[0074] Optionally, a mapping can be performed between the header address of the created target information linked list and the target message identifier, and the mapping relationship can be recorded in the subscription table. Simultaneously, the first subscription information can be added to the created target information linked list. The first subscription information can be added by adding the node storing the first subscription information to the target information linked list, for example, by pointing to the node storing the first subscription information through a pointer.
[0075] Through this embodiment, by creating an information linked list for storing subscription information, the storage speed of subscription information can be improved, and an information linked list is provided for subsequent subscription information corresponding to the same message identifier.
[0076] In an exemplary embodiment, when a memory address of a target storage unit corresponding to a target message identifier is found in a subscription table and subscription information matching the first subscription information does not exist in the subscription information stored in the target storage unit, adding the first subscription information to the target storage unit includes:
[0077] S51. When the header address of the target information linked list corresponding to the target message identifier is found from the subscription table and there is no subscription information matching the first subscription information among the subscription information stored in all the linked list nodes in the target information linked list, the target node is added to the tail of the target information linked list, wherein the first subscription information is stored in the target node.
[0078] In the case where the information storage unit is an information linked list and the memory address of the information storage unit is the header address of the information linked list, the subscription information stored in all linked list nodes in the target information linked list can be traversed based on the found header address. If the traversed subscription information does not match the first subscription information, it means that there is no duplicate subscription. In this case, the target node can be added to the end of the target information linked list to complete the target information linked list's record of the first subscription information, thereby completing the first component's subscription to the message identified by the target message identifier. Here, the target node can store the first subscription information.
[0079] Optionally, a node for storing the first subscription information, i.e., a target node, may be created, and the first subscription information may be stored in the target node. The target node may be created after receiving the first request message, or after confirming that no subscription information matching the first subscription information exists. In the aforementioned case where the header address of the information linked list corresponding to the target message identifier is not found in the subscription table, after the target information linked list is created, the target node storing the first subscription information may be added to the end of the created target information linked list.
[0080] For example, when a subscriber subscribes to a message with a specified msg_id, the subscription table is checked to see if a linked list header exists. If so, the subscription information is added to the end of the linked list. If not, a new linked list header is created, a mapping relationship is added to the subscription table, and the subscription information is added to the end of the linked list.
[0081] Through this embodiment, by adding a linked list node that caches subscription information at the end of the information linked list, the storage efficiency of the subscription information can be improved.
[0082] In an exemplary embodiment, in response to the acquired message subscription request, after determining the first subscription information corresponding to the first component, the method further includes:
[0083] S61, when the memory address of the target storage unit corresponding to the target message identifier is found from the subscription table, the preset subscription parameters in the first subscription information are matched with the preset subscription parameters in each subscription information stored in the target storage unit, wherein the preset subscription parameters include at least one of the following: a message identifier, a component identifier, a message processing function of the message identified by the message identifier, and a runtime environment for executing the message processing function of the message identified by the message identifier.
[0084] If the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, it can be determined whether any subscription information matching the first subscription information exists in the subscription information stored in the target storage unit. The subscription information matching can be performed based on preset subscription parameters. That is, the preset subscription parameters of the first subscription information can be matched with the preset subscription parameters in each subscription information stored in the target storage unit to determine whether any subscription information matching the first subscription information exists.
[0085] In this embodiment, the preset subscription parameters may be pre-set subscription parameters related to matching the subscription information, which may be all or part of the parameters in the subscription information. The preset subscription parameters may include at least one of the following: a message identifier, a component identifier, a message processing function for the message identified by the message identifier, and a runtime environment for executing the message processing function for the message identified by the message identifier. Here, the meaning of the message processing function is similar to that in the aforementioned embodiment and is not further described here. The runtime environment for executing the message processing function may be an RTE environment, which may or may not exist in the message subscription component.
[0086] Through this embodiment, subscription information matching is performed based on preset subscription parameters, which can avoid the waste of storage resources and repeated message distribution caused by repeated subscriptions, and at the same time, can also improve the efficiency and flexibility of subscription information matching.
[0087] In an exemplary embodiment, the method further includes:
[0088] S71, obtaining a subscription cancellation request from a second component of a target device, wherein the subscription cancellation request is used to request cancellation of subscription to a message identified by a target message identifier;
[0089] S72, in response to the obtained unsubscribe request, determining second subscription information corresponding to the second component;
[0090] S73. When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and subscription information matching the second subscription information exists in the subscription information stored in the target storage unit, the subscription information matching the second subscription information is removed from the target storage unit.
[0091] A component that has subscribed to the message identified by the target message identifier but no longer needs to receive the message identified by the target message identifier for other reasons can unsubscribe from the message identified by the target message identifier by sending an unsubscribe request to the messaging component. A second component that needs to unsubscribe from the message identified by the target message identifier can send an unsubscribe request to the messaging component. Here, the second component can be an independent component to which the target device has subscribed to the target message. The unsubscribe request can be used to request unsubscription from the message identified by the target message identifier and can contain the same content as the message subscription request.
[0092] Here, the messaging component may be configured with an unsubscribe interface for canceling message subscriptions. The message subscription component may call the unsubscribe interface to send the information required to cancel the subscription message (equivalent to passing in a unsubscribe request) to the messaging component to cancel the subscription. For example, the second component may call the unsubscribe interface of the messaging component and pass in information such as a target message identifier for unsubscribing from messages identified by the target message identifier to cancel the subscription to the messages identified by the target message identifier.
[0093] In this embodiment, the messaging component can obtain a cancellation request sent by the second component. Based on the obtained cancellation request, the messaging component can determine the second subscription information corresponding to the second component. The second subscription information can have the same parameters as the first subscription information, and the method of determining the second subscription information is similar to the aforementioned method of determining the first subscription information. At the same time, the second subscription information can also be pre-stored in a section of memory applied for, which has been explained and will not be repeated here. For the second subscription information, the memory address of the information storage unit corresponding to the target message identifier in the subscription table can be searched, and if the memory address of the target storage unit corresponding to the target message identifier is found, it is determined whether there is subscription information matching the second subscription information in the target storage unit. The method of searching the subscription table and determining the subscription information matching the second subscription information is similar to the aforementioned method of searching the subscription table and determining the subscription information matching the first subscription information, and will not be repeated here.
[0094] If the memory address of the target storage unit corresponding to the target message identifier is not found in the subscription table, it means that the subscription information to be canceled does not exist, and the subscription information cancellation process can be ended. If the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, and the subscription information stored in the target storage unit does not contain subscription information that matches the second subscription information, the subscription information cancellation process can be ended. If the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, and the subscription information stored in the target storage unit contains subscription information that matches the second subscription information, the subscription information that matches the second subscription information can be removed from the target storage unit, thereby completing the second component's cancellation of subscription to the message identified by the target message identifier.
[0095] Through this embodiment, the memory address of the corresponding information storage unit in the subscription table is found through the message identifier, and the subscription information matching the subscription message requested to be canceled in the found information storage unit is removed to complete the message unsubscription, thereby improving the accuracy of the message unsubscription.
[0096] In an exemplary embodiment, when a memory address of a target storage unit corresponding to a target message identifier is found in a subscription table, and subscription information matching the second subscription information exists in subscription information stored in the target storage unit, removing the subscription information matching the second subscription information from the target storage unit includes:
[0097] S81, when the header address of the target information linked list corresponding to the target message identifier is found from the subscription table and the subscription information stored in the target linked list node in the target information linked list matches the second subscription information, the target linked list node is deleted from the target information linked list and the memory resources occupied by the target linked list node are released.
[0098] In the case where the information storage unit is an information linked list and the memory address of the information storage unit is the header address of the information linked list, the process of removing the subscription information matching the second subscription information from the target storage unit can be: deleting the linked list node storing the subscription information matching the second subscription information from the target information linked list, and releasing the memory resources occupied by the linked list node.
[0099] In this embodiment, if the header address of the target information linked list corresponding to the target message identifier is found from the subscription table, and the subscription information stored in the target linked list node in the target information linked list matches the second subscription information, the target linked list node can be deleted from the target information linked list and the memory resources occupied by the target linked list node can be released.
[0100] For example, when canceling a subscription with a msg_id, the subscription table is searched for a linked list header mapping based on the msg_id. If so, the linked list is traversed and the node storing the matching subscription is compared with the one to be canceled. If a match is found, the linked list node storing the matching subscription is deleted from the linked list and the associated memory is released.
[0101] Through this embodiment, by deleting the linked list node storing the corresponding subscription information in the information linked list and releasing the memory resources occupied by the linked list node, the rationality of memory resource utilization can be improved.
[0102] In an exemplary embodiment, after removing the subscription information matching the second subscription information from the target storage unit, the method further includes:
[0103] S91: When the subscription information stored in the target storage unit is empty, the mapping relationship between the target message identifier and the memory address of the target storage unit is deleted from the subscription table.
[0104] When a second component receives an unsubscribe request, if the message identified by the target message identifier has only been subscribed to by the second component, then after the subscription information matching the second subscription information is removed from the target storage unit, the subscription information stored in the target storage unit becomes empty. If the target storage unit is a target information linked list, it can be determined after the target linked list node that if the depth of the target information linked list is 0, it indicates that there is no remaining subscription information in the target information linked list; otherwise, it is determined that there is remaining subscription information in the target information linked list.
[0105] In this embodiment, if the subscription information stored in the target storage unit is empty, the mapping relationship between the target message identifier and the memory address of the target storage unit can be deleted from the subscription table to reduce the resource usage of the subscription table by deleting useless mapping relationships.
[0106] According to this embodiment, when there is no other subscription information in the storage unit after the corresponding subscription information is removed, the corresponding mapping relationship in the subscription table is deleted, which can improve the utilization rate of the storage resources in the subscription table.
[0107] The following is an explanation of the message transmission method between components in the embodiment of the present application with reference to an optional example. In this optional example, the information storage unit is an information linked list, the message publishing component is the publisher, the message transmission component is the publish-subscribe component, the message subscription component is the subscriber, and the message is represented by msg_id.
[0108] Currently, for the distribution and transmission of messages between multiple components within a system based on a subscription-based publishing approach, to improve the efficiency of information acquisition, this optional example provides a low-resource memory management solution that can reduce the memory occupied by the subscription table and shorten the time it takes to search for subscription information. Optionally, the process of the inter-component message transmission method in this optional example may include the following steps:
[0109] Step 1: Add subscribers with the same msg_id to the same linked list, use the address of the linked list head as the value and perform hash mapping on the msg_id, and record the mapping relationship in the subscription table.
[0110] Step 2: When publishing msg_id, search the subscription table to see if there is a mapping relationship with the linked list header based on msg_id. If there is, traverse the linked list and distribute the message to be published to each subscriber.
[0111] Step 3: When a subscriber subscribes to a msg_id, the subscription table is searched for a managed linked list header based on the msg_id. If so, the subscription information is added to the end of the linked list. If not, a new linked list header is created, a mapping relationship is added to the subscription table, and the subscription information is added to the end of the linked list.
[0112] Step 4: When unsubscribing from msg_id, search the subscription table to see if there is a mapping relationship with the linked list header based on msg_id. If there is, traverse the linked list and compare it with the information to be unsubscribed. If a match is successful, delete the node from the linked list and release the associated memory information.
[0113] Through this optional example, the information of multiple subscribers who subscribe to the same msg_id is managed using a linked list. The subscription table only stores the mapping relationship between the message identifier and the linked list header. This can reduce the memory resources occupied by the subscription table, shorten the time to find subscription information, and improve the efficiency of information acquisition.
[0114] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.
[0115] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory, Read-Only Memory) / RAM (Random Access Memory, Random Access Memory), a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.
[0116] According to another aspect of the embodiments of the present application, an inter-component message transmission device for implementing the above-mentioned inter-component message transmission method is also provided. Figure 4 This is a structural block diagram of an optional inter-component message transmission device according to an embodiment of the present application, such as Figure 4 As shown, the device may include:
[0117] A first acquiring unit 402 is configured to acquire, through a message delivery component of the target device, a target message published by a message publishing component of the target device, wherein the message delivery component is configured to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier;
[0118] a search unit 404 connected to the first acquisition unit 402, and configured to search a subscription table according to the target message identifier in response to the acquired target message, wherein the subscription table is configured to record a mapping relationship between a message identifier of a subscribed message and a memory address of an information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is configured to store subscription information corresponding to a message subscription component of the subscribed message;
[0119] The delivery unit 406 is connected to the search unit 404 and is used to deliver the target message to the message subscription component corresponding to the subscription information stored in the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table.
[0120] It should be noted that the first acquiring unit 402 in this embodiment can be used to execute the above step S202, the searching unit 404 in this embodiment can be used to execute the above step S204, and the transmitting unit 406 in this embodiment can be used to execute the above step S206.
[0121] Through the above module, the message delivery component of the target device obtains the target message published by the message publishing component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier; in response to the acquired target message, the subscription table is searched according to the target message identifier, wherein the subscription table is used to record the mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store the subscription information corresponding to the message subscription component of the subscribed message; when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit, thereby solving the problem of low efficiency of information acquisition due to the large storage resources occupied by the subscription table in the message delivery method between components in the related art, thereby improving the efficiency of information acquisition.
[0122] In one exemplary embodiment, the transfer unit comprises:
[0123] a traversal module, configured to, upon finding a header address of a target information linked list corresponding to a target message identifier in a subscription table, traverse each linked list node in the target information linked list according to the header address of the target information linked list, wherein each linked list node stores subscription information corresponding to a message subscription component of a message identified by the target message identifier;
[0124] The delivery module is used to deliver the target message to the message subscription component corresponding to the subscription information stored in each traversed linked list node.
[0125] In an exemplary embodiment, the apparatus further comprises:
[0126] A second acquiring unit is configured to acquire a message subscription request of the first component of the target device, wherein the message subscription request is used to request subscription to a message identified by a target message identifier in a message published to the messaging component of the target device;
[0127] A first determining unit, configured to determine first subscription information corresponding to the first component in response to the acquired message subscription request;
[0128] The first adding unit is used to add the first subscription information to the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and there is no subscription information matching the first subscription information in the subscription information stored in the target storage unit.
[0129] In an exemplary embodiment, the apparatus further comprises:
[0130] a creating unit configured to, after determining the first subscription information corresponding to the first component in response to the acquired message subscription request, create an information storage unit to obtain a target storage unit if the memory address of the information storage unit corresponding to the target message identifier is not found in the subscription table;
[0131] The second adding unit is configured to add a mapping relationship between the target message identifier and the memory address of the target storage unit in the subscription table, and add the first subscription information to the target storage unit.
[0132] In one exemplary embodiment, the creating unit includes:
[0133] The creation module is used to create an information chain table to obtain a target information chain table when the header address of the information chain table corresponding to the target message identifier is not found in the subscription table.
[0134] In an exemplary embodiment, the first adding unit includes:
[0135] An adding module is used to add a target node to the tail of the target information linked list when a header address of a target information linked list corresponding to a target message identifier is found in a subscription table and subscription information matching the first subscription information does not exist in the subscription information stored in all the linked list nodes in the target information linked list, wherein the target node stores the first subscription information.
[0136] In an exemplary embodiment, the apparatus further comprises:
[0137] A matching unit is used to, after determining the first subscription information corresponding to the first component in response to the acquired message subscription request, match the preset subscription parameters in the first subscription information with the preset subscription parameters in each subscription information stored in the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found from the subscription table, wherein the preset subscription parameters include at least one of the following: a message identifier, a component identifier, a message processing function of the message identified by the message identifier, and a runtime environment for executing the message processing function of the message identified by the message identifier.
[0138] In an exemplary embodiment, the apparatus further comprises:
[0139] A third obtaining unit is configured to obtain a subscription cancellation request from the second component of the target device, wherein the subscription cancellation request is used to request cancellation of subscription to a message identified by the target message identifier;
[0140] A second determining unit, configured to determine, in response to the obtained unsubscribe request, second subscription information corresponding to the second component;
[0141] A removal unit is used to remove the subscription information matching the second subscription information from the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and the subscription information stored in the target storage unit contains subscription information matching the second subscription information.
[0142] In one exemplary embodiment, the removal unit comprises:
[0143] An execution module is used to delete the target linked list node from the target information linked list and release the memory resources occupied by the target linked list node when a header address of the target information linked list corresponding to the target message identifier is found in the subscription table and the subscription information stored in the target linked list node in the target information linked list matches the subscription information of the second subscription information.
[0144] In an exemplary embodiment, the apparatus further comprises:
[0145] The deleting unit is used to delete the mapping relationship between the target message identifier and the memory address of the target storage unit from the subscription table after removing the subscription information matching the second subscription information from the target storage unit and when the subscription information stored in the target storage unit is empty.
[0146] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. Figure 1 The hardware environment shown can be implemented through software or hardware, wherein the hardware environment includes a network environment.
[0147] According to another aspect of the embodiments of the present application, a storage medium is further provided. Optionally, in this embodiment, the storage medium can be used to execute the program code of any of the above-mentioned inter-component message transmission methods in the embodiments of the present application.
[0148] Optionally, in this embodiment, the above-mentioned storage medium may be located on at least one network device among the multiple network devices in the network shown in the above-mentioned embodiment.
[0149] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:
[0150] S1, obtaining a target message published by a message publishing component of the target device through a message delivery component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier;
[0151] S2, in response to the acquired target message, searching a subscription table according to the target message identifier, wherein the subscription table is used to record a mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store subscription information corresponding to the message subscription component of the subscribed message;
[0152] S3. When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit.
[0153] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, which will not be described in detail in this embodiment.
[0154] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.
[0155] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned message transmission method between components is also provided. The electronic device can be a server, a terminal, or a combination thereof.
[0156] Figure 5 is a structural block diagram of an optional electronic device according to an embodiment of the present application, such as Figure 5 As shown, it includes a processor 502, a communication interface 504, a memory 506 and a communication bus 508, wherein the processor 502, the communication interface 504 and the memory 506 communicate with each other through the communication bus 508, wherein,
[0157] Memory 506, for storing computer programs;
[0158] The processor 502 is configured to execute the computer program stored in the memory 506 to implement the following steps:
[0159] S1, obtaining a target message published by a message publishing component of the target device through a message delivery component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier;
[0160] S2, in response to the acquired target message, searching a subscription table according to the target message identifier, wherein the subscription table is used to record a mapping relationship between the message identifier of the subscribed message and the memory address of the information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store subscription information corresponding to the message subscription component of the subscribed message;
[0161] S3. When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit.
[0162] Optionally, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 The communication interface is used for communication between the electronic device and other devices.
[0163] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Alternatively, the memory may also be at least one storage device located away from the aforementioned processor.
[0164] As an example, the memory 506 may include, but is not limited to, the first acquisition unit 402, search unit 404, and transfer unit 406 in the inter-component message transfer apparatus. Furthermore, it may also include, but is not limited to, other module units in the inter-component message transfer apparatus, which will not be described in detail in this example.
[0165] The above-mentioned processor can be a general-purpose processor, including but not limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0166] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0167] It can be understood by those skilled in the art that Figure 5 The structure shown is for illustration only. The device for implementing the message transmission method between the above components may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 5 It does not limit the structure of the above electronic device. For example, the electronic device may also include Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or with Figure 5 Different configurations shown.
[0168] A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.
[0169] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0170] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in each embodiment of the present application.
[0171] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0172] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, and can be electrical or other forms.
[0173] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected based on actual needs to achieve the purpose of the solution provided in this embodiment.
[0174] In addition, the functional units in the various embodiments of the present application may be integrated into a processing unit, or each unit may exist physically separately, or at least two units may be integrated into a single unit. The above-mentioned integrated units may be implemented in the form of hardware or software functional units.
[0175] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for message transmission between components, characterized in that: include: Acquiring, through a message delivery component of the target device, a target message published by a message publishing component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier; In response to the acquired target message, searching a subscription table according to the target message identifier, wherein the subscription table is used to record a mapping relationship between a message identifier of a subscribed message and a memory address of an information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is used to store subscription information corresponding to a message subscription component of the subscribed message; When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit; Wherein, when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, the target message is delivered to the message subscription component corresponding to the subscription information stored in the target storage unit, including: When a header address of a target information linked list corresponding to the target message identifier is found in the subscription table, traversing each linked list node in the target information linked list according to the header address of the target information linked list, wherein each linked list node stores subscription information corresponding to a message subscription component of the message identified by the target message identifier; The target message is delivered to the message subscription component corresponding to the subscription information stored in each traversed linked list node.
2. The method according to claim 1, characterized in that The method further comprises: Obtaining a message subscription request of a first component of the target device, wherein the message subscription request is used to request subscription to a message published to a messaging component of the target device, the message identified by the target message identifier; In response to the obtained message subscription request, determining first subscription information corresponding to the first component; When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and no subscription information matching the first subscription information exists in the subscription information stored in the target storage unit, the first subscription information is added to the target storage unit.
3. The method according to claim 2, characterized in that After determining the first subscription information corresponding to the first component in response to the acquired message subscription request, the method further includes: In the case that the memory address of the information storage unit corresponding to the target message identifier is not found in the subscription table, creating an information storage unit to obtain the target storage unit; A mapping relationship between the target message identifier and the memory address of the target storage unit is added to the subscription table, and the first subscription information is added to the target storage unit.
4. The method according to claim 3, characterized in that The step of creating an information storage unit to obtain the target storage unit when the memory address of the information storage unit corresponding to the target message identifier is not found in the subscription table includes: In the case that the header address of the information linked list corresponding to the target message identifier is not found in the subscription table, an information linked list is created to obtain the target information linked list.
5. The method according to claim 2, characterized in that The step of adding the first subscription information to the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and no subscription information matching the first subscription information exists in the subscription information stored in the target storage unit, comprises: When the header address of the target information linked list corresponding to the target message identifier is found from the subscription table and there is no subscription information matching the first subscription information among the subscription information stored in all the linked list nodes in the target information linked list, the target node is added to the tail of the target information linked list, wherein the first subscription information is stored in the target node.
6. The method according to claim 2, characterized in that After determining the first subscription information corresponding to the first component in response to the acquired message subscription request, the method further includes: When the memory address of the target storage unit corresponding to the target message identifier is found from the subscription table, the preset subscription parameters in the first subscription information are matched with the preset subscription parameters in each subscription information stored in the target storage unit, wherein the preset subscription parameters include at least one of the following: a message identifier, a component identifier, a message processing function of the message identified by the message identifier, and a runtime environment for executing the message processing function of the message identified by the message identifier.
7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: Obtaining a subscription cancellation request of a second component of the target device, wherein the subscription cancellation request is used to request cancellation of subscription to a message identified by the target message identifier; In response to the obtained unsubscribe request, determining second subscription information corresponding to the second component; When the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table, and subscription information matching the second subscription information exists in the subscription information stored in the target storage unit, the subscription information matching the second subscription information is removed from the target storage unit.
8. The method according to claim 7, characterized in that The step of removing the subscription information matching the second subscription information from the target storage unit when the memory address of the target storage unit corresponding to the target message identifier is found in the subscription table and subscription information matching the second subscription information exists in the subscription information stored in the target storage unit includes: When the header address of the target information linked list corresponding to the target message identifier is found in the subscription table, and the subscription information stored in the target linked list node in the target information linked list matches the second subscription information, the target linked list node is deleted from the target information linked list and the memory resources occupied by the target linked list node are released.
9. The method according to claim 7, characterized in that After removing the subscription information matching the second subscription information from the target storage unit, the method further includes: In a case where the subscription information stored in the target storage unit is empty, the mapping relationship between the target message identifier and the memory address of the target storage unit is deleted from the subscription table.
10. A message transmission device between components, characterized in that: include: A first acquiring unit is configured to acquire, through a message delivery component of a target device, a target message published by a message publishing component of the target device, wherein the message delivery component is configured to deliver messages between different components of the target device, and the target message is a message identified by a target message identifier; a search unit, configured to search a subscription table according to the target message identifier in response to the acquired target message, wherein the subscription table is configured to record a mapping relationship between a message identifier of a subscribed message and a memory address of an information storage unit corresponding to the message identifier of the subscribed message, and the information storage unit corresponding to the message identifier of the subscribed message is configured to store subscription information corresponding to a message subscription component of the subscribed message; a delivery unit configured to deliver the target message to a message subscription component corresponding to the subscription information stored in the target storage unit when a memory address of the target storage unit corresponding to the target message identifier is found in the subscription table; In which, the transmission unit is also used to traverse each linked list node in the target information linked list according to the header address of the target information linked list when the header address of the target information linked list corresponding to the target message identifier is found in the subscription table, wherein each linked list node stores subscription information corresponding to a message subscription component of the message identified by the target message identifier; and pass the target message to the message subscription component corresponding to the subscription information stored in each linked list node traversed.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method according to any one of claims 1 to 9 when executed.
12. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 9 through the computer program.
Citation Information
Patent Citations
Apparatus and method for implementing communication between components of single process
CN101315609A
Data storage and forwarding method, electronic equipment and storage medium
CN109491617A