Method and device for message transmission between components, storage medium and electronic device

By introducing a message passing component between components, decoupling between components is achieved, which solves the problem of complexity in pruning caused by high coupling between components, and improves the ease of component pruning and message passing efficiency.

CN115766317BActive Publication Date: 2025-08-22HAIER YOUJIA INTELLIGENT TECH (BEIJING) CO LTD +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211350471.6
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

Technical Problem

The high coupling between components leads to high complexity in component pruning.

Method used

By introducing a message passing component, the decoupling between the message publisher and receiver is achieved. The message passing component is used for message distribution and transmission, reducing the coupling between components.

Benefits of technology

It reduces the complexity of component trimming and improves the independence between components and the efficiency of message passing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115766317B_ABST
    Figure CN115766317B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for message transmission between components, a storage medium and an electronic device, and relates to the field of smart home / intelligent home technology, wherein the method comprises: obtaining a target message published by a first component of the target device through a message transmission component of the target device, wherein the message transmission component is used to transmit messages between different components of the target device; in response to the obtained target message, determining the component in the target device that subscribes to the target message according to the message identifier of the target message; and in the case of determining that a second component in the target device subscribes to the target message, transmitting the target message to the second component through the message transmission component. Through the present application, the problem of high complexity of component tailoring caused by high coupling between components in the message transmission method between components in the related art is solved.
Need to check novelty before this filing date? Find Prior Art

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] Currently, in the embedded system field, data transmission is typically carried out along existing channels, and message distribution and delivery are implemented within the system. The channels used are usually message queues. For example, when two independent components (such as business components) communicate with each other, each component creates its own message queue and provides an interface for writing to its own message queue (i.e., a write message interface and a write message queue interface) to implement message transmission between the two components.

[0003] However, in the above-mentioned message passing method between components, when performing message passing, the message publisher needs to pay attention to the interface code of the message receiver. The coupling between components is relatively high. Tailoring a component requires simultaneously updating the component that calls the interface of the component to write messages, resulting in a high complexity in component tailoring.

[0004] It can be seen that the message transmission method between components in the related art has the problem of high complexity of component tailoring due to the high coupling between components. 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 high complexity of component tailoring caused by high coupling between components 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 passing between components is provided, including: obtaining a target message published by a first component of a target device through a message passing component of the target device, wherein the message passing component is used to pass messages between different components of the target device; in response to the obtained target message, determining a component in the target device that subscribes to the target message based on a message identifier of the target message; and when it is determined that a second component in the target device has subscribed to the target message, passing the target message to the second component through the message passing component.

[0007] In an exemplary embodiment, the method further includes: obtaining a message subscription request of the second component through the messaging component, wherein the message subscription request carries a group of message identifiers to be subscribed, and the group of message identifiers includes the message identifier of the target message; in response to the obtained message subscription request, saving the message subscription relationship between the second component and the message identified by each message identifier in the group of message identifiers.

[0008] In an exemplary embodiment, obtaining the target message published by the first component of the target device through the messaging component of the target device includes: obtaining, through the messaging component of the target device, the target message published by the first component of the target device by calling the message publishing interface of the message subscription component.

[0009] In an exemplary embodiment, when it is determined that a second component in the target device has subscribed to the target message, the target message is passed to the second component through the messaging component, including: when it is determined that multiple components in the target device have subscribed to the target message, the target message is passed to each of the multiple components in turn through the messaging component, wherein the second component includes the multiple components.

[0010] In an exemplary embodiment, after the target message is passed to the second component through the messaging component, the method further includes: determining the publishing result of the target message through the messaging component within a preset time, wherein the publishing result of the target message is the result of publishing the target message to the multiple components; and feeding back the publishing result of the target message to the first component through the messaging component.

[0011] In an exemplary embodiment, after the target message is delivered to each of the multiple components in sequence through the message delivery component, the method further includes: in the event that distribution of the target message to the target component among the multiple components fails, re-delivering the target message to the target component through the message delivery component.

[0012] In an exemplary embodiment, the method further includes: if it is determined that no component in the target device has subscribed to the target message, releasing memory resources corresponding to publishing the target message and ending the publishing of the target message.

[0013] According to another aspect of an embodiment of the present application, a message passing device between components is also provided, including: a first acquisition unit, used to obtain a target message published by a first component of the target device through a message passing component of the target device, wherein the message passing component is used to pass messages between different components of the target device; a first determination unit, used to determine, in response to the acquired target message, the component in the target device that subscribes to the target message according to the message identifier of the target message; a first delivery unit, used to distribute the target message to the second component in the target device through the message passing component when it is determined that the second component in the target device has subscribed to the target message.

[0014] In an exemplary embodiment, the apparatus further includes: a second acquiring unit, configured to acquire, through the message delivery component, a message subscription request of the second component, wherein the message subscription request carries a group of message identifiers to be subscribed, the group of message identifiers including the message identifier of the target message;

[0015] A saving unit is used to save the message subscription relationship between the second component and the message identified by each message identifier in the group of message identifiers in response to the acquired message subscription request.

[0016] In an exemplary embodiment, the first acquiring unit includes: an acquiring module, configured to acquire, through the message delivery component of the target device, the target message published by the first component of the target device by calling a message publishing interface of the message subscription component.

[0017] In an exemplary embodiment, the first delivery unit includes: a delivery module for delivering the target message to each of the multiple components in sequence through the message delivery component when it is determined that multiple components in the target device have subscribed to the target message, wherein the second component includes the multiple components.

[0018] In an exemplary embodiment, the device also includes: a second determination unit, used to determine the publication result of the target message through the message passing component within a preset time after the target message is passed to the second component through the message passing component, wherein the publication result of the target message is the result of publishing the target message to the multiple components; a feedback unit, used to feed back the publication result of the target message to the first component through the message passing component.

[0019] In an exemplary embodiment, the device also includes: a second delivery unit, which is used to, after the target message is delivered to each of the multiple components in sequence through the message delivery component, re-deliver the target message to the target component through the message delivery component in the event that delivery of the target message to the target component among the multiple components fails.

[0020] In an exemplary embodiment, the apparatus further includes: an execution unit configured to release memory resources corresponding to publishing the target message and end publishing of the target message when it is determined that no component in the target device has subscribed to the target message.

[0021] 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.

[0022] 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.

[0023] In an embodiment of the present application, a method of adding a message passing component agent to execute message distribution and delivery is adopted, and the target message published by the first component of the target device is obtained through the message passing component of the target device, wherein the message passing component is used to deliver messages between different components of the target device; in response to the obtained target message, the component in the target device that subscribes to the target message is determined according to the message identifier of the target message; when it is determined that the second component in the target device has subscribed to the target message, the target message is delivered to the second component through the message passing component. Since the message publishing end (such as the first component) only needs to publish the target message to the message passing component and does not need to pay attention to the interface code of the message receiving end (such as the second component) that receives the target message, the purpose of reducing the coupling between components can be achieved. The component can be tailored without updating the component that calls the interface of the component to write the message, thereby achieving the technical effect of reducing the complexity of component tailoring, thereby solving the problem of high complexity of component tailoring caused by high coupling between components in the message passing method between components in the related art. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] 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.

[0025] 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.

[0026] 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;

[0027] Figure 2 This is a flow chart of an optional method for message transmission between components according to an embodiment of the present application;

[0028] Figure 3 is a schematic diagram of an optional method for message transmission between components according to an embodiment of the present application;

[0029] Figure 4 This is a structural block diagram of an optional inter-component message transmission device according to an embodiment of the present application;

[0030] Figure 5 This is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0031] 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.

[0032] 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.

[0033] 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.

[0034] 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, and the like.

[0035] 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.

[0036] 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:

[0037] Step S202: Acquire a target message published by a first 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.

[0038] The message transmission method between components in this embodiment can be applied to the scenario of message distribution and transmission between different components inside the target device. The operating system running on the target device here can be an operating system of an embedded system, which can include non-real-time operating systems and real-time operating systems, for example, the ecological operating system of a smart home in the smart home field. The embedded system can include hardware and software parts. The operating system of the embedded system can have the core functions of a general operating system and be responsible for the allocation of all software and hardware 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.

[0039] In the embedded system field, internal message distribution and transmission typically uses existing channels to transmit data, such as local sockets (interfaces for local network communication) and message queues. For example, using message queues to distribute and transmit messages between two independent business modules (e.g., components, which can be business components) within the system, Module 1 and Module 2 must meet the following requirements: each module has its own message queue and a locking mechanism that ensures the atomicity of read and write operations; each module provides an external interface for writing to the message queue (i.e., a write message queue interface) that allows the other module to write to its own message queue by calling this interface. The write message queue interface is protected by locking for atomic operations; and each module has a polling mechanism (equivalent to a timer, used to wake up a process) that cyclically reads its own queue. If a message is written, it reads the message and processes it. Module 1 can send messages to Module 2 by calling Module 2's write message queue interface.

[0040] However, in the above-mentioned message transmission method between components, the message publishing end (component 1) needs to call the message receiving end (module 2)'s write message queue interface to send messages to the message receiving end. Therefore, it is necessary to pay attention to the interface code of the message receiving end. The coupling degree between components is high, and it is impossible to achieve complete independence between components (that is, there is no coupling relationship between components). Due to the coupling relationship between components, trimming a component requires simultaneously updating the component that calls the component's write message queue interface, resulting in a high complexity in component trimming. For example, if component 2 is trimmed based on business scenario requirements (that is, the corresponding overall solution does not require component 2, and component 2 is completely deleted), component 1 cannot be compiled because there is an interface reference to component 2 in component 1.

[0041] To at least partially address the above-mentioned issues, in this embodiment, a messaging component can be provided to implement message distribution and delivery between a message publisher and a message receiver. The message publisher and the message receiver do not need to pay attention to each other's interface information, but only to the corresponding interface of the messaging component to implement message publishing and reception. This allows for complete independence in message delivery between the message publisher and the message receiver (i.e., complete decoupling between components), and further enables arbitrary component customization. Here, the message publisher can be a message publisher of a specific message type, and the message subscriber (i.e., the message receiver) can be a message receiver of a specific message type or a subscriber of a specific message type. The message receiver can be an independent component or a component that relies on a certain RTE (Run-Time Environment) environment. An RTE environment refers to a specific, independent context environment in which a piece of code is to be executed, equivalent to an independent thread.

[0042] The messaging component, also known as the message broker or publish-subscribe component, is distinct from the message publisher and message receiver. When a message is published to the messaging component during a message broker publishing operation, the messaging component retrieves the message type and sends it to the RTE environment for execution. If an RTE environment is not available, the messaging component can directly execute the callback function registered by the message receiver. When subscribing to messages, the 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 publisher can publish messages by calling the message publishing interface provided by the publish-subscribe component. This publishes the message to be published to the messaging component, which then completes the distribution and message delivery process.

[0043] In this embodiment, the target device may include a messaging component, a first component, and a second component. The first component and the second component may be different business components of the target device. The first component may serve as a message publisher to publish a target message (i.e., a published message) to the messaging component. The target message may be published to the messaging component by the first component by calling the message publishing interface of the messaging component. The messaging component may obtain the target message published by the first component. The target message may be a message of a specific message type sent by the first component, which may be used to trigger the message receiving end to execute a corresponding business.

[0044] Step S204 : In response to the acquired target message, a component in the target device that subscribes to the target message is determined according to the message identifier of the target message.

[0045] Message delivery can be performed based on message identifiers within the system, that is, the message delivery component can distribute and deliver messages based on message identifiers. The components on the target device can subscribe to the messages of interest through the message identifiers. In order to facilitate the message delivery component to deliver messages, message subscription information can be saved in advance. The message subscription information here is used to characterize the component that subscribes to the message identified by the message identifier through the correspondence between the message identifier and the component identifier, which can be achieved by saving the correspondence between the message identifier and the component identifier. The above-mentioned message subscription information can be saved in the message delivery component, or in other storage resources outside the message delivery component, but the address information of the corresponding storage resource can be saved in the message delivery component to ensure that the message delivery component can search for the saved message subscription information.

[0046] After obtaining the target message, the messaging component can determine the component in the target device that subscribes to the target message, i.e., the message subscriber of the target message, based on the message identifier of the target message. Here, the message identifier can be a message ID (Identity document), which can be a message event number defined according to specific business logic requirements. The component in the target device that subscribes to the target message can be determined by using the message identifier of the target message to search for saved message subscription information. If a component identifier corresponding to the message identifier of the target message is found, the component identified by the found component identifier can be determined as the component that subscribes to the target message, i.e., the message subscriber component.

[0047] Step S206: When it is determined that the second component in the target device has subscribed to the target message, the target message is delivered to the second component through the message delivery component.

[0048] The target device may have one or more components subscribed to the target message, or no component may have subscribed to the target message. If no component has subscribed to the target message, the messaging component may not perform any operation and directly ignore the target message, or may return an indication to the first component indicating that no component has subscribed to the target message (i.e., the target message has no subscribers).

[0049] In the case where one or more components have subscribed to the target message, for example, if it is determined that a second component in the target device has subscribed to the target message, the messaging component may deliver (i.e., distribute) the target message to the second component. The second component may include one or more components. In the case where the second component includes multiple components, the messaging component may deliver the target message to each component separately. The process of distributing the target message to different components may be performed in parallel or serially (i.e., the target message is delivered to each component in sequence), which is not limited in this embodiment.

[0050] For example, take component 1 as the message publisher, components 2 / 3 / ..n as the message subscribers, and call the components that implement message distribution and delivery based on subscription and publishing as publish-subscribe components. In a one-to-many multicast scenario, such as Figure 3 As shown in the figure, if components 2 / 3 / … / n all follow message id_1, then components 2 / 3 / … / n all subscribe to message id_1 from the publish / subscribe component. When a message with id id_1 is published, the publish / subscribe component publishes the message to components 2 / 3 / … / n that have subscribed to the message based on message id_1.

[0051] When distributing the target message to the second component, if an RTE environment exists, the RTE environment can perform the target message distribution. If not, the messaging component can directly perform the target message distribution. Furthermore, while the RTE environment is distributing the target message, the messaging component can perform other operations, such as receiving messages published by other components and determining the component that subscribes to the message based on the message identifier corresponding to the message.

[0052] It should be noted that, when performing message delivery, the message delivery component can deliver the message to be published (eg, target message) to the message subscription component by executing the callback function registered by the message subscription component. The callback function can be the above-mentioned message processing function.

[0053] Through the above steps S202 to S206, the target message published by the first component of the target device is obtained through the message passing component of the target device, wherein the message passing component is used to pass messages between different components of the target device; in response to the obtained target message, the component in the target device that subscribes to the target message is determined according to the message identifier of the target message; when it is determined that the second component in the target device has subscribed to the target message, the target message is passed to the second component through the message passing component, which solves the problem of high complexity of component tailoring due to the high degree of coupling between components in the message passing method between components in the related art, and reduces the complexity of component tailoring.

[0054] In an exemplary embodiment, the method further includes:

[0055] S11, obtaining a message subscription request from the second component through the message delivery component, wherein the message subscription request carries a group of message identifiers to be subscribed, and the group of message identifiers includes a message identifier of a target message;

[0056] S12: In response to the acquired message subscription request, save, according to each message identifier in a group of message identifiers, a message subscription relationship between the second component and the message identified by each message identifier.

[0057] Message subscription can be triggered by a component with subscription requirements sending a message subscription request to a messaging component. To facilitate the issuance and retrieval of message subscription requests, a message subscription interface for message subscription can be configured for the messaging component. The issuance of a message subscription request can be completed by the component with subscription requirements calling the above message subscription interface, while the retrieval of a message subscription request can be completed by the messaging component through the above message subscription interface. By configuring the above message subscription interface on the messaging component, the message receiving end does not need to pay attention to the information of the message publishing end. It only needs to inform the messaging component of the message identifier corresponding to the message to be subscribed to complete the message subscription.

[0058] In this embodiment, when a second component needs to subscribe to a message identified by a target message identifier (i.e., the message identifier of a target message), the second component can send a message subscription request to the messaging component through the message subscription interface of the messaging component to request to subscribe to the message identified by the target message identifier. The message subscription request carries the target message identifier to be subscribed. The messaging component can obtain the message subscription request from the second component through the message subscription interface and, in response to the received message subscription request, save the message subscription relationship between the second component and the message identified by the target message identifier according to the target message identifier.

[0059] It should be noted that when sending a message subscription request to the messaging component through the message subscription interface, the message subscription component can pass the information required to subscribe to the message to the messaging component by calling the message subscription interface. For example, when it is necessary to subscribe to the message identified by the target message identifier, the second component can pass the target message identifier and other necessary information (for example, RTE environment, message processing function, parameters of the message processing function, etc.) to the messaging component by calling the message subscription interface to realize the subscription to the message identified by the target message identifier.

[0060] To improve the efficiency of message subscriptions, a message subscription request can be used to request subscription to messages identified by each message identifier in a set of message identifiers. The set of message identifiers may include a target message identifier and other message identifiers. Correspondingly, after receiving the message subscription request, the messaging component can save, for each message identifier, a message subscription relationship between the second component and the message identified by each message identifier in response to the received message subscription request.

[0061] The message subscription relationship between the second component and the message identified by each message identifier can be saved as the aforementioned message subscription information. The message subscription information can be stored in one or more specific data structures, such as a subscription table, a linked list, etc. To improve storage resource utilization and avoid duplicate message distribution, before saving a message subscription relationship corresponding to a message identified by a certain message identifier, a search can be performed on the saved message subscription relationships to determine whether a message subscription relationship between the messages identified by the message identifier already exists. If so, the message subscription relationship will not be saved again. If not, the aforementioned message subscription relationship can be saved.

[0062] It's important to note that before receiving the actual message, the messaging component doesn't know the specific messages that need to be distributed to each component. It only uses the message subscription relationships to determine which components subscribe to the messages identified by the message identifiers. For example, before receiving the target message, the messaging component only knows that the second component has subscribed to the message identified by the target message identifier. Only after receiving the target message does the messaging component know that the target message is the message to which the second component has subscribed.

[0063] For example, Figure 3 As shown, component 2 subscribes to the message id_1 (which can be a certain message id) that it is concerned about through the message subscription interface provided by the publish-subscribe component.

[0064] Through this embodiment, the message identified by each message identifier in a group of message identifiers is subscribed to through the same message subscription request, which can improve the efficiency of message subscription.

[0065] In an exemplary embodiment, receiving, by a message delivery component of a target device, a target message published by a first component of a target device includes:

[0066] S21: Acquire, through the message delivery component of the target device, a target message published by the first component of the target device by calling the message publishing interface of the message subscription component.

[0067] Components publish messages to messaging components by calling the message publishing interface on the messaging component. By setting up the message publishing interface on the messaging component, components on target devices that need to publish messages can do so by calling the message publishing interface, without having to worry about the components that subscribe to the messages being published.

[0068] In this embodiment, the first component may publish the target message to the messaging component through the message publishing interface of the messaging component, and the messaging component may obtain the target message published by the first component through the message publishing interface.

[0069] For example, Figure 3 As shown, when component 1 needs to publish message id_1, it can complete the message publishing by calling the publish-subscribe component's message publishing interface. The publish-subscribe component retrieves the subscription information for message id_1 and publishes the message published by the message publisher to the associated message subscriber. In this way, the message publisher does not need to worry about the existence of the message subscriber. Instead, it only needs to publish the message to the message broker (i.e., the publish-subscribe component).

[0070] According to this embodiment, by calling the message publishing interface to publish the message from the message publishing end to the message delivery component, the coupling between components can be reduced and the efficiency of message publishing can be improved.

[0071] In an exemplary embodiment, when it is determined that a second component in a target device has subscribed to a target message, delivering the target message to the second component through a message delivery component includes:

[0072] S31 , when it is determined that multiple components in the target device have subscribed to the target message, deliver the target message to each component in the multiple components in sequence through the message delivery component, wherein the second component includes multiple components.

[0073] In the related art, messages are delivered within the system in a point-to-point unicast manner, and cannot be distributed in a one-to-many multicast or broadcast manner. In this embodiment, to improve the efficiency of message delivery, the message delivery component can distribute a received message to multiple components based on the message identifier, thereby achieving one-to-many multicast or broadcast message distribution (i.e., one-to-many multicast transmission of the message). Through the above method, even if multiple components need to deliver the message, the message publisher only needs to publish the message once, and the message delivery component executes the message distribution and delivery through the message subscription relationship.

[0074] For the target message, if multiple components in the target device have subscribed to the target message, that is, the second component includes multiple components, the target message can be delivered to each of the multiple components in sequence through the message delivery component. Here, the method of delivering the target message to multiple components is similar to that in the previous embodiment and is not further described in this embodiment.

[0075] Through this embodiment, the same message is delivered to multiple components respectively through the message delivery component, which can achieve one-to-many message distribution and improve the efficiency of message delivery.

[0076] In an exemplary embodiment, after delivering the target message to the second component through the message delivery component, the method further includes:

[0077] S41, determining a publishing result of a target message through a message delivery component within a preset time, wherein the publishing result of the target message is a result of publishing the target message to multiple components;

[0078] S42: Feedback the publishing result of the target message to the first component through the message delivery component.

[0079] In the related art, when messages are passed between components within the system, after the message publisher calls the message queue write interface of the message receiver, it does not know whether the message has been processed normally by the message receiver. For the message publisher, the message is only written to the message queue of the message receiver, and it does not know whether the message receiver has processed the incoming message. If, after the message is published, the message publisher wants to know whether the message receiver has processed the message written by the message publisher, the message receiver needs to send a response to the message publisher. In terms of code complexity, it is relatively complicated to implement. In particular, the above solution is not friendly to low-resource environments (limited memory resources and flash memory resources).

[0080] In this embodiment, if the message publisher needs to monitor whether all subscribed message receivers have processed the message after it is published, the message delivery component can count the message publishing results. That is, whether the target message published to each component has been processed by each component, thereby obtaining the target message publishing results, i.e., the results of publishing the target message to multiple components. It should be noted that when the message delivery component delivers a message, it can implement message delivery by calling the message processing function of the message receiver that subscribed to the message. The completion of the message processing function call indicates that the receiving end has completed receiving and processing the message. Here, the parameters of the message processing function can be defined by the message receiver and passed in when subscribing to the message, so that the message delivery component can call it when delivering the message.

[0081] To avoid long wait times for the messaging component due to unprocessed target messages on a particular component, a waiting time can be preset. For example, a timer or counter can be used to measure the waiting time. Here, the waiting time is set to a preset time. Within the preset time, the messaging component can deliver the message and collect statistics on the publishing results. The publishing result of the target message is then determined based on the statistics collected within the preset time. If the message is delivered to all components that have subscribed to the target message within the preset time, it can be determined that all subscribed components have processed the target message. Otherwise, it can be determined that the target message has not been processed by all components.

[0082] After receiving the target message's publication result, the messaging component can feed the target message's publication result back to the first component to inform it of the publication result. The target message's publication result can be one of multiple, for example, the target message has been processed by all subscribed components, or the target message has not been processed by all subscribed components. This approach avoids the cumbersome process of requiring each message receiver to respond to the message publisher's processing result during message transmission, which would require the publisher to perform its own statistics. This also reduces the use of network transmission resources.

[0083] It should be noted that the messaging component's ability to return message processing results to the publisher is optional. The publisher can choose whether to implement this function. If so, it can register a publishing result notification function when publishing a message to the messaging component. This function is then called after the message broker completes publishing, triggering the messaging component to initiate the post-message result statistics function. If an RTE environment is available, the RTE can perform the publishing result statistics process. Otherwise, the messaging component can perform the publishing result statistics process directly.

[0084] For example, if the message publisher needs to check whether all message receivers have processed the message after it is published, the message broker will initiate a "message broker processes the message and then responds after the subscribers have processed it" function when publishing message id_1. This function is used to count whether all subscribers (message receivers) have received and processed the message. Upon completion of processing or a timeout, the message broker can provide feedback to the publisher regarding whether all subscribers have processed the message.

[0085] Through this embodiment, the publishing results are counted through the message passing component, and the processing results of all message receiving ends are returned through a response message, which can reduce the complexity of the processing results counted by the message publishing end itself and reduce the occupation of network transmission resources.

[0086] In an exemplary embodiment, after the target message is sequentially delivered to each component of the plurality of components through the message delivery component, the method further includes:

[0087] S51 , in the case where the target message fails to be delivered to the target component among the multiple components, the target message is redistributed to the target component through the message delivery component.

[0088] If the publishing results (or processing results) calculated by the messaging component within a preset time indicate that the target component among the multiple components has not received and processed the target message, it can be determined that the target message has failed to be delivered to the target component. In this case, the messaging component and the message publishing component may not perform any operation, or the message publishing component may re-deliver the target message to the messaging component, and the message publishing component or the messaging component may specify that the re-published target message be published to the target component.

[0089] In this embodiment, to improve the efficiency of message republication, the messaging component can redistribute the target message to the target component. Here, the target component can include one or more components. If the target component includes multiple components, the messaging component can redistribute the target message to multiple components using a method similar to the above. This has already been explained and will not be repeated here.

[0090] Through this embodiment, when publishing fails, the message delivery component re-delivers the message, which can improve the success rate of component message reception and improve the efficiency of message delivery.

[0091] In an exemplary embodiment, the method further includes:

[0092] S61: When it is determined that no component in the target device has subscribed to the target message, the memory resources corresponding to the published target message are released, and the publication of the target message is ended.

[0093] For message distribution and delivery between components within the system, the messaging component can manage message distribution and delivery through memory, i.e., store information related to the target message. After completing the distribution of the target message, returning the target message publishing result to the first component, or republishing the target message, the memory resources corresponding to the target message can be released, and the target message publishing can be terminated.

[0094] In this embodiment, if it is determined that no component in the target device has subscribed to the target message, the messaging component may directly release the memory resources corresponding to publishing the target message and terminate publishing of the target message. Optionally, the messaging component may also return an indication to the first component that no component has subscribed to the target message. This return of the indication to the first component may be performed before or after the release of the memory resources.

[0095] In this embodiment, when it is determined that no component has subscribed to the message published to the messaging component, by releasing the memory resources corresponding to the published message, the waste of memory resources can be reduced and the rationality of resource utilization can be improved.

[0096] The following describes the message transmission method between components in the embodiment of the present application with reference to an optional example. In this optional example, the message publishing end is component 1, the message subscription end is component 2 / 3 / ..n, and the message transmission component is a publish-subscribe component.

[0097] Currently, some operating systems are designed to be component-based (modular), with decoupling between components so that any component can be added or removed as needed. However, calling each other's interfaces is not permitted. To reduce the coupling between components, this optional example provides a subscription-based message distribution and delivery solution. This allows for highly cohesive and low-coupling code between components, allowing for flexible customization.

[0098] In addition, in the message transmission method in the related art, after the message is sent, if the message sending end needs to confirm whether the message receiving end has received the message, the message receiving end needs to make a response to the message. In this optional example, after the message is published, if the message publishing end needs to know the result of whether the message has been received and processed by the message subscribing end, it can register a result callback notification interface (function) through the message publishing interface to achieve it. There is no need to pay attention to the response of each message subscribing end. The publishing and subscribing end (i.e., the publishing and subscribing component) delegates the response statistics work. In this way, a more user-friendly experience can be provided for the users of the component, and more processing resources can be saved.

[0099] Combine Figure 3 The process of the message transmission method between components in this optional example may include the following steps:

[0100] Step 1: Component 2 / 3 / … / n subscribes to the message id_1 that it is interested in through the message subscription interface provided by the publish / subscribe component.

[0101] Step 2: Component 1 completes the publication of message id_1 by calling the message publishing interface of the publish-subscribe component.

[0102] Step 3: The publish-subscribe component retrieves the subscription status of the message id_1 and publishes the message id_1 published by component 1 to the subscribing components 2 / 3 / … / n in sequence.

[0103] In step 4, when the publish-subscribe component publishes message id_1 through the proxy, it starts the "message proxy processes the publication and then responds after the subscriber completes the processing" function to count the reception of message id_1 by components 2 / 3 / ..n.

[0104] Step 5: When statistics are completed or processing times out, the publish-subscribe component feeds back the publishing results to component 1.

[0105] This optional example allows for multicast message distribution and message content delivery within the system. By completely decoupling message delivery between components, the message sender and receiver only need to focus on the message itself without worrying about each other, making it easier to tailor components.

[0106] 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.

[0107] 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.

[0108] 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:

[0109] A first acquiring unit 402 is configured to acquire a target message published by a first component of the target device through a message delivery component of the target device, wherein the message delivery component is configured to deliver messages between different components of the target device;

[0110] A first determining unit 404 is connected to the first acquiring unit 402 and is configured to determine, in response to the acquired target message and according to the message identifier of the target message, a component in the target device that subscribes to the target message;

[0111] The first delivery unit 406 is connected to the first determination unit 404 and is configured to distribute the target message to the second component through the message delivery component when it is determined that the second component in the target device has subscribed to the target message.

[0112] It should be noted that the first acquiring unit 402 in this embodiment can be used to execute the above step S202, the first determining unit 404 in this embodiment can be used to execute the above step S204, and the first transmitting unit 406 in this embodiment can be used to execute the above step S206.

[0113] Through the above module, the target message published by the first component of the target device is obtained through the message passing component of the target device, wherein the message passing component is used to pass messages between different components of the target device; in response to the obtained target message, the component in the target device that subscribes to the target message is determined according to the message identifier of the target message; when it is determined that the second component in the target device has subscribed to the target message, the target message is distributed to the second component through the message passing component, which solves the problem of high complexity of component tailoring caused by the high degree of coupling between components in the message passing method between components in the related art, and reduces the complexity of component tailoring.

[0114] In an exemplary embodiment, the apparatus further comprises:

[0115] A second acquiring unit is configured to acquire a message subscription request of a second component through a message delivery component, wherein the message subscription request carries a group of message identifiers to be subscribed, and the group of message identifiers includes a message identifier of a target message;

[0116] The storage unit is used to save the message subscription relationship between the second component and the message identified by each message identifier in a group of message identifiers in response to the acquired message subscription request.

[0117] In an exemplary embodiment, the first acquiring unit includes:

[0118] The acquisition module is used to acquire, through the message delivery component of the target device, the target message published by the first component of the target device by calling the message publishing interface of the message subscription component.

[0119] In one exemplary embodiment, the first transfer unit includes:

[0120] The delivery module is used to deliver the target message to each component of the multiple components in sequence through the message delivery component when it is determined that multiple components in the target device have subscribed to the target message, wherein the second component includes multiple components.

[0121] In an exemplary embodiment, the apparatus further comprises:

[0122] a second determining unit, configured to determine, through the message delivery component within a preset time, a publishing result of the target message after the target message is delivered to the second component through the message delivery component, wherein the publishing result of the target message is a result of publishing the target message to multiple components;

[0123] The feedback unit is used to feed back the publishing result of the target message to the first component through the message delivery component.

[0124] In an exemplary embodiment, the apparatus further comprises:

[0125] The second delivery unit is used to deliver the target message to each component of the multiple components in sequence through the message delivery component, and then re-deliver the target message to the target component through the message delivery component in the event that delivery of the target message to the target component of the multiple components fails.

[0126] In an exemplary embodiment, the apparatus further comprises:

[0127] The execution unit is used to release the memory resources corresponding to the target message and end the publication of the target message when it is determined that no component in the target device has subscribed to the target message.

[0128] 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.

[0129] 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.

[0130] 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.

[0131] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:

[0132] S1, obtaining a target message published by a first 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;

[0133] S2, in response to the acquired target message, determining a component in the target device that subscribes to the target message according to the message identifier of the target message;

[0134] S3: When it is determined that the second component in the target device has subscribed to the target message, the target message is delivered to the second component through the message delivery component.

[0135] 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.

[0136] 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.

[0137] 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.

[0138] 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,

[0139] Memory 506, for storing computer programs;

[0140] The processor 502 is configured to execute the computer program stored in the memory 506 to implement the following steps:

[0141] S1, obtaining a target message published by a first 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;

[0142] S2, in response to the acquired target message, determining a component in the target device that subscribes to the target message according to the message identifier of the target message;

[0143] S3: When it is determined that the second component in the target device has subscribed to the target message, the target message is delivered to the second component through the message delivery component.

[0144] 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.

[0145] 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.

[0146] As an example, the memory 506 may include, but is not limited to, the first acquisition unit 402, the first determination unit 404, and the first transmission unit 406 in the resource information push device. In addition, it may also include, but is not limited to, other module units in the resource information push device, which will not be repeated in this example.

[0147] 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.

[0148] 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.

[0149] 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.

[0150] 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.

[0151] 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.

[0152] 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.

[0153] 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.

[0154] 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.

[0155] 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.

[0156] 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.

[0157] 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: Acquire, through a message delivery component of the target device, a target message published by a first component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device; In response to the acquired target message, determining, according to the message identifier of the target message, a component in the target device that subscribes to the target message; In a case where it is determined that a second component in the target device has subscribed to the target message, delivering the target message to the second component through the message delivery component; The method further comprises: Obtaining, through the messaging component, a message subscription request of the second component, wherein the message subscription request carries a group of message identifiers to be subscribed, and the group of message identifiers includes the message identifier of the target message; In response to the acquired message subscription request, the message subscription relationship between the second component and the message identified by each message identifier in the set of message identifiers is saved.

2. The method according to claim 1, characterized in that The acquiring, through the message delivery component of the target device, the target message published by the first component of the target device, includes: The target message published by the first component of the target device by calling the message publishing interface of the message subscription component is obtained through the message delivery component of the target device.

3. The method according to claim 1, characterized in that The delivering the target message to the second component in the target device by using the message delivery component when it is determined that the second component in the target device has subscribed to the target message includes: When it is determined that multiple components in the target device have subscribed to the target message, the target message is sequentially delivered to each component in the multiple components through the message delivery component, wherein the second component includes the multiple components.

4. The method according to claim 3, characterized in that After delivering the target message to the second component through the message delivery component, the method further includes: Determining a publishing result of the target message through the message delivery component within a preset time, wherein the publishing result of the target message is a result of publishing the target message to the multiple components; The publishing result of the target message is fed back to the first component through the message delivery component.

5. The method according to claim 3, characterized in that After the target message is sequentially delivered to each component of the plurality of components by the message delivery component, the method further includes: In the case that delivery of the target message to a target component among the multiple components fails, the target message is re-delivered to the target component through the message delivery component.

6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: When it is determined that no component in the target device has subscribed to the target message, the memory resources corresponding to publishing the target message are released, and the publishing of the target message is ended.

7. A message transmission device between components, characterized in that: include: A first acquiring unit is configured to acquire a target message published by a first component of the target device through a message delivery component of the target device, wherein the message delivery component is configured to deliver messages between different components of the target device; a determining unit, configured to determine, in response to the acquired target message and according to a message identifier of the target message, a component in the target device that subscribes to the target message; A first delivery unit is configured to deliver the target message to the second component through the message delivery component when it is determined that the second component in the target device has subscribed to the target message; A second acquiring unit is configured to acquire a message subscription request of the second component through the message delivery component, wherein the message subscription request carries a group of message identifiers to be subscribed, and the group of message identifiers includes the message identifier of the target message; A saving unit is used to save the message subscription relationship between the second component and the message identified by each message identifier in the group of message identifiers in response to the acquired message subscription request.

8. 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 6 when executed.

9. 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 6 through the computer program.

Citation Information

Patent Citations

  • Apparatus and method for implementing communication between components of single process

    CN101315609A

  • Subscription merging method and device, electronic equipment, storage medium and product

    CN115103322A