WO2024092938A1 - 组件间的消息传递方法和装置、存储介质及电子装置 - Google Patents
组件间的消息传递方法和装置、存储介质及电子装置 Download PDFInfo
- Publication number
- WO2024092938A1 WO2024092938A1 PCT/CN2022/135687 CN2022135687W WO2024092938A1 WO 2024092938 A1 WO2024092938 A1 WO 2024092938A1 CN 2022135687 W CN2022135687 W CN 2022135687W WO 2024092938 A1 WO2024092938 A1 WO 2024092938A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- message
- target
- publishing
- component
- subscription
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 130
- 230000005540 biological transmission Effects 0.000 title claims abstract description 100
- 230000006870 function Effects 0.000 claims description 153
- 238000012545 processing Methods 0.000 claims description 68
- 238000005316 response function Methods 0.000 claims description 68
- 230000008569 process Effects 0.000 claims description 62
- 238000013507 mapping Methods 0.000 claims description 22
- 238000004590 computer program Methods 0.000 claims description 8
- 230000001960 triggered effect Effects 0.000 claims description 8
- 230000004044 response Effects 0.000 description 17
- 238000004891 communication Methods 0.000 description 12
- 239000003795 chemical substances by application Substances 0.000 description 8
- 230000009471 action Effects 0.000 description 7
- 238000010586 diagram Methods 0.000 description 7
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 4
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000012546 transfer Methods 0.000 description 3
- 230000006872 improvement Effects 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 238000005406 washing Methods 0.000 description 2
- XLYOFNOQVPJJNP-UHFFFAOYSA-N water Substances O XLYOFNOQVPJJNP-UHFFFAOYSA-N 0.000 description 2
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 1
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 1
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 1
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 1
- 238000004887 air purification Methods 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000004140 cleaning Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000001035 drying Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 239000004984 smart glass Substances 0.000 description 1
- 238000010408 sweeping Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/51—Discovery or management thereof, e.g. service location protocol [SLP] or web services
Definitions
- the present disclosure relates to the field of smart home/intelligent family technology, and in particular to a method and device for message transmission between components, a storage medium, and an electronic device.
- data transmission is usually carried out according to existing channels, and message distribution and transmission are realized within the system, and the channels used are usually message queues.
- the two components create their own message queues respectively, and each component provides an interface for writing its own message queue (i.e., an interface for writing messages, an interface for writing message queues) to realize message transmission between the two components.
- the message sending end wants to send a message to multiple receiving ends and needs to confirm whether the message has been received by all message receiving ends after sending the message, it is necessary to send the message to each message receiving end respectively, and wait for the reply message returned by each message receiving end.
- the processing logic of the component is complicated, and the efficiency of message transmission is low.
- the message transmission method between components in the related art has the problem that the processing logic of the component is complicated and the efficiency of message transmission is low because the message sending end needs to send messages to each message receiving end respectively and wait for the reply message of each message receiving end.
- Embodiments of the present disclosure provide a method and device for message transmission between components, a storage medium, and an electronic device.
- a method for message transmission between components comprising: obtaining a target published message published by a message publishing component of a 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; determining whether there is a message subscription component subscribed to the target published message in the target device according to a target message identifier of the target published message; in a case where it is determined that there is a message subscription component subscribed to the target published message in the target device, and the message publishing component indicates that a publishing result of the target published message is fed back to the message publishing component, the target published message is transmitted to each message subscription component subscribed to the target published message through the message transmission component; and according to the message subscription components to which the target published message has been published within a preset time, feeding back a first publishing result to the message publishing component, wherein the first publishing result is used to indicate whether the target published message has been published to all message subscription components of the target published message.
- a message transmission device between components, including: an acquisition unit, configured to acquire a target published message published by a message publishing component of a 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; a first determination unit, configured to determine whether there is a message subscription component that has subscribed to the target published message in the target device according to a target message identifier of the target published message; a transmission unit, configured to, when it is determined that there is a message subscription component that has subscribed to the target published message in the target device and the message publishing component indicates that the publishing result of the target published message is fed back to the message publishing component, transmit the target published message to each message subscription component that has subscribed to the target published message through the message transmission component; a first feedback unit, configured to feedback a first publishing result to the message publishing component according to the message subscription components to which the target published message has been published within a preset time, wherein the first publishing result is
- a computer-readable storage medium in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned message transmission method between components when running.
- an electronic device 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.
- a message delivery component is used to deliver messages between different components, and the message delivery component performs statistics on the message distribution results and sends the statistics results to the message distribution component.
- the target release message published by the message publishing component of the target device is obtained through the message delivery component of the target device, wherein the message delivery component is used to deliver messages between different components of the target device; according to the target message identifier of the target release message, it is determined whether there is a message subscription component that has subscribed to the target release message in the target device; when it is determined that there is a message subscription component that has subscribed to the target release message in the target device, and the message publishing component indicates that the publishing result of the target release message is fed back to the message publishing component, the target release message is delivered to each message subscription component that has subscribed to the target release message through the message delivery component; according to the message subscription components to which the target release message has been published within a preset time, a first publishing result is fed back to the message publishing component, wherein the first publishing result is used to indicate whether the
- FIG1 is a schematic diagram of a hardware environment of a message transmission method between components according to an embodiment of the present disclosure
- FIG2 is a flow chart of an optional method for message transmission between components according to an embodiment of the present disclosure
- FIG3 is a flow chart of another optional method for message transmission between components according to an embodiment of the present disclosure.
- FIG4 is a schematic diagram of an optional method for message transmission between components according to an embodiment of the present disclosure.
- FIG5 is a schematic diagram of another optional method for message transmission between components according to an embodiment of the present disclosure.
- FIG6 is a structural block diagram of an optional message transmission device between components according to an embodiment of the present disclosure.
- FIG. 7 is a structural block diagram of an optional electronic device according to an embodiment of the present disclosure.
- a method for message transmission between components is provided.
- the method for message transmission between components is widely used in whole-house intelligent digital control application scenarios such as smart home, smart home, smart home device ecology, and smart house ecology.
- the above-mentioned method for message transmission between components can be applied to a hardware environment composed of a terminal device 102 and a server 104 as shown in Figure 1.
- the server 104 is connected to the terminal device 102 through a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal.
- a database can be set 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.
- the above network may include but is not limited to at least one of the following: wired network, wireless network.
- the above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth.
- WIFI Wireless Fidelity
- the terminal device 102 may be but is not limited to a PC, mobile phone, tablet computer, smart air conditioner, smart range hood, smart refrigerator, smart oven, smart stove, smart washing machine, smart water heater, smart washing equipment, smart dishwasher, smart projection equipment, smart TV, smart clothes drying rack, smart curtain, smart audio and video, smart socket, smart audio, smart speaker, smart fresh air equipment, smart kitchen and bathroom equipment, smart bathroom equipment, smart sweeping robot, smart window cleaning robot, smart mopping robot, smart air purification equipment, smart steamer, smart microwave oven, smart kitchen treasure, smart purifier, smart water dispenser, smart door lock and other voice devices that can perform voice interaction.
- the message transmission method between components of the embodiment of the present disclosure may be executed by the server 104, or by the terminal device 102, or by both the server 104 and the terminal device 102.
- the message transmission method between components of the embodiment of the present disclosure may be executed by the terminal device 102 or by a client installed thereon.
- FIG. 2 is a flow chart of an optional method for transmitting messages between components according to an embodiment of the present disclosure. As shown in FIG. 2 , the flow of the method may include the following steps:
- Step S202 acquiring a target publishing message published by a message publishing 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.
- 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, an ecological operating system for smart homes in the field of smart homes.
- An embedded system may include a hardware part and a software part.
- the operating system of an embedded system may 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 may be a smart home device or other types of terminal devices.
- the channels used can be local sockets (local "sockets", that is, interfaces for local network communication), message queues, etc.
- local sockets local "sockets", that is, interfaces for local network communication
- message queues etc.
- each has its own message queue and a lock mechanism that can ensure the atomicity of the read and write process; provide an interface for writing message queues (that is, writing message queue interface) to the outside world, so that the other party can complete the operation of other components writing message queues to their own components by calling this interface, and the writing message queue interface is protected by atomic operations through locking; each has a poll mechanism (equivalent to a timer, used to wake up the process) to read their own queues cyclically. If there is a message written, the message is read out for processing.
- Component 1 can send a message to component 2 by calling the writing message queue interface of component 2.
- the message publisher (component 1) calls the write message queue interface of the message receiver (component 2) to publish the message to the message receiver, it does not know whether the message is processed normally by the message receiver. For the message publisher, it only writes the data to the message queue of the message receiver, but does not know whether the message receiver has processed the incoming data. If the message publisher wants to know that the message receiver has processed the message, the message receiver needs to feedback the corresponding response to the message publisher. Especially in the one-to-many message publishing, after the message publisher publishes the message to multiple message receivers, the message publisher needs to wait for the response message returned by each message receiver. The corresponding statistical process is cumbersome, the processing logic is complex, and the message transmission efficiency is also low.
- a message proxy can be set up to transfer messages between different components of the target device.
- the message proxy performs proxy publishing of messages. If the message publisher needs to know whether all message receivers have obtained and processed the message, the message proxy can perform statistics on the publishing results and feed back the publishing results of whether the message has been published to all message receivers to the message publisher.
- the message proxy performs proxy publishing of messages based on subscription and publishing methods.
- the message receiver is the message subscription component that subscribes to the message
- the corresponding message publisher is the message publishing component.
- the message publishing component can be a message publisher of a specific message type, which can be called a message publishing component, publisher, publisher, etc.
- the message subscription component can be a message receiver of a specific message type, which can be a subscriber of a specific message type, which can be called a message subscription component, subscriber, subscriber, etc.
- the message proxy is also called a message transmission component, a publishing and subscription component, etc.
- the message receiving end can be an independent component or a component that relies on a certain RTE environment (Run-Time Environment).
- the RTE environment refers to a specific and independent context environment when a piece of code is about to be executed, which is equivalent to an independent thread.
- the message passing component is a component different from the message publishing end and the message receiving end.
- the message agent When the message agent is publishing, when the message published to the message passing component is obtained, the message passing component can retrieve the message type and send it to the RTE environment for execution. If there is no RTE environment, the callback function registered by the message receiving end can be directly executed.
- the message subscriber can use the message subscription interface provided by the publish-subscribe component to perform the action of subscribing to specific messages.
- the message publisher can call the message publishing interface provided by the publish-subscribe component to perform the action of publishing messages, publish the messages to be published to the message passing component, and the message passing component completes the distribution and message delivery process. Since the distribution of messages and the statistics of distribution results are completed by the message publishing component, the message publishing component only needs to call the corresponding interface of the message passing component, so that the purpose of not requiring the message sender to send messages to each message receiving end separately and wait for the reply messages of each message receiving end can be achieved.
- the process of proxy publishing of messages by the messaging component can be a process of retrieving the message type and sending it to the RTE environment for execution. If there is no RTE environment, the process of directly executing the callback function registered by the message receiving component can be performed.
- the callback function can be a message processing function, and the message-related content can be passed into the function in the form of parameters.
- the call and execution of the function when the proxy publishes the message can enable the message receiving component to obtain the corresponding message and perform corresponding business logic processing.
- the parameters of the callback function that is, the parameters of the message processing function, can be customized by the message subscription component, and the message subscription component can choose to use or not as needed.
- the messaging component can bring this parameter in when calling the message processing function to meet the special needs of the message subscription component.
- the message subscription component can use the message subscription interface provided by the messaging component to perform the action of subscribing to a specific message.
- the message publishing component can use the message publishing interface provided by the messaging component to perform the action of publishing the message. The messaging component completes the distribution and message delivery process.
- the target publishing message published by the message publishing component of the target device can be obtained through the message delivery component of the target device.
- the target publishing message can be a message of a specific message type published by the first component, which can be used to trigger the message receiving component to execute the corresponding business, and can be a message published by the message publishing component to the message delivery component by calling the message publishing interface of the message delivery component.
- the message publishing component can call the message publishing interface of the messaging component and input the corresponding parameter data to complete the publishing of the target publishing message to the messaging component.
- the parameter data here may include: the type of message, the content of the message body, the length of the message body, etc.
- the type of the message may be a message identifier, i.e., a message ID (Identifier), which may be a msg_id (message identity document) defined according to specific business logic requirements.
- the message body may correspond to the message data (i.e., the publishing content), which may be the structured message content that needs to be transmitted in the messaging requirement.
- the message body length is the data length of the message data to be transmitted when the message body needs to be transmitted (0 may be filled in if the message body does not need to be transmitted).
- the message body content and the message body length may be optional, and are filled in by the message publishing component in the scenario where a structured message needs to be transmitted.
- Step S204 determining whether there is a message subscription component in the target device that has subscribed to the target published message according to the target message identifier of the target published message.
- Message transmission can be performed based on message identifiers within the system, that is, the message transmission component can distribute and transmit messages based on message identifiers.
- the components on the target device can subscribe to the messages of interest through message identifiers.
- message subscription information can be saved in advance.
- the message subscription information here is used to characterize the message subscription component that publishes 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 transmission component, or in other storage resources outside the message transmission component, but the address information of the corresponding storage resource can be saved in the message transmission component to ensure that the message transmission component can search for the saved message subscription information.
- the message delivery component can determine whether there is a message subscription component subscribed to the target published message in the target device according to the target message identifier of the target published message.
- the method of determining whether there is a message subscription component subscribed to the target published message in the target device can be: using the message identifier of the target published message to search for the saved message subscription information, and in the case of finding a component identifier corresponding to the message identifier of the target published message, it can be determined that there is a message subscription component subscribed to the target published message, and the component identified by the found component identifier can be determined as the message subscription component subscribed to the target published message.
- Step S206 when it is determined that there is a message subscription component that has subscribed to the target published message in the target device, and the message publishing component indicates that the publishing result of the target published message is fed back to the message publishing component, the target published message is delivered to each message subscription component that has subscribed to the target published message through the message delivery component.
- the message publishing component can add instruction information for feeding back the publishing result of the target published message to the message delivery component in the input parameter data during the process of publishing the target published message to the message delivery component, which can be the publishing reply processing callback registered by the message publishing component and the corresponding publishing reply callback parameter.
- the publishing reply processing callback is filled in according to the business logic requirements of the message publishing component. If the message publishing component wants to know whether the message proxy (message delivery component) has published the message to all message subscription components, the message publishing component can register this publishing reply callback to know whether the message has been distributed and delivered to all message subscription components within the specified time.
- the message publishing component can choose whether to use and fill in the publishing reply callback parameter according to its own business logic requirements. If the publishing reply callback parameter is filled in, the publishing reply callback parameter can be passed in as a function parameter when the publishing reply callback is called after the message publishing completes the distribution and delivery or when the distribution and delivery timeout occurs.
- the target published message when it is determined that there is a message subscription component that has subscribed to the target published message in the target device, and the message publishing component indicates that the publishing result of the target published message is fed back to the message publishing component, the target published message can be distributed (and delivered) to each message subscription component that has subscribed to the target published message through the message delivery component.
- the message delivery component can deliver the target published message to each message subscription component respectively.
- the process of delivering the target published message to different message subscription components can be executed in parallel or in series (that is, the target published message is distributed to each component in turn), which is not limited in this embodiment.
- the RTE environment of the message subscription component can execute the distribution of the target published message. If the RTE environment does not exist, the message delivery component can directly execute the distribution of the target published message. In addition, during the process of executing the distribution of the target published message in the RTE environment, the message delivery component can execute other operations, such as receiving messages published by other components, determining the component that subscribes to the message according to the message identifier corresponding to the message, and so on.
- the above-mentioned process of distributing the target published message to the message subscription component can be the process of executing the message processing function by the above-mentioned RTE environment or the message transmission component. Since the parameters of the message processing function are registered to the message transmission component by each message transmission component when subscribing to the corresponding message according to its own business logic requirements, in the proxy publishing process, the corresponding message processing function is called and executed, and the distribution of the target published message to the corresponding message subscription component is completed; similarly, after the target published message is processed by the message processing function of the message subscription component, it can be indicated that the message subscription component has received and processed the target published message.
- the publishing result of the target published message is the result of whether the target published message has been published to all message subscription components.
- Step S208 based on the message subscription components to which the target published message has been published within a preset time, a first publishing result is fed back to the message publishing component, wherein the first publishing result is used to indicate whether the target published message has been published to all message subscription components of the target published message.
- a time can be preset as the maximum time for the message publisher to wait for the response result after the message is published, that is, the timeout time for waiting for the response processing callback after the publication, which can be specified by the message publisher or a default value.
- the first publishing result can be directly fed back to the message publishing component, and the first publishing result is used to indicate that the target published message has been published to all the message subscription components of the target published message;
- the proxy publishing and statistics can also be stopped, and the first publishing result can be fed back to the message publishing component, and the first publishing result is used to indicate that the target published message has not been published to all the message subscription components of the target published message, so as to quickly determine the publishing result in a shorter time, release the corresponding resources in time, and make corresponding policy adjustments in time according to the publishing result.
- the arrival of the preset time can be counted by a timer. The timer can be created after the subscription information is determined, and the timer can be started when the distribution of the target published message starts according to the subscription information.
- the first publishing result can also be used to indicate the message subscription components to which the target published message has been published and the message subscription components to which it has not been published. Since the subscription information of each message subscription component is known, it is possible to determine which components have subscribed to the target published message, thereby being able to count the message subscription components to which the target published message has been published and the message subscription components to which it has not been published within a preset time. Considering that the message publishing component and the message subscription component are decoupled through the messaging component in this embodiment, the message publishing component usually does not care about the components that have subscribed to the messages it publishes. Therefore, the first publishing result can also be used to only indicate whether the target published message has been published to all message subscription components, without indicating the publishing results of the target published message to each message subscription component.
- the target published 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; according to the target message identifier of the target published message, it is determined whether there is a message subscription component that has subscribed to the target published message in the target device; when it is determined that there is a message subscription component that has subscribed to the target published message in the target device, and the message publishing component indicates that the publishing result of the target published message is fed back to the message publishing component, the target published message is transmitted to each message subscription component that has subscribed to the target published message through the message transmission component; according to the message subscription components to which the target published message has been published within a preset time, the first publishing result is fed back to the message publishing component, wherein the first publishing result is used to indicate whether the target published message has been published to all the message subscription components of the target published message, thereby solving the problem that the message transmission method between components in the related art has complex component processing
- determining whether there is a message subscription component subscribed to the target published message in the target device according to the target message identifier of the target published message includes:
- the subscription table is used to record a mapping relationship between a message identifier of a subscribed message and a header address of an information linked table corresponding to the message identifier of the subscribed message, and the information linked table 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;
- the subscription information corresponding to each message identifier can be recorded in the form of an information linked list, and the subscription information corresponding to different message identifiers can be recorded through different information linked lists.
- the subscription information corresponding to the message identifier refers to the subscription information corresponding to the component that subscribes to the message identified by the message identifier.
- the subscription information corresponding to the message subscription component of the subscribed message can be stored, and the subscription information corresponding to the message subscription component of the same message can be stored in the same information linked list.
- the mapping relationship between the message identifier of the subscribed message and the header address of the information linked list corresponding to the message identifier of the subscribed message can be recorded in the subscription table.
- the mapping relationship here can be the relationship obtained by hash mapping the message identifier and the header address of the corresponding information linked list.
- the validity of the subscription table can be determined first. If the subscription table is invalid, the publishing process can be exited. If the subscription table is valid, the publishing process can be continued, and the subscription table can be searched, etc.
- the validity of the subscription table refers to whether the subscription table is in a valid state or an available state, which can indicate whether the subscription table records the mapping relationship between the message identifier of the subscribed message and the header address of the information linked table corresponding to the message identifier of the subscribed message, or whether the mapping relationship recorded in the subscription table can be read.
- the message identifier of the target published message is the target message identifier, and the target message identifier can be used to search the subscription table.
- the target message identifier can be used to search the subscription table.
- the header address of the information linked list corresponding to the target message identifier is found, it can be determined that there is a message subscription component subscribed to the target published message in the target device.
- the header address of the information linked list corresponding to the target message identifier is not found in the subscription table, it can be determined that there is no message subscription component subscribed to the target published message in the target device.
- the header position of the information linked list can be determined according to the header address of the information linked list recorded in the subscription table, and the message subscription component that subscribes to the target published message can be determined by traversing the linked list nodes in the information linked list, where a linked list node in the information linked list is used to record the subscription information corresponding to a message subscription component that subscribes to the published message identified by the target message identifier.
- the depth of the found information linked list can be determined; if the depth is not zero, it can be determined that there is a message subscription component that subscribes to the target published message in the target device; otherwise (the header address of the information linked list is not found, or the header address of the information linked list is found but the depth of the found information linked list is zero), it is determined that there is no message subscription component that subscribes to the target published message in the target device.
- relevant data processing and message distribution can be performed. If it is determined that there is no message subscription component that has subscribed to the target published message, other operations on the target published message can be stopped, and the result that there is no message subscription component that has subscribed to the target published message can be fed back to the message publishing component.
- msg_id determines whether msg_id is in the subscription table. If not, it means that there is no subscriber (message subscription component, or subscriber) for this message to be published by the proxy. If the publishing result needs to be responded to by the publisher (message publishing component, or publisher), change the publishing response result to "no one subscribes", call the response callback to notify the publishing result; release necessary resources to end the publishing. If no response is required, release necessary resources and end the publishing.
- delivering the target publishing message to each message subscription component that subscribes to the target publishing message through the message delivery component includes:
- the message delivery component performs the following message delivery operation for each message subscription component to deliver the target published message to each message subscription component, wherein in the process of performing the following message delivery operation, each message subscription component is a current subscription component:
- the execution function body and the response function body are executed in sequence, wherein the execution function body is used to process the publishing information in the target publishing message according to the message processing function, and the response function body is used to adjust the publishing indication identifier corresponding to the current subscription component to the publishing completion indication identifier after the execution of the execution function body is completed.
- the target publishing message after receiving the target publishing message, can be delivered to the message subscription component of the target publishing message within a preset time.
- the message delivery operation performed by the message delivery component for each message subscription component may include: registering an execution function body (job) corresponding to the current subscription component and a response function body (jobback) corresponding to the execution function body; and sequentially executing the above execution function body and the response function body.
- each message subscription component is the current subscription component.
- the above-mentioned execution function body may include the message processing function registered by the current subscription component, which may be used to process the published information in the target published message according to the message processing function, and the parameters of the execution function body may include the published information in the target published message (which may be the published content in the message body). Since the message processing function is registered by the message subscription component, it may be used to perform the processing operations required by the message subscription component on the target published message, that is, it is equivalent to the processing operations performed on the target published message by the message subscription component after the published message is written to the message queue of the message subscription component and the message subscription component reads the target published message from the message queue in the related art. The message processing function in the execution function body is executed, which is equivalent to the target published message being delivered to the message subscription component and the processing operations required by the message subscription component being performed.
- the above-mentioned message delivery operation can be performed after determining the subscription information of all message subscription components that have subscribed to the target published message; it can also be performed after determining the subscription information of some message subscription components that have subscribed to the target published message.
- the delivery process of the target published message and the subscription information of the message subscription component can be executed in parallel or serially.
- the corresponding response function body can be executed to adjust the publishing indication mark corresponding to the current subscription component to the indication mark of publishing completion.
- the response function body includes a publishing statistics function, and the publishing statistics function can be used to indicate the above operation of adjusting the publishing indication mark corresponding to the current subscription component to the indication mark of publishing completion. Since all message subscription components of the target published message are known, a corresponding publishing indication mark can be set for each message subscription component. It can be determined whether the target published message has been published to all message subscription components within the preset time based on whether all the publishing indication marks have been adjusted to the indication mark of publishing completion within the preset time.
- the transmission of the published message and the statistics of the publishing result are completed by registering the execution function body and the corresponding response function body, so that the efficiency of message transmission can be improved.
- executing the execution function body and the response function body in sequence includes:
- the execution function body and the reply function body when the runtime environment (i.e., RTE environment) of the current subscription component is valid, the execution function body and the reply function body can be executed by the runtime environment of the message subscription component; when the runtime environment of the current subscription component is invalid, the execution function body and the reply function body can be executed by the runtime environment agent of the messaging component.
- the runtime environment i.e., RTE environment
- the execution function body and the response function body can be passed into the runtime environment of the current subscription component by calling the interface of the runtime environment of the current subscription component, so that the execution function body and the response function body can be executed in sequence by the runtime environment of the current subscription component.
- the messaging component may continue to perform other operations, for example, it may continue to search for subscription information corresponding to the message subscription component that has subscribed to the target published message, or perform other operations such as message reception and proxy publishing.
- the runtime environment of the current subscription component may be specified when the current subscription component subscribes to the published message identified by the target message identifier. If not specified, the runtime environment of the current subscription component may be considered invalid.
- the RTE environment of the message subscription component determines whether the RTE environment of the message subscription component is valid. If valid, you can register an executor job and register an executor response joback. Call the interface of the RTE environment to let the RTE environment execute the job and joback. Executing a job in the RTE environment is an asynchronous processing process, which is equivalent to making a copy of the message to be published and handing it over to the context of the RTE environment to execute the message processing function.
- the message passing component allows the RTE environment to start executing the job and then perform a loop traversal (the traversal here can include traversing the linked list nodes in the information linked list). After executing the message processing function in the executor job, the RTE environment will call the joback function (that is, the publishing statistics function) to perform statistics on the publishing results.
- the runtime environment of the current subscription component when the runtime environment of the current subscription component is invalid, it is possible to continue to determine whether the message processing function of the current subscription component is valid.
- the execution function body and the response function body can be executed by the runtime environment agent of the messaging component.
- the message transfer component agent will execute the message processing function.
- executing the execution function body and the response function body in sequence includes:
- the process of executing the above-mentioned execution function body may be: passing the publishing information in the target publishing message and the parameters specified by the current subscription component into the execution function body.
- the message subscription component may execute the parameters of the message processing function, which may be a function customized by the message subscription component, and the message subscription component may choose to use or not use it as needed. If this parameter is passed in, the messaging component may bring this parameter in when calling the message processing function to meet the special needs of the message subscription component.
- the execution response function body can be triggered to adjust the publishing indicator corresponding to the current subscription component to the indicator of publishing completion.
- the indicator here can be used to indicate whether the target publishing message has been published to the current subscription component, which can be represented by bits.
- the publishing indicator corresponding to the current subscription component can have obvious differences before and after the execution of the function body is completed to distinguish whether the target publishing message has been published to the current subscription component.
- the messaging component can determine the subscription information corresponding to each message subscription component that has subscribed to the target published message, and can also set a corresponding index value (index) for each message subscription component, using the index value to distinguish which message subscription component this publication traverses.
- a section of memory can be applied for caching the index value.
- a publishing indication corresponding to the index value can be set at the same time.
- the memory that is, the memory for caching the publishing index, can be used to count the publishing results. When counting the publishing results, it can be determined that the target published message has been published to all message subscription components based on the publishing indication of each message subscription component.
- the subscriber list uhos_list_t i.e., the above information list
- the index value (index) can be increased.
- a section of memory can be applied for caching the publishing index and for counting the publishing results.
- the published content and the parameters specified by the message subscription component are passed into the execution function body, and the published content is processed according to the parameters executed by the message subscription component, which can meet the processing requirements of different message subscription components and improve the flexibility of published message processing.
- executing the execution function body and the response function body in sequence includes:
- the execution process of the execution function body may be: passing the publishing information in the target publishing message into the execution function body, executing the above execution function body, and processing the publishing information in the target publishing message according to the message processing function.
- the parameters passed into the execution function body may also include parameters specified by the message subscription component. After the execution of the execution function body is completed, the execution response function body may be triggered.
- the publishing results of different message subscription components can be counted through different bits in the publishing statistics, that is, one bit in the publishing statistics corresponds to a message subscription component of the target publishing message, and one bit usually has two values (0 and 1), wherein the first value (0 or 1) of the two values is used to indicate that the target publishing message has not been published to the corresponding message subscription component, and the second value (1 or 0) of the two values is used to indicate that the target publishing message has been published to the corresponding message subscription component.
- the first value can be set to 1 and the second value can be set to 0.
- the value of the bit corresponding to the current subscription component in the publishing statistical result is adjusted from the first value to the second value, which can facilitate the statistics of the publishing results and improve the efficiency of the statistics of the publishing results.
- the method further includes:
- each publishing process can generate a unique serial number (Serial Number), that is, the publishing response associated SN number, which is used to distinguish the previous and subsequent publishing calls.
- Serial Number can run through the entire cycle of a publishing process. After a publishing process is completed or the publishing timeout is completed, the SN number can be released along with the release of related resources.
- the serial number of the published message can be generated after obtaining the published message published by the message publishing component, or after determining that a component has subscribed to the published message, or at other times.
- a memory cache can be applied for to obtain a publish handle (uh_publish_handler_t), and the obtained publish handle can indicate the memory address of the corresponding published message cache.
- the sequence number generated for it is the target sequence number
- the publish handle of the target publish message can be the publish handle corresponding to the target sequence number, that is, the target publish handle.
- the generated target sequence number can be mapped to the target publish handle, and the mapping relationship between the target sequence number and the target publish handle can be recorded in the publish table.
- mapping relationship between the serial number of the published message and the publishing handle of the published message can be recorded in the publishing table, which can ensure the integrity of the publishing process.
- Each publishing process will generate a unique serial number SN.
- the SN and the publishing handle of the current content to be published can be used to make a mapping.
- the mapping relationship will be released after the publication is completed and/or the publication timeout.
- the validity of the subscription table and the publishing table can be determined first. When both are valid, the subsequent publishing process can be executed. Otherwise, if any one is invalid, the publishing process will be exited.
- the mapping relationship between the message identifier of the subscribed message and the header address of the information linked list corresponding to the message identifier of the subscribed message is recorded in the subscription table
- the target sequence number is generated (the target sequence number may also be generated when the target publication message is received, or when it is determined that both the subscription table and the publication table are valid), and it and the corresponding publication handle are mapped to the publication table (which can be saved in the form of key-value, where the key is the message identifier and the value is the publication handle).
- msg_id is in the subscription table. If the mapping of this msg_id exists in the table, that is, this message has a subscriber, a unique SN can be generated and mapped to the publishing table with the publishing handle uh_publish_handler_t.
- the header address of the information linked list corresponding to the target message identifier is found in the subscription table
- the header address found can be assigned to the subscription information associated with the target publishing handle. Since the subscription information corresponding to each message subscription component can be found according to the header address of the information linked list, the relevant message processing function can be determined, and the proxy can distribute and transmit the message after the assignment is completed.
- a timer can be created and assigned to the publishing handle, the timing time of the timer is the above-mentioned preset time, and the timer is started. In the process of statistically analyzing the publishing results, when the target publishing message is distributed to all message subscription components within the preset time, the target publishing handle can be used to stop the timer.
- the publishing process to be stopped can also be determined based on the corresponding relationship between the target publishing handle and the target publishing handle.
- the pointer of the memory can be associated with the publishing handle, and the bit position of the statistical result corresponding to each index value (index) is the first value (for example, 1).
- the assignment here can be the memory address of the corresponding object pointed to by the pointer in the publishing table, for example, the header address, the memory address of the timer, etc.
- the subscription table is searched to obtain the list header uhos_list_t of the information list, and it is assigned to the subscription information associated with the publishing handle (assigned to uh_publish_handler_t->m_list_subcribe). This is the destination information for the message agent to distribute and deliver messages.
- the relevant message processing functions are all in this header.
- the parameters of the reply function body may include the target sequence number and the index value of the current message subscription component, that is, the current index value.
- the publishing handle corresponding to the target sequence number can be searched in the publishing table according to the target sequence number of the target published message.
- the target sequence number can be a sequence number used to uniquely identify the publishing process of the target published message.
- the target memory pointer can be a pointer to the memory storing the publishing statistical result, that is, the memory of the aforementioned cache publishing index.
- Each index value can correspond to a bit in the publishing statistical result, and the value of the bit corresponding to the current index value in the publishing statistical result can be adjusted from the first value to the second value.
- the current index value can be used to indicate the position of the bit corresponding to the current index value in the publishing statistical result.
- the RTE environment calls joback to trigger the response statistics processing flow.
- the release handle is checked using the SN in the joback parameter, and the release handle statistics result is modified according to the index value in the joback parameter, and the corresponding bit is cleared.
- the publishing handle is determined by the serial number, and the address for recording the publishing statistical results is determined according to the information associated with the publishing handle, which can improve the accuracy of the publishing statistical results.
- the method further comprises:
- each linked list node of the target information linked list corresponding to the target message identifier traverses each linked list node of the target information linked list corresponding to the target message identifier in turn, obtain the subscription information corresponding to each message subscription component, and the index value corresponding to each message subscription component, wherein each linked list node stores the subscription information corresponding to a message subscription component of the message identified by the target message identifier, and the index value corresponding to each message subscription component is generated according to the order in which each message subscription component is traversed.
- the index value can be determined by traversing the information linked list corresponding to the message identifier in sequence to obtain the subscription information corresponding to each message subscription component.
- the index value corresponding to each message subscription component can be generated according to the order in which each message subscription component is traversed.
- the information linked list corresponding to the target message identifier is the target information linked list, and each linked list node in the target information linked list can be traversed in sequence to obtain the subscription information corresponding to each message subscription component and the index value corresponding to each message subscription component.
- each linked list node can store subscription information corresponding to a message subscription component of the message identified by the target message identifier.
- the subscription information stored in different linked list nodes is at least partially different, that is, it can be partially the same but not completely the same.
- the number of bits in the published statistical results can be configured according to the index value of the message subscription component, that is, if the index value is increased by 1, the number of bits in the published statistical results is also increased by 1.
- a corresponding index value is set for each traversed message subscription component, and the index value is used to distinguish which message subscription component is traversed in this release.
- the index value can be self-incremental.
- the index value of the first traversed message subscription component can be 0, and the index value of the second traversed message subscription component can be 1, and the index value of the third traversed message subscription component can be 2, and so on...
- the index value of the message subscription component is determined according to the order of determining the message subscription components, which can avoid the bit modification error caused by too many message subscription components, thereby improving the accuracy of the published statistical results.
- the method further includes:
- the target publishing message according to the values of all bits in the publishing statistics, it can be determined whether the target publishing message has been published to all message subscription components of the target publishing message. In the case where all bits in the publishing statistics are the second value, it can be determined that the target publishing message has been published to all message subscription components of the target publishing message. In the case where at least some bits in the publishing statistics are the first value, it can be determined that the target publishing message has not been published to at least some message subscription components of the target publishing message.
- the determination process of publishing the statistical results can be executed once. For example, each time the publishing statistical function in the response function body is executed, it will determine that all bits in the published statistical results are the second value. If so, the publishing process will end even if the timer has not timed out. In addition, if the timer times out, the publishing process will end even if the response function body is not triggered.
- the statistical result is not all zero, it means that the release is not complete, and the statistical function can return. If the statistical result is all zero, use the release handle to stop the timer.
- the publishing response interface is valid (that is, the publisher is concerned about the publishing result)
- the publishing response interface can be called to feed back the publishing result to the publisher, release resources, release the mapping relationship associated with the publishing SN, and release the publishing handle.
- the published statistical result is not all zero, it indicates that the publishing is not complete, and the publishing statistics function can return.
- the method further includes:
- the release process in the case where it is determined that there is no message subscription component in the target device that has subscribed to the target release message according to the received target release message, if the message release component does not indicate that the release result of the target release message is fed back to the message release component, the release process can be directly ended. If the message release component indicates that the release result of the target release message is fed back to the message release component, a second release result can be fed back to the message release component through the message delivery component.
- the second release result is used to indicate that there is no component in the target device that has subscribed to the target release message.
- the message publishing component can pass in the message to be published by calling the message publishing interface, and the relevant parameters of the message may include: uh_msg_id_t (message type), msg_data (message body), msg_data_len (message length), fn_publish_ack_routine (answer processing callback after publishing), fn_param (callback parameter), ack_fn_timeout_ms (timeout for waiting for answer processing callback after publishing), uh_publish_ack_sn_t (publish answer sn (invisible to the caller)), etc.
- the subscription table and the publishing answer table i.e., the publishing table
- msg_id is in the subscription table. If not, it means that there is no message subscription component for the message to be published by the proxy. If the publishing result needs to be replied to the message publishing component, the publishing reply result is changed to "no one subscribes", the reply callback is called to notify the publishing result, and the necessary resources are released to end the publishing. If no reply is required, the necessary resources are directly released to end the publishing.
- the publishing result is fed back to the message publishing component and the publishing is ended, which can improve the message transmission efficiency.
- the message subscription component is a subscriber
- the message publishing component is a publisher
- the message transmission component is a publish-subscribe component
- the message identifier is msg_id
- the first value is 1, and the second value is 0.
- This optional example provides a message publishing process.
- the publisher registers a publishing result notification function. After the message agent completes publishing, this function is called to obtain the message publishing statistics. This avoids the cumbersome process of each subscriber responding to the processing result when transmitting messages one-to-many, and the publisher needs to publish the statistics based on the response statistics.
- the process of the message transmission method between components in this optional example may include the following steps:
- Step 1 If msg_id is in the subscription table, map the sequence number and the publishing handle to the publishing reply table (ie, the publishing table).
- the validity of the subscription table and the publishing table can be determined in a similar manner to that in FIG4, and whether msg_id is in the subscription table. If not, the processing flow in FIG4 is executed. If it is, the subscription table can be searched according to msg_id, the linked list head of the message subscription component can be determined, and assigned to the publishing handle.
- Step 2 Search the subscription table according to msg_id, determine the linked list head of the message subscription component, and assign it to the publishing handle.
- Step 3 Create a timer and start it. The message distribution process starts from then on.
- Step 3 traverse the linked list and determine the subscriber information (ie, subscription information) and index value one by one.
- Step 4 register the executor job and the response executor jobback.
- the RTE executes the job and jobback by calling the RTE interface.
- Step 5 If the RTE environment is invalid, determine whether the message processing function is valid. If the message processing function is valid, the publish-subscribe component executes the message processing function and clears the bit in the corresponding index value result array, and continues to traverse the subscriber information.
- Step 6 When the timer reaches the end or the statistical results are all zero, the publishing response interface is called using the publishing handle to feed back the result to the publisher, release the resources, cancel the publishing mapping relationship, and release the publishing handle.
- the computer software product is stored in a storage medium (such as ROM (Read-Only Memory)/RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of the various embodiments of the present disclosure.
- a storage medium such as ROM (Read-Only Memory)/RAM (Random Access Memory), a disk, or an optical disk
- a terminal device which can be a mobile phone, a computer, a server, or a network device, etc.
- FIG6 is a structural block diagram of an optional message transmission device between components according to the embodiment of the present disclosure. As shown in FIG6, the device may include:
- An acquisition unit 602 is configured to acquire a target publishing message published by a message publishing 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;
- the first determining unit 604 is connected to the acquiring unit 602 and is configured to determine whether there is a message subscription component in the target device that has subscribed to the target published message according to the target message identifier of the target published message;
- the delivery unit 606 is connected to the first determination unit 604 and is configured to distribute the target published message to each message subscription component subscribed to the target published message through the message delivery component when it is determined that there is a message subscription component subscribed to the target published message in the target device and the message publishing component indicates that the publishing result of the target published message is replied to the message publishing component;
- the first feedback unit 608 is connected to the transmission unit 606, and is configured to send a first publishing result to the message publishing component according to the message subscription components to which the target publishing message has been published within a preset time, wherein the first publishing result is used to indicate whether the target publishing message has been published to all message subscription components of the target publishing message.
- the acquisition unit 602 in this embodiment can be used to execute the above step S202
- the first determination unit 604 in this embodiment can be used to execute the above step S204
- the transmission unit 606 in this embodiment can be used to execute the above step S206
- the first feedback unit 608 in this embodiment can be used to execute the above step S208.
- the target published 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; according to the target message identifier of the target published message, it is determined whether there is a message subscription component that has subscribed to the target published message in the target device; when it is determined that there is a message subscription component that has subscribed to the target published message in the target device, and the message publishing component indicates that the publishing result of the target published message is fed back to the message publishing component, the target published message is transmitted to each message subscription component that has subscribed to the target published message through the message transmission component; according to the message subscription components to which the target published message has been published within a preset time, the first publishing result is fed back to the message publishing component, wherein the first publishing result is used to indicate whether the target published message has been published to all the message subscription components of the target published message, thereby solving the problem that the message transmission method between components in the related art has the complex processing logic of the component and
- the first determining unit includes:
- a search module configured to use the target message identifier to search for a subscription table, wherein the subscription table is used to record a mapping relationship between a message identifier of a subscribed message and a header address of an information linked table corresponding to the message identifier of the subscribed message, and the information linked table 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;
- a first determination module is configured to determine that a message subscription component subscribed to a target published message exists in the target device when a header address of an information linked list corresponding to a target message identifier is found in a subscription table;
- the second determination module is configured to determine that there is no message subscription component subscribed to the target published message in the target device if the header address of the information linked list corresponding to the target message identifier is not found in the subscription table.
- the transfer unit comprises:
- the execution module is configured to perform the following message delivery operation for each message subscription component through the message delivery component within a preset time to deliver the target published message to each message subscription component, wherein each message subscription component is a current subscription component during the execution of the following message delivery operation:
- the execution function body and the response function body are executed in sequence, wherein the execution function body is used to process the publishing information in the target publishing message according to the message processing function, and the response function body is used to adjust the publishing indication identifier corresponding to the current subscription component to the publishing completion indication identifier after the execution of the execution function body is completed.
- the execution module includes:
- the first input submodule is configured to input the execution function body and the response function body into the runtime environment of the current subscription component by calling the interface of the runtime environment of the current subscription component when the runtime environment of the current subscription component is valid, so that the execution function body and the response function body are executed in sequence by the runtime environment of the current subscription component;
- the first execution submodule is configured to execute the execution function body and the response function body by the runtime environment agent of the messaging component when the runtime environment of the current subscription component is invalid.
- the execution module includes:
- the second input submodule is configured to input the publishing information in the target publishing message and the parameters specified by the current subscription component into the execution function body to execute the execution function body;
- the second execution submodule is configured to trigger the execution response function body after the execution function body is completed, so as to adjust the publishing indication mark corresponding to the current subscription component to the indication mark of publishing completion.
- the execution module includes:
- a third execution submodule is configured to execute an execution function body to process the publishing information in the target publishing message according to the message processing function;
- the fourth execution submodule is configured to trigger the execution response function body after the execution of the execution function body is completed, so as to adjust the value of the bit corresponding to the current subscription component in the publishing statistical result from the first value to the second value, wherein a bit in the publishing statistical result corresponds to a message subscription component of the target publishing message, the first value is used to indicate that the target publishing message has not been published to the corresponding message subscription component, and the second value is used to indicate that the target publishing message has been published to the corresponding message subscription component.
- the apparatus further comprises:
- a search unit is configured to search for a publishing handle corresponding to a target sequence number in a publishing table according to a target sequence number of a target published message after triggering the execution of the response function body, wherein the target sequence number is used to uniquely identify a publishing process of the target published message, the publishing table is used to record a mapping relationship between a sequence number of a published message and a publishing handle of the published message, and the publishing handle is used to indicate a memory address of a corresponding published message;
- a jump unit is configured to jump to the memory pointed to by the target memory pointer associated with the target publishing handle when the target publishing handle corresponding to the target publishing message is found, to obtain the publishing statistical result, wherein the target memory pointer is a pointer to the memory storing the publishing statistical result;
- An adjustment unit configured to adjust the value of a bit corresponding to the current index value in the published statistical result from a first value to a second value according to a current index value corresponding to the current subscription component, wherein the current index value is used to indicate the position of the bit corresponding to the current index value in the published statistical result;
- the parameters of the response function body include the target sequence number and the current index value.
- the apparatus further comprises:
- the traversal unit is configured to traverse each linked list node of the target information linked list corresponding to the target message identifier in turn, and obtain subscription information corresponding to each message subscription component and an index value corresponding to each message subscription component, wherein each linked list node stores subscription information corresponding to a message subscription component of the message identified by the target message identifier, and the index value corresponding to each message subscription component is generated according to the order in which each message subscription component is traversed.
- the apparatus further comprises:
- a second determination unit is configured to determine, after triggering the execution of the response function body, that the target published message has been published to all message subscription components of the target published message when all bits in the published statistical result are the second value;
- the third determining unit is configured to determine that the target publishing message is not published to at least some message subscription components of the target publishing message when at least some bits in the publishing statistical result are the first value.
- the apparatus after determining whether there is a message subscription component subscribed to the target published message in the target device according to the target message identifier of the target published message, the apparatus further includes:
- the second feedback unit is configured to, after determining whether there is a message subscription component that has subscribed to the target publish message in the target device according to the target message identifier of the target publish message, and if it is determined that there is no message subscription component that has subscribed to the target publish message in the target device and the message publish component indicates that the publishing result of the target publish message should be fed back to the message publish component, feedback a second publishing result to the message publish component through the message transmission component, wherein the second publishing result is used to indicate that no component in the target device has subscribed to the target publish message.
- a storage medium is further provided.
- 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 disclosure.
- the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.
- the storage medium is configured to store program codes for executing the following steps:
- the storage medium may include but is not limited to: a U disk, a ROM, a RAM, a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
- an electronic device for implementing the above-mentioned message transmission method between components is also provided.
- the electronic device may be a server, a terminal, or a combination thereof.
- FIG7 is a structural block diagram of an optional electronic device according to an embodiment of the present disclosure.
- the electronic device includes a processor 702, a communication interface 704, a memory 706, and a communication bus 708.
- the processor 702, the communication interface 704, and the memory 706 communicate with each other through the communication bus 708.
- the processor 702 is used to execute the computer program stored in the memory 706 to implement the following steps:
- the communication bus may be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc.
- the communication bus may be divided into an address bus, a data bus, a control bus, etc.
- FIG7 is represented by only one thick line, but it does not mean that there is only one bus or one type of bus.
- the communication interface is used for communication between the above-mentioned electronic device and other devices.
- the memory may include RAM, or may include non-volatile memory, such as at least one disk storage.
- the memory may also be at least one storage device located away from the aforementioned processor.
- the memory 706 may include, but is not limited to, the acquisition unit 602, the first determination unit 604, the transmission unit 606, and the first feedback unit 608 in the above-mentioned inter-component message transmission device. In addition, it may also include, but is not limited to, other module units in the above-mentioned inter-component message transmission device, which will not be repeated in this example.
- the above-mentioned processor can be a general-purpose processor, which can include but not be 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.
- CPU Central Processing Unit
- NP Network Processor
- DSP Digital Signal Processing
- ASIC Application Specific Integrated Circuit
- FPGA Field-Programmable Gate Array
- other programmable logic devices discrete gate or transistor logic devices, discrete hardware components.
- the device 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.
- FIG. 7 does not limit the structure of the above electronic device.
- the electronic device may also include more or fewer components (such as a network interface, a display device, etc.) than those shown in FIG. 7, or have a different configuration from that shown in FIG. 7.
- a person of ordinary skill 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.
- 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 computer-readable storage medium.
- the technical solution of the present disclosure, 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 may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure.
- the disclosed client can be implemented in other ways.
- the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
- Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
- the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.
- each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or at least two units may be integrated into one unit.
- the above integrated unit may be implemented in the form of hardware or in the form of software functional units.
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Transfer Between Computers (AREA)
Abstract
本公开公开了一种组件间的消息传递方法和装置、存储介质及电子装置,涉及智能家居/智慧家庭技术领域,该方法包括:通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息;根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;在目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件;根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈用于指示目标发布消息是否已发布给了所有消息订阅组件的第一发布结果。
Description
本公开要求于2022年10月31日提交中国专利局、申请号为202211366283.2、发明名称“组件间的消息传递方法和装置、存储介质及电子装置”的中国专利申请的优先权,其全部内容通过引用结合在本公开中。
本公开涉及智能家居/智慧家庭技术领域,具体而言,涉及一种组件间的消息传递方法和装置、存储介质及电子装置。
目前,在嵌入式系统领域,通常按照现有通道进行数据传输,在系统内部实现消息分发与传递,使用的通道通常为消息队列。以两个独立的组件进行消息传递为例,两个组件分别创建自己的消息队列,并且各个组件对外各自提供一个写入自己消息队列的接口(即,写消息的接口、写消息队列接口),以实现两个组件之间的消息传递。但如果消息发送端想要将消息发送给多个接收端并且在发送完消息之后需要确认消息是否已被所有消息接收端所接收,需要将消息分别发送给各个消息接收端,并等待各个消息接收端返回的应答消息,组件的处理逻辑复杂,消息传递的效率较低。由此可见,相关技术中的组件间的消息传递方法,存在由于消息发送端需要分别向各个消息接收端发送消息并等待各个消息接收端的应答消息导致的组件的处理逻辑复杂、消息传递的效率低的问题。
发明内容
本公开实施例提供了一种组件间的消息传递方法和装置、存储介质及电子装置。
根据本公开实施例的一个方面,提供了一种组件间的消息传递方法,包括:通过目标设备的消息传递组件获取所述目标设备的消息发布组件所发布的目标 发布消息,其中,所述消息传递组件用于在所述目标设备的不同组件之间传递消息;根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件;在确定所述目标设备中存在订阅了所述目标发布消息的消息订阅组件、且所述消息发布组件指示将所述目标发布消息的发布结果反馈给所述消息发布组件的情况下,通过所述消息传递组件将所述目标发布消息传递给订阅了所述目标发布消息的每个消息订阅组件;根据在预设时间内所述目标发布消息已发布给的消息订阅组件,向所述消息发布组件反馈第一发布结果,其中,所述第一发布结果用于指示所述目标发布消息是否已发布给了所述目标发布消息的所有消息订阅组件。
根据本公开实施例的另一个方面,还提供了一种组件间的消息传递装置,包括:获取单元,设置为通过目标设备的消息传递组件获取所述目标设备的消息发布组件所发布的目标发布消息,其中,所述消息传递组件用于在所述目标设备的不同组件之间传递消息;第一确定单元,设置为根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件;传递单元,设置为在确定所述目标设备中存在订阅了所述目标发布消息的消息订阅组件、且所述消息发布组件指示将所述目标发布消息的发布结果反馈给所述消息发布组件的情况下,通过所述消息传递组件将所述目标发布消息传递给订阅了所述目标发布消息的每个消息订阅组件;第一反馈单元,设置为根据在预设时间内所述目标发布消息已发布给的消息订阅组件,向所述消息发布组件反馈第一发布结果,其中,所述第一发布结果用于指示所述目标发布消息是否已发布给了所述目标发布消息的所有消息订阅组件。
根据本公开实施例的又一方面,还提供了一种计算机可读的存储介质,该计算机可读的存储介质中存储有计算机程序,其中,该计算机程序被设置为运行时执行上述组件间的消息传递方法。
根据本公开实施例的又一方面,还提供了一种电子装置,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,上述处理器通过计算机程序执行上述的组件间的消息传递方法。
在本申请实施例中,采用由消息传递组件在不同组件之间传递消息、并由消息传递组件进行消息分发结果的统计、并将统计结果发送给消息分发组件的方式,通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息;根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件;根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件。
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本公开的实施例,并与说明书一起用于解释本公开的原理。
为了更清楚地说明本公开实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,对于本领域普通技术人员而言,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1是根据本公开实施例的一种组件间的消息传递方法的硬件环境示意图;
图2是根据本公开实施例的一种可选的组件间的消息传递方法的流程示意图;
图3是根据本公开实施例的另一种可选的组件间的消息传递方法的流程示意图;
图4是根据本公开实施例的一种可选的组件间的消息传递方法的示意图;
图5是根据本公开实施例的另一种可选的组件间的消息传递方法的示意图;
图6是根据本公开实施例的一种可选的组件间的消息传递装置的结构框图;
图7是根据本公开实施例的一种可选的电子装置的结构框图。
为了使本技术领域的人员更好地理解本公开方案,下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分的实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本公开保护的范围。
需要说明的是,本公开的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本公开的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
根据本公开实施例的一个方面,提供了一种组件间的消息传递方法。该组件间的消息传递方法广泛应用于智慧家庭(Smart Home)、智能家居、智能家用设备生态、智慧住宅(Intelligence House)生态等全屋智能数字化控制应用场景。可选地,在本实施例中,上述组件间的消息传递方法可以应用于如图1所示的由终端设备102和服务器104所构成的硬件环境中。如图1所示,服务器104通过网络与终端设备102进行连接,可用于为终端或终端上安装的客户端提供服务(如应用服务等),可在服务器上或独立于服务器设置数据库,用于为服务器104提供数据存储服务,可在服务器上或独立于服务器配置云计算和/或边缘计算服务,用于为服务器104提供数据运算服务。
上述网络可以包括但不限于以下至少之一:有线网络,无线网络。上述有线网络可以包括但不限于以下至少之一:广域网,城域网,局域网,上述无线网络 可以包括但不限于以下至少之一:WIFI(Wireless Fidelity,无线保真),蓝牙。终端设备102可以并不限定于为PC、手机、平板电脑、智能空调、智能烟机、智能冰箱、智能烤箱、智能炉灶、智能洗衣机、智能热水器、智能洗涤设备、智能洗碗机、智能投影设备、智能电视、智能晾衣架、智能窗帘、智能影音、智能插座、智能音响、智能音箱、智能新风设备、智能厨卫设备、智能卫浴设备、智能扫地机器人、智能擦窗机器人、智能拖地机器人、智能空气净化设备、智能蒸箱、智能微波炉、智能厨宝、智能净化器、智能饮水机、智能门锁等可以进行语音交互的语音设备。
本公开实施例的组件间的消息传递方法可以由服务器104来执行,也可以由终端设备102来执行,还可以是由服务器104和终端设备102共同执行。其中,终端设备102执行本公开实施例的组件间的消息传递方法也可以是由安装在其上的客户端来执行。
以由终端设备102来执行本实施例中的组件间的消息传递方法为例,图2是根据本公开实施例的一种可选的组件间的消息传递方法的流程示意图,如图2所示,该方法的流程可以包括以下步骤:
步骤S202,通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息。
本实施例中的组件间的消息传递方法可以应用到在目标设备的设备内部不同的组件之间进行消息分发与传递的场景。这里的目标设备上运行的操作系统可以是嵌入式系统的操作系统,其可以包括非实时操作系统和实时操作系统,例如,智能家居领域的智慧家庭的生态操作系统。嵌入式系统可以是包括硬件部分和软件部分,嵌入式系统的操作系统可以具有一般操作系统的核心功能,并负责嵌入式系统的全部软硬件资源的分配、调度工作控制、协调并发活动。目标设备可以是智能家居设备,也可以是其他类型的终端设备。
在嵌入式系统领域,在系统内部进行消息分发与传递的方式,通常是使用现有通道传输数据,所采用的通道可以是local socket(本地“套接字”,即本地网 络通信的接口)、消息队列等。以通过消息队列方式进行系统内部的两个独立的业务组件(例如,组件,可以是业务组件)之间进行消息的分发和传递为例,对于组件1和组件2,两个组件需要同时满足以下条件:各自有自己的消息队列和能够保证读写过程的原子性的锁机制;对外提供一个写消息队列的接口(即,写消息队列接口),可以让对方通过调用该接口来完成其他组件向自己的组件写消息队列的操作,写消息队列接口通过加锁进行原子化操作保护;各自有poll机制(相当于定时器,用于唤醒进程)循环的读取各自的队列,如果有消息写入,就读出消息进行处理。组件1可以通过调用组件2的写消息队列接口,实现向组件2发送消息的目的。
然而,上述组件间的消息传递方式,消息发布端(组件1)在调用消息接收端(组件2)的写消息队列接口将消息发布给消息接收端后,并不知道消息是否被消息接收端正常处理,对于消息发布端而言,只是将数据写到了消息接收端的消息队列,但并不知道消息接收端是否处理了传入的数据。如果消息发布端想要知道消息接收端已处理消息,需要消息接收端再向消息发布端反馈对应的应答。尤其是消息的一对多发布中,在消息发布端将消息发布给多个消息接收端之后,消息发布端需要等待各个消息接收端返回的应答消息。对应的统计过程较繁琐,处理逻辑复杂,消息的传递效率也较低。
为了至少部分解决上述问题,在本实施例中,可以设置一个消息代理端,用于在目标设备的不同组件之间传递消息。由消息代理端进行消息的代理发布,如果消息发布端需要知道是否所有的消息接收端都获取并处理完毕消息,可以由消息代理端进行发布结果的统计,并将消息是否已发布给所有消息接收端的发布结果反馈给消息发布端。消息代理端进行消息的代理发布,可以是基于订阅和发布方式完成的,消息接收端即为订阅消息的消息订阅组件,对应的消息发布端即为消息发布组件。这里,消息发布组件可以是特定消息类型的消息发布者,可以称为消息发布组件、发布者、发布方等,消息订阅组件可以是特定消息类型的消息接收者,可以是特定消息类型的订阅者,可以称为消息订阅组件、订阅者、订阅方等。消息代理端也称为消息传递组件、发布订阅组件等。
需要说明的是,消息接收端可以是独立的组件,也可以是依托于某个RTE环境(Run-Time Environment,运行时环境)的组件,RTE环境是指一段代码将要被执行时的一个特定的、独立的上下文环境,等同于一个独立线程。消息传递组件是不同于消息发布端和消息接收端的组件。在进行消息代理发布时,在获取到发布到消息传递组件的消息时,消息传递组件可以检索消息类型并发送到RTE环境执行的过程,如果没有RTE环境,可以直接执行消息接收端注册的回调函数的过程。在进行消息订阅时,消息订阅端可以利用发布订阅组件提供的消息订阅接口,执行订阅特定消息的动作,在系统内部消息分发时,消息发布端可以通过调用发布订阅组件提供的消息发布接口,执行消息发布的动作,将待发布的消息发布至消息传递组件,由消息传递组件完成分发和消息传递过程。由于消息的分发和分发结果的统计都由完成,消息发布组件只需要调用消息传递组件的对应接口,可以实现无需消息发送端分别向各个消息接收端发送消息并等待各个消息接收端的应答消息的目的。
消息传递组件对消息进行的代理发布的过程,可以是检索消息类型并发送到RTE环境执行的过程,如果没有RTE环境,可以直接执行消息接收组件注册的回调函数的过程。这里,回调函数可以是消息处理函数,消息相关内容可以以参数的形式传入该函数。在代理发布消息时对函数的调用和执行,可以实现消息接收组件获取对应消息,并做出相应的业务逻辑处理。回调函数的参数,即消息处理函数的参数,可以是消息订阅组件自定义确定的,由消息订阅组件按需选择用还是不用,如果有传入此参数,消息传递组件可以在调用消息处理函数时,将此参数带入,以满足消息订阅组件的特殊需求。在进行消息订阅时,消息订阅组件可以利用消息传递组件提供的消息订阅接口,执行订阅特定消息的动作,在系统内部消息分发时,消息发布组件可以利用消息传递组件提供的消息发布接口,执行消息发布的动作,由消息传递组件完成分发和消息传递过程。
在本实施例中,通过目标设备的消息传递组件可以获取目标设备的消息发布组件所发布的目标发布消息。这里,目标发布消息可以是第一组件发布的特定消息类型的消息,可以用于触发消息接收组件执行对应的业务,可以是消息发布组件通过调用消息传递组件的消息发布接口发布至消息传递组件的消息。
可选地,消息发布组件可以通过调用消息传递组件的消息发布接口,输入对应的参数数据,以完成将目标发布消息发布至消息传递组件。这里的参数数据可以包括:消息的类型,消息体内容,消息体长度等。消息的类型可以为消息标识,即消息ID(Identifier,标识),其可以是根据具体的业务逻辑需要定义出来的一个msg_id(message identity document,消息事件号)。消息体可以对应于消息数据(即,发布内容),可以是消息传递需求中,需要传递的结构化的消息内容,对应地,消息体长度是在需要传递消息体时所填写的要传递的消息数据的数据长度(不需要传递消息体可以填0)。消息体内容和消息体长度可以是可选项,由消息发布组件在需要传递结构化消息的场景下填写的内容。
步骤S204,根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件。
在系统内部可以基于消息标识进行消息传递,即,消息传递组件可以基于消息标识进行消息的分发与传递。目标设备上的组件可以通过消息标识订阅所关注的消息。为了方便消息传递组件进行消息分发,可以预先保存消息订阅信息,这里的消息订阅信息用于通过消息标识与组件标识之间的对应关系来表征消息标识所标识的发布消息的消息订阅组件,其可以是通过保存消息标识与组件标识之间的对应关系实现的。上述消息订阅信息可以保存在消息传递组件中,也可以保存在消息传递组件之外的其他存储资源中,但对应的存储资源的地址信息可以保存在消息传递组件中,以保证消息传递组件可以对保存的消息订阅信息进行查找。
在本实施例中,在接收到目标发布消息之后,消息传递组件可以根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件。确定目标设备中是否存在订阅目标发布消息的消息订阅组件的方式可以是:使用目标发布消息的消息标识查找已保存的消息订阅信息,在查找到与目标发布消息的消息标识对应的组件标识的情况下,可以确定存在订阅了目标发布消息的消息订阅组件,并可以将查找到的组件标识所标识的组件,确定为订阅了目标发布消息的消息订阅组件。
步骤S206,在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且 消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件。
如果消息发布组件想要知道目标消息已发布给了所有的消息传递组件,消息发布组件可以在发布目标发布消息至消息传递组件的过程中,在输入的参数数据中增加用于指示将目标发布消息的发布结果反馈给消息发布组件的指示信息,其可以是消息发布组件注册的发布应答处理回调和对应的发布应答回调参数。发布应答处理回调是按照消息发布组件的业务逻辑需求进行填写的。如果消息发布组件想要知道消息代理端(消息传递组件)是否将消息发布给了所有消息订阅组件这个事件,消息发布组件可以通过注册这个发布应答回调知道,在规定时间内这个消息是否已经被分发与传递到了所有的消息订阅组件。消息发布组件可以按照自己的业务逻辑需求选择是否使用并填写发布应答回调参数。如果填写了发布应答回调参数,发布应答回调参数可以在消息发布完成分发传递后调用发布应答回调时或者分发传递超时时,以函数参数的方式传入。
对于目标发布消息,在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,可以通过消息传递组件将目标发布消息分发(与传递)给订阅了目标发布消息的每个消息订阅组件。在目标发布消息的消息订阅组件的数量为多个的情况下,消息传递组件可以将目标发布消息分别传递给每个消息订阅组件。向不同的消息订阅组件传递目标发布消息的过程可以是并行执行的,也可以是串行执行的(即,依次向各个组件分发目标发布消息),本实施例中对此不做限定。
在向消息订阅组件传递目标发布消息时,如果对应的消息订阅组件中存在RTE环境,可以由消息订阅组件的RTE环境执行目标发布消息的分发,如果不存在RTE环境,可以由消息传递组件直接执行目标发布消息的分发。此外,在RTE环境执行目标发布消息的分发的过程中,消息传递组件可以执行其他操作,例如,接收其他组件发布的消息、根据消息对应的消息标识确定订阅消息的组件等工作。
上述将目标发布消息的分发至消息订阅组件的过程,可以是由上述RTE环境或消息传递组件执行消息处理函数的过程。由于消息处理函数的参数是各个消息传递组件根据自身的业务逻辑需求在订阅对应消息时注册到消息传递组件的,在代理发布过程中,调用执行对应的消息处理函数,即完成了将目标发布消息向对应的消息订阅组件的分发;同样地,通过消息订阅组件的消息处理函数对目标发布消息进行处理之后,即可以表示该消息订阅组件接收并处理了目标发布消息。目标发布消息的发布结果即为是否目标发布消息已发布给了所有的消息订阅组件的结果。
步骤S208,根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件。
对于发布结果的统计,可以预先设定一个时间,作为消息发布端本次消息发布后等待应答结果的最大时间,即发布后等待应答处理回调的超时时间,其可以是消息发布端由规定的,也可以采用默认值。在预设时间到达之前,如果目标发布消息已发布给了目标发布消息的所有消息订阅组件,可以直接反馈第一发布结果至消息发布组件,第一发布结果用于指示目标发布消息已发布给了目标发布消息的所有消息订阅组件;在预设时间到达时,如果还有目标发布消息未分发给的消息订阅组件,也可以停止代理发布和统计,并反馈第一发布结果至消息发布组件,第一发布结果用于指示目标发布消息未发布给目标发布消息的所有消息订阅组件,以在较短的时间内快速确定发布结果,可以及时释放对应的资源,并针对发布结果及时作出对应的策略调整。每次代理发布过程中,预设时间的到达,可以由定时器进行统计。定时器可以是在确定订阅信息后创建的,可以在根据订阅信息开始进行目标发布消息的分发时,启动定时器。
可选地,第一发布结果还可以用于指示目标发布消息已发布给的消息订阅组件和未发布给的消息订阅组件。由于每个消息订阅组件的订阅信息是已知的,因此,可以确定出哪些组件订阅了目标发布消息,从而可以统计出预设时间内目标发布消息已发布给的消息订阅组件和未发布给的消息订阅组件。考虑到本实施例 中通过消息传递组件进行消息发布组件和消息订阅组件的解耦,消息发布组件通常不关心订阅了其所发布的消息的组件,因此,也可以通过第一发布结果仅指示目标发布消息是否发布给了所有的消息订阅组件,也不指示目标发布消息向各个消息订阅组件的发布结果。
通过上述步骤S202至步骤S208,通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息;根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件;根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件,解决了相关技术中的组件间的消息传递方式存在由于消息发送端需要分别向各个消息接收端发送消息并等待各个消息接收端的应答消息导致的组件的处理逻辑复杂、消息传递的效率低的问题,简化了组件的处理逻辑,并提高了消息传递的效率。
在一个示例性实施例中,根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件,包括:
S11,使用目标消息标识查找订阅表,其中,订阅表用于记录已订阅消息的消息标识和与已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系,与已订阅消息的消息标识对应的信息链表用于存储与已订阅消息的消息订阅组件对应的订阅信息;
S12,在订阅表中查找到与目标消息标识对应的信息链表的表头地址的情况下,确定目标设备中存在订阅了目标发布消息的消息订阅组件;
S13,在订阅表中未查找到与目标消息标识对应的信息链表的表头地址的情况下,确定目标设备中不存在订阅了目标发布消息的消息订阅组件。
在本实施例中,为了提高消息订阅组件确定的便捷性,各个消息标识对应的订阅信息可以以信息链表的形式进行记录,不同的消息标识所对应的订阅信息可以通过不同的信息链表记录,这里,消息标识对应的订阅信息是指订阅了消息标识所标识的消息的组件对应的订阅信息。在信息链表中,可以存储与已订阅消息的消息订阅组件对应的订阅信息,同一消息的消息订阅组件对应的订阅信息可以存储在同一信息链表中。已订阅消息的消息标识和与已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系可以记录在订阅表中。这里映射关系可以是将消息标识和对应的信息链表的表头地址进行哈希映射后得到的关系。
可选地,在接收到目标发布消息之后,即,消息传递组件的发布接口被触发后,可以先判定订阅表的有效性,在订阅表无效的情况下,可以退出发布流程,在订阅表有效的情况下,可以继续进行发布流程,对订阅表进行查找等。这里,订阅表的有效性是指订阅表是否处于有效状态或者可用状态,可以表示订阅表中是否记录有已订阅消息的消息标识和与已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系,或者,订阅表中记录的映射关系是否可以被读取到。
目标发布消息的消息标识为目标消息标识,可以使用目标消息标识对订阅表进行查找。在查找到与目标消息标识对应的信息链表的表头地址的情况下,可以确定目标设备中存在订阅了目标发布消息的消息订阅组件。在订阅表中未查找到与目标消息标识对应的信息链表的表头地址的情况下,可以确定目标设备中不存在订阅了目标发布消息的消息订阅组件。
可选地,在查找到与目标消息标识对应的信息链表的表头地址的情况下,可以根据订阅表中记录的信息链表的表头地址,确定信息链表的表头位置,并通过遍历该信息链表中的链表节点确定订阅了目标发布消息的消息订阅组件,这里,信息链表中的一个链表节点用于记录与订阅了目标消息标识所标识的发布消息的一个消息订阅组件对应的订阅信息。此外,为了避免信息链表为空的情况,可以在查找到与目标消息标识对应的信息链表的表头地址之后,确定查找到的信息链表的深度;如果深度不为零,可以确定目标设备中存在订阅了目标发布消息的消息订阅组件;否则(未查找到信息链表的表头地址、或者查找到信息链表的表 头地址但查找到信息链表的深度为零),确定目标设备中不存在订阅了目标发布消息的消息订阅组件。
可选地,在确定存在订阅了目标发布消息的消息订阅组件的情况下,可以进行相关的数据处理和消息分发。在确定不存在订阅了目标发布消息的消息订阅组件的情况下,可以停止对目标发布消息进行其他操作,也可以将不存在订阅了目标发布消息的消息订阅组件的结果反馈给消息发布组件。
例如,以消息标识为msg_id为例,判定msg_id是否在订阅表中,如果不在,表示要代理发布的此消息没有订阅者(消息订阅组件,或称订阅方)。如果发布结果需要应答给发布者(消息发布组件,或称发布方),将发布应答结果改为”无人订阅”,调用应答回调通知发布结果;释放必要资源结束发布。如果不需要应答,释放必要资源后结束发布。
通过本实施例,通过记录消息标识和存储订阅信息的信息链表的表头地址之间的映射关系的订阅表,确定是否存在订阅了发布消息的消息订阅组件,可以提高查找和确定订阅信息的效率。
在一个示例性实施例中,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件,包括:
S21,在预设时间内,通过消息传递组件为每个消息订阅组件执行以下消息传递操作,以将目标发布消息传递给每个消息订阅组件,其中,在执行以下消息传递操作的过程中,每个消息订阅组件为当前订阅组件:
注册与当前订阅组件对应的执行函数体和与执行函数体对应的应答函数体,其中,执行函数体包含当前订阅组件注册的消息处理函数,执行函数体的参数包括目标发布消息中的发布信息;
依次执行执行函数体和应答函数体,其中,执行函数体用于按照消息处理函数对目标发布消息中的发布信息进行处理,应答函数体用于在执行函数体执行完成之后,将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
在本实施例中,在接收到目标发布消息之后,可以在预设时间内将目标发布 消息传递给目标发布消息的消息订阅组件。对于每个消息订阅组件,通过消息传递组件为每个消息订阅组件执行的消息传递操作可以包括:注册当前订阅组件对应的执行函数体(job)和与执行函数体对应的应答函数体(joback);依次执行上述执行函数体和应答函数体。在执行消息传递操作的过程中,每个消息订阅组件为当前订阅组件。
对于当前订阅组件(当前目标发布消息要传递给的消息订阅组件),上述执行函数体可以包含当前订阅组件注册的消息处理函数,可以用于按照消息处理函数对目标发布消息中的发布信息进行处理,执行函数体的参数可以包括目标发布消息中的发布信息(可以是消息体中的发布内容)。由于消息处理函数是由消息订阅组件注册的,其可以用于对目标发布消息执行消息订阅组件所需的处理操作,即,相当于相关技术中在将发布消息写入到消息订阅组件的消息队列之后,消息订阅组件从消息队列读取出目标发布消息之后对目标发布消息所进行的处理操作,执行函数体中的消息处理函数执行完毕,相当于目标发布消息已传递给消息订阅组件并执行完消息订阅组件所需的处理操作。
可选地,上述消息传递操作可以是在确定所有订阅了目标发布消息的消息订阅组件的订阅信息之后进行的;也可以是在确定部分订阅了目标发布消息的消息订阅组件的订阅信息后进行的,此时,目标发布消息的传递过程与消息订阅组件的订阅信息可以是并行执行,也可以是串行执行的。
在执行函数体执行完成之后,可以执行对应的应答函数体,以将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识,在应答函数体中包含了发布统计函数,还发布统计函数可以用于指示上述将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识的操作。由于目标发布消息的所有消息订阅组件是已知的,因此,可以为每个消息订阅组件设置对应的发布指示标识。可以基于预设时间内是否所有的发布指示标识已调整为发布完成的指示标识来确定预设时间内目标发布消息已发布给了所有的消息订阅组件。
通过本实施例,通过注册执行函数体和对应的应答函数体完成对发布消息的传递和发布结果的统计,可以提高消息传递的效率。
在一个示例性实施例中,依次执行执行函数体和应答函数体,包括:
S31,在当前订阅组件的运行时环境有效的情况下,通过调用当前订阅组件的运行时环境的接口将执行函数体和应答函数体传入当前订阅组件的运行时环境,以由当前订阅组件的运行时环境依次执行执行函数体和应答函数体;
S32,在当前订阅组件的运行时环境无效的情况下,由消息传递组件的运行时环境代理执行执行函数体和应答函数体。
对于执行函数体和应答函数体的执行,在当前订阅组件的运行时环境(即,RTE环境)有效的情况下,可以由消息订阅组件的运行时环境执行执行函数体和应答函数体,在当前订阅组件的运行时环境无效的情况下,可以由消息传递组件的运行时环境代理执行执行函数体和应答函数体。
在本实施例中,在当前订阅组件的运行时环境有效的情况下,可以通过调用当前订阅组件的运行时环境的接口将执行函数体和应答函数体传入当前订阅组件的运行时环境,以由当前订阅组件的运行时环境依次执行执行函数体和应答函数体。
可选地,在由当前订阅组件的运行时环境依次执行执行函数体和应答函数体的过程中,消息传递组件可以继续执行其他的操作,例如,可以继续进行与订阅了目标发布消息的消息订阅组件对应的订阅信息的查找、或者进行其他的消息接收、代理发布等操作。这里,当前订阅组件的运行时环境可以是在当前订阅组件订阅目标消息标识所标识的发布消息时指定的,如果未指定,则可以认为当前订阅组件的运行时环境无效。
例如,判定消息订阅组件的RTE环境是否有效,如果有效,可以注册一个执行体job和注册一个执行体的应答joback。将job和joback通过调用RTE环境的接口让RTE环境去执行job和joback。在RTE环境执行job是个异步处理过程,相当于将要发布的消息做了一个副本完整的交给了RTE环境的上下文中去执行消息处理函数,消息传递组件让RTE环境开始执行job后即可进行循环遍历(这里的遍历可以包括遍历信息链表中的链表节点),而RTE环境在执行完执行体 job中的消息处理函数,会调用joback函数(即,发布统计函数),以进行发布结果的统计。
在本实施例中,在当前订阅组件的运行时环境无效的情况下,可以继续确定当前订阅组件的消息处理函数是否有效,在对应的消息处理函数有效的情况下,可以由消息传递组件的运行时环境代理执行执行函数体和应答函数体。
例如,如果当前消息订阅组件的RTE环境判定为无效的,则继续判断当前消息订阅组件的消息处理函数的有效性,无效则继续循环遍历。如果当前消息订阅组件的消息处理函数是有效的,则由消息传递组件代理执行消息处理函数。
通过本实施例,通过使用运行时环境执行消息的分发和发布结果的统计,可以为同时处理其他消息的接收和分发,从而提高消息处理的效率。
在一个示例性实施例中,依次执行执行函数体和应答函数体,包括:
S41,将目标发布消息中的发布信息以及当前订阅组件所指定的参数传入执行函数体,以执行执行函数体;
S42,在执行函数体执行完成之后,触发执行应答函数体,以将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
在本实施例中,执行上述执行函数体的过程可以是:将目标发布消息中的发布信息以及当前订阅组件所指定的参数传入执行函数体。这里,消息订阅组件在进行消息订阅时,可以执行消息处理函数的参数,其可以是消息订阅组件自定义使用的函数,消息订阅组件可以按需选择用还是不用。如果有传入此参数,消息传递组件可以在调用消息处理函数时,将此参数带入,以满足消息订阅组件的特殊需求。
在执行函数体执行完成之后,可以触发执行应答函数体,以将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识。这里的指示标识可以用于指示目标发布消息是否已发布给了当前订阅组件,可以用比特位进行表示。当前订阅组件对应的发布指示标识在执行函数体执行完毕前后,可以有明显的区别,以区分目标发布消息是否已发布给了当前订阅组件。
可选地,消息传递组件可以确定与订阅了目标发布消息的每个消息订阅组件对应的订阅信息,还可以为每个消息订阅组件设置一个对应的索引值(index),用索引值区分本次发布遍历到第几个消息订阅组件。同时,可以申请一段内存对索引值进行缓存。在该内存中,可以同时设置有索引值对应的发布指示标识。该内存,即缓存发布索引的内存,可以用于统计发布结果。在统计发布结果时,可以根据各个消息订阅组件的发布指示标识来确定目标发布消息已发布给了所有的消息订阅组件。
例如,可以遍历订阅者链表uhos_list_t(即,上述信息链表),逐个拿到订阅者信息,索引值(index)自加。此外,还可以申请一段内存用于缓存发布索引,用于统计发布结果。
通过本实施例,将发布内容以及消息订阅组件所指定的参数传入执行函数体,已按照消息订阅组件所执行的参数对发布内容进行处理,可以满足不同消息订阅组件的处理需求,可以提高发布消息处理的灵活性。
在一个示例性实施例中,依次执行执行函数体和应答函数体,包括:
S51,执行执行函数体,以按照消息处理函数对目标发布消息中的发布信息进行处理;
S52,在执行函数体执行完成之后,触发执行应答函数体,以将发布统计结果中与当前订阅组件对应的比特位的值由第一值调整为第二值,其中,发布统计结果中的一个比特位对应于目标发布消息的一个消息订阅组件,第一值用于指示目标发布消息未发布给对应的消息订阅组件,第二值用于指示目标发布消息已发布给了对应的消息订阅组件。
执行函数体的执行过程可以是:将目标发布消息中的发布信息传入执行函数体,执行上述执行函数体,以按照消息处理函数对目标发布消息中的发布信息进行处理。此外,传入执行函数体的参数还可以包含消息订阅组件所指定的参数。在执行函数体执行完成之后,可以触发执行应答函数体。
在本实施例中,可以通过该发布统计结果中的不同比特位统计不同消息订阅 组件的发布结果,即,发布统计结果中的一个比特位对应于目标发布消息的一个消息订阅组件,一个比特位通常具有两个值(0和1),其中,两个值中的第一值(0或者1)用于指示目标发布消息未发布给对应的消息订阅组件,两个值中的第二值(1或者0)用于指示目标发布消息已发布给了对应的消息订阅组件。为了便于区别,可以将第一值设置为1,第二值设置为0。
通过本实施例,通过执行应答函数体,将发布统计结果中与当前订阅组件对应的比特位的值由第一值调整为第二值,可以便于对发布结果的统计,提高发布结果统计的效率。
在一个示例性实施例中,在触发执行应答函数体之后,上述方法还包括:
S61,根据目标发布消息的目标序列号在发布表中查找与目标序列号对应的发布句柄,其中,目标序列号用于唯一标识目标发布消息的发布流程,发布表用于记录发布消息的序列号和发布消息的发布句柄之间的映射关系,发布句柄用于指示对应的发布消息的内存地址;
S62,在查找到与目标发布消息对应的目标发布句柄的情况下,跳转至目标发布句柄所关联的目标内存指针所指向的内存,得到发布统计结果,其中,目标内存指针为存储发布统计结果的内存的指针;
S63,根据当前订阅组件所对应的当前索引值,将发布统计结果中与当前索引值对应的比特位的值由第一值调整为第二值,其中,当前索引值用于表示与当前索引值对应的比特位在发布统计结果中的位置;其中,应答函数体的参数包括目标序列号和当前索引值。
为了便于对发布结果进行统计,避免将不同发布过程的发布结果混合,每次发布过程都可以产生一个唯一的序列号(Serial Number),即,发布应答关联SN号,用于区别前后发布的调用。SN号可以贯穿一次发布过程的全周期,在一次发布过程完成或发布超时完成后,SN号可以伴随相关资源的释放而释放。
发布消息的序列号可以是在获取到消息发布组件发布的发布消息之后产生的,也可以是在确定有组件订阅了发布消息之后产生的,还可以是在其他时机生 成的。此外,对于接收到的发布消息,可以申请一段内存缓存发布消息,得到一个发布句柄(uh_publish_handler_t),得到的发布句柄可以指示对应的发布消息缓存的内存地址。
对于目标发布消息,为其产生的序列号为目标序列号,目标发布消息的发布句柄可以是与目标序列号对应的发布句柄,即,目标发布句柄。在根据目标消息标识确定目标设备中存在订阅了目标发布消息的消息订阅组件的情况下,可以将产生的目标序列号与目标发布句柄进行映射,并在发布表中记录目标序列号和目标发布句柄之间的映射关系。
这里,发布表中可以记录发布消息的序列号和发布消息的发布句柄之间的映射关系,可以在发布过程保证发布过程的完整性。每次发布的过程会产生一个唯一的序列号SN,在发布开始时,可以利用SN和当前要发布的内容的发布句柄做一次映射,在发布完毕和/或发布超时后解除映射关系。在消息发布接口被触发后,可以先判定订阅表和发布表的有效性,两者均有效时,可以执行后续的发布过程,否则,任何一个无效则退出发布过程。
可选地,对于上述通过订阅表记录已订阅消息的消息标识和与已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系的场景,可以在订阅表中查找到与目标消息标识对应的信息链表的表头地址的情况下,产生上述目标序列号(目标序列号也可以是在接收到目标发布消息、或者判定订阅表和发布表均有效时产生),并将其和对应的发布句柄映射到发布表中(可以通过key-value的形式保存,其中,key为消息标识,value为发布句柄)。
例如,在订阅表和发布表均有效时,判定msg_id是否在订阅表中,如果表中存在此msg_id的映射,即此消息有订阅者,可以产生一个唯一SN,并将其和发布句柄uh_publish_handler_t映射到发布表。
在订阅表中查找到目标消息标识对应的信息链表的表头地址的情况下,可以将查找到的表头地址赋值给目标发布句柄关联的订阅信息。由于可以根据信息链表的表头地址查找到每个消息订阅组件对应的订阅信息,从而确定相关的消息处理函数,赋值完成后可以代理进行消息的分发和传递。此外,还可以创建一个定 时器,并将其赋值给发布句柄,定时器的定时时间为上述预设时间,并启动定时器。在对发布结果进行统计的过程中,在确定预设时间内将目标发布消息分发给所有消息订阅组件的情况下,可以利用目标发布句柄停止定时器,同时,在定时器超时时,也可以基于与目标发布句柄之间的对应关系确定要停止的发布流程。对于前述申请的统计发布结果的内存,可以将内存的指针关联到发布句柄,并将各个索引值(index)对应的统计结果的bit位置为第一值(例如,1)。这里的赋值可以是在发布表中通过指针指向对应的对象的内存地址,例如,表头地址、定时器的内存地址等。
例如,根据msg_id查订阅表,获取到信息链表的链表头uhos_list_t,将其赋值给发布句柄关联的订阅信息(赋值给uh_publish_handler_t->m_list_subcribe),此为要消息代理端进行消息分发和传递的目的信息,相关消息处理函数都在此表头中。
可选地,应答函数体的参数可以包括目标序列号和当前消息订阅组件的索引值,即,当前索引值。在执行应答函数体的过程中,可以根据目标发布消息的目标序列号在发布表中查找与目标序列号对应的发布句柄。这里,目标序列号可以是用于唯一标识目标发布消息的发布流程的序列号。在查找到与目标发布消息对应的目标发布句柄的情况下,可以跳转至目标发布句柄所关联的目标内存指针所指向的内存,得到发布统计结果。这里,目标内存指针可以为存储发布统计结果的内存的指针,即,前述缓存发布索引的内存。每个索引值可以对应于发布统计结果中的一个比特位,可以将将发布统计结果中与当前索引值对应的比特位的值由第一值调整为第二值。这里,当前索引值可以用于表示与当前索引值对应的比特位在发布统计结果中的位置。
例如,以由RTE环境执行应答函数体joback为例,如图3所示,RTE环境调用joback触发,应答统计处理流程开始。利用joback的参数中的SN反查发布句柄,根据joback参数中的索引值修改发布句柄统计结果,将对应的比特位清零。
通过本实施例,在执行应答函数体的过程中,通过序列号确定发布句柄,在根据发布句柄关联的信息确定记录发布统计结果的地址,可以提高发布统计结果 的准确性。
在一个示例性实施例中,上述方法还包括:
S71,依次遍历与目标消息标识对应的目标信息链表的每个链表节点,得到与每个消息订阅组件对应的订阅信息、以及与每个消息订阅组件对应的索引值,其中,每个链表节点中存储有与目标消息标识所标识的消息的一个消息订阅组件对应的订阅信息,与每个消息订阅组件对应的索引值是根据每个消息订阅组件遍历到的顺序生成的。
对于索引值的确定,可以是在依次遍历与消息标识对应的信息链表,得到与每个消息订阅组件对应的订阅信息的情况下确定的。与每个消息订阅组件对应的索引值可以是根据每个消息订阅组件遍历到的顺序生成的。与目标消息标识对应的信息链表为目标信息链表,可以依次遍历目标信息链表中的每个链表节点,得到与每个消息订阅组件对应的订阅信息、以及与每个消息订阅组件对应的索引值。这里,每个链表节点中可以存储有与目标消息标识所标识的消息的一个消息订阅组件对应的订阅信息。不同的链表节点所存储的订阅信息至少部分不同,即,可以部分相同但不完全相同。发布统计结果中的比特位数可以是根据消息订阅组件的索引值所配置的,即,索引值如果加1,则发布统计结果中的比特位数也加1。
例如,根据遍历顺序,将每个遍历到的消息订阅组件设置一个对应的索引值,用索引值区分本次发布遍历到第几个消息订阅组件。索引值可以自加,第一个遍历到的消息订阅组件的索引值可以为0,则第二个遍历到的消息订阅组件的索引值为1,第三个遍历到的消息订阅组件的索引值为2,以此类推……
通过本实施例,根据确定消息订阅组件的顺序确定消息订阅组件的索引值,可以避免因消息订阅组件过多而出现比特位修改错误的情况,从而提高发布统计结果的准确性。
在一个示例性实施例中,在触发执行应答函数体之后,上述方法还包括:
S81,在发布统计结果中的所有比特位均为第二值的情况下,确定目标发布消息已发布给了目标发布消息的所有消息订阅组件;
S82,在发布统计结果中的至少部分比特位为第一值的情况下,确定目标发布消息未发布给目标发布消息的至少部分消息订阅组件。
在本实施例中,根据发布统计结果中的所有比特位的值,可以确定目标发布消息是否已发布给了目标发布消息的所有消息订阅组件。在发布统计结果中的所有比特位均为第二值的情况下,可以确定目标发布消息已发布给了目标发布消息的所有消息订阅组件。在发布统计结果中的至少部分比特位为第一值的情况下,可以确定目标发布消息未发布给目标发布消息的至少部分消息订阅组件。
在每次触发执行应答函数体之后,均可以执行一次发布统计结果的判定过程。比如,应答函数体中的发布统计函数每次执行时均会确定发布统计结果中的所有比特位均为第二值,如果是,即使定时器未超时,也会结束发布流程。此外,如果定时器超时,及时有应答函数体未被触发,也会结束发布流程。
例如,在统计结果非全零情况下,表示未发布完毕,统计函数可以返回。在统计结果全零情况下,利用发布句柄停止定时器,
可选地,对于比特位的第一值为1,第二值为0的情况,如图3所示,在触发joback将统计结果中对应的比特位清零之后,遍历统计结果是否全零。在发布统计结果全零时,可以确定目标发布消息发布完毕,已订阅目标发布消息的所有消息订阅组件均接收并处理了目标发布消息,可以利用发布句柄停止定时器。如果发布应答接口有效(即,发布者关注发布结果)时,可以调用发布应答接口,将发布结果反馈给发布者,释放资源,解除发布SN关联的映射关系,并释放发布句柄。在发布统计结果非全零时,标识未发布完毕,发布统计函数可以返回。
通过本实施例,在每次执行应答函数体之后通过确定发布统计结果中所有的比特位的值判断发布消息是否发布给了所有的消息订阅组件,可以提高发布消息的发布结果的效率。
在一个示例性实施例中,在根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件之后,上述方法还包括:
S91,在确定目标设备中不存在订阅了目标发布消息的消息订阅组件、且消 息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件向消息发布组件反馈第二发布结果,其中,第二发布结果用于指示目标设备中没有组件订阅目标发布消息。
在本实施例中,对于根据接收到的目标发布消息,确定目标设备中不存在订阅了目标发布消息的消息订阅组件的情况,如果消息发布组件未指示将目标发布消息的发布结果反馈给消息发布组件,则可以直接结束发布流程。如果消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件,可以通过消息传递组件向消息发布组件反馈第二发布结果。这里,第二发布结果用于指示目标设备中没有组件订阅目标发布消息。
例如,如图4所示,消息发布组件可以通过调用消息发布接口传入待发布的消息,消息的相关参数可以包括:uh_msg_id_t(消息类型),msg_data(消息体),msg_data_len(消息长度),fn_publish_ack_routine(发布后应答处理回调),fn_param(回调参数),ack_fn_timeout_ms(发布后等待应答处理回调的超时时间),uh_publish_ack_sn_t(发布应答sn(调用者不可见))等。在确定订阅表、发布应答表(即,发布表)有效的情况下,可以判定msg_id是否在订阅表中,如果不在,表示要代理发布的此消息没有消息订阅组件。如果发布结果需要应答给消息发布组件,将发布应答结果改为“无人订阅”,调用应答回调通知发布结果,释放必要资源结束发布,如果不需要应答,直接释放必要资源结束发布。
通过本实施例,在确定发布消息没有消息订阅组件的情况下,将发布结果反馈至消息发布组件并结束发布,可以提高消息的传递效率。
下面结合可选示例对本公开实施例中的组件间的消息传递方法进行解释说明。在本可选示例中,消息订阅组件为订阅者,消息发布组件为发布者,消息传递组件为发布订阅组件,消息标识为msg_id,第一值为1,第二值为0。
本可选示例中提供了一种消息发布流程,发布者在消息发布时注册一个发布结果通知函数,在消息代理发布完毕后调用此函数,则可以获得消息的发布统计结果。避免了一对多传输消息时,每个订阅者都要应答处理结果,且需要发布者自己根据应答统计布统计结果的繁琐过程。
如图5所示,本可选示例中的组件间的消息传递方法的流程可以包括以下步骤:
步骤1,如果msg_id在订阅表中,将序列号和发布句柄映射到发布应答表(即,发布表)。
在消息发布接口被触发后,可以采用与图4中类似的方式判定订阅表和发布表的有效性、以及msg_id是否在订阅表中,如果不在订阅表中,执行图4中的处理流程。如果在,可以根据msg_id查找订阅表,确定消息订阅组件的链表头,并赋值给发布句柄。
步骤2,根据msg_id查找订阅表,确定消息订阅组件的链表头,赋值给发布句柄。
步骤3,创建定时器,并开启定时器,消息的分发流程从此开始。
步骤3,遍历链表,逐个确定订阅者信息(即,订阅信息)和索引值。
步骤4,注册执行体job和应答执行体joback,在RTE环境有效的情况下,通过调用RTE的接口,由RTE执行job和joback。
步骤5,在RTE环境无效的情况下,确定消息处理函数是否有效,在消息处理函数有效的情况下,由发布订阅组件执行消息处理函数,并将对应索引值结果数组中比特位清零,同时,继续遍历订阅者信息。
步骤6,在定时器的时间到达或者统计结果全零的情况下,利用发布句柄调用发布应答接口,将结果反馈给发布者,资源释放,并解除发布映射关系,释放发布句柄。
传统的通讯方式,消息发送后要确认对方是否接收到了消息,需要对方做出针对该消息的应答。通过本可选示例,消息发布后,对于发布者需要知道是否被接收处理结果的情况,可以通过发布接口注册一个结果回调通知接口即可实现,不用再关注每一个消息接收方的所有的应答,消息代理方法代理了应答统计工作,这种设计对于组件的使用者更友好,且更省资源。
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本公开并不受所描述的动作顺序的限制,因为依据本公开,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本公开所必须的。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM(Read-Only Memory,只读存储器)/RAM(Random Access Memory,随机存取存储器)、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本公开各个实施例的方法。
根据本公开实施例的另一个方面,还提供了一种用于实施上述组件间的消息传递方法的组件间的消息传递装置。图6是根据本公开实施例的一种可选的组件间的消息传递装置的结构框图,如图6所示,该装置可以包括:
获取单元602,设置为通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息;
第一确定单元604,与获取单元602相连,设置为根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;
传递单元606,与第一确定单元604相连,设置为在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果应答给消息发布组件的情况下,通过消息传递组件将目标发布消息分发给订阅了目标发布消息的每个消息订阅组件;
第一反馈单元608,与传递单元606相连,设置为根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件发送第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件。
需要说明的是,该实施例中的获取单元602可以用于执行上述步骤S202,该实施例中的第一确定单元604可以用于执行上述步骤S204,该实施例中的传递单元606可以用于执行上述步骤S206,该实施例中的第一反馈单元608可以用于执行上述步骤S208。
通过上述模块,通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息;根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件;根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件,解决了相关技术中的组件间的消息传递方式存在由于消息发送端需要分别向各个消息接收端发送消息并等待各个消息接收端的应答消息导致的组件的处理逻辑复杂、消息传递的效率低的问题,提高了简化了组件的处理逻辑,并提高了消息传递的效率。
在一个示例性实施例中,第一确定单元包括:
查找模块,设置为使用目标消息标识查找订阅表,其中,订阅表用于记录已订阅消息的消息标识和与已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系,与已订阅消息的消息标识对应的信息链表用于存储与已订阅消息的消息订阅组件对应的订阅信息;
第一确定模块,设置为在订阅表中查找到与目标消息标识对应的信息链表的表头地址的情况下,确定目标设备中存在订阅了目标发布消息的消息订阅组件;
第二确定模块,设置为在订阅表中未查找到与目标消息标识对应的信息链表的表头地址的情况下,确定目标设备中不存在订阅了目标发布消息的消息订阅组件。
在一个示例性实施例中,传递单元包括:
执行模块,设置为在预设时间内,通过消息传递组件为每个消息订阅组件执行以下消息传递操作,以将目标发布消息传递给每个消息订阅组件,其中,在执行以下消息传递操作的过程中,每个消息订阅组件为当前订阅组件:
注册与当前订阅组件对应的执行函数体和与执行函数体对应的应答函数体,其中,执行函数体包含当前订阅组件注册的消息处理函数,执行函数体的参数包括目标发布消息中的发布信息;
依次执行执行函数体和应答函数体,其中,执行函数体用于按照消息处理函数对目标发布消息中的发布信息进行处理,应答函数体用于在执行函数体执行完成之后,将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
在一个示例性实施例中,执行模块包括:
第一传入子模块,设置为在当前订阅组件的运行时环境有效的情况下,通过调用当前订阅组件的运行时环境的接口将执行函数体和应答函数体传入当前订阅组件的运行时环境,以由当前订阅组件的运行时环境依次执行执行函数体和应答函数体;
第一执行子模块,设置为在当前订阅组件的运行时环境无效的情况下,由消息传递组件的运行时环境代理执行执行函数体和应答函数体。
在一个示例性实施例中,执行模块包括:
第二传入子模块,设置为将目标发布消息中的发布信息以及当前订阅组件所指定的参数传入执行函数体,以执行执行函数体;
第二执行子模块,设置为在执行函数体执行完成之后,触发执行应答函数体,以将与当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
在一个示例性实施例中,执行模块包括:
第三执行子模块,设置为执行执行函数体,以按照消息处理函数对目标发布消息中的发布信息进行处理;
第四执行子模块,设置为在执行函数体执行完成之后,触发执行应答函数体,以将发布统计结果中与当前订阅组件对应的比特位的值由第一值调整为第二值,其中,发布统计结果中的一个比特位对应于目标发布消息的一个消息订阅组件,第一值用于指示目标发布消息未发布给对应的消息订阅组件,第二值用于指示目标发布消息已发布给了对应的消息订阅组件。
在一个示例性实施例中,上述装置还包括:
查找单元,设置为在触发执行应答函数体之后,根据目标发布消息的目标序列号在发布表中查找与目标序列号对应的发布句柄,其中,目标序列号用于唯一标识目标发布消息的发布流程,发布表用于记录发布消息的序列号和发布消息的发布句柄之间的映射关系,发布句柄用于指示对应的发布消息的内存地址;
跳转单元,设置为在查找到与目标发布消息对应的目标发布句柄的情况下,跳转至目标发布句柄所关联的目标内存指针所指向的内存,得到发布统计结果,其中,目标内存指针为存储发布统计结果的内存的指针;
调整单元,设置为根据当前订阅组件所对应的当前索引值,将发布统计结果中与当前索引值对应的比特位的值由第一值调整为第二值,其中,当前索引值用于表示与当前索引值对应的比特位在发布统计结果中的位置;
其中,应答函数体的参数包括目标序列号和当前索引值。
在一个示例性实施例中,上述装置还包括:
遍历单元,设置为依次遍历与目标消息标识对应的目标信息链表的每个链表节点,得到与每个消息订阅组件对应的订阅信息、以及与每个消息订阅组件对应的索引值,其中,每个链表节点中存储有与目标消息标识所标识的消息的一个消息订阅组件对应的订阅信息,与每个消息订阅组件对应的索引值是根据每个消息 订阅组件遍历到的顺序生成的。
在一个示例性实施例中,上述装置还包括:
第二确定单元,设置为在触发执行应答函数体之后,在发布统计结果中的所有比特位均为第二值的情况下,确定目标发布消息已发布给了目标发布消息的所有消息订阅组件;
第三确定单元,设置为在发布统计结果中的至少部分比特位为第一值的情况下,确定目标发布消息未发布给目标发布消息的至少部分消息订阅组件。
在一个示例性实施例中,在根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件之后,上述装置还包括:
第二反馈单元,设置为在根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件之后,在确定目标设备中不存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件向消息发布组件反馈第二发布结果,其中,第二发布结果用于指示目标设备中没有组件订阅目标发布消息。
此处需要说明的是,上述模块与对应的步骤所实现的示例和应用场景相同,但不限于上述实施例所公开的内容。需要说明的是,上述模块作为装置的一部分可以运行在如图1所示的硬件环境中,可以通过软件实现,也可以通过硬件实现,其中,硬件环境包括网络环境。
根据本公开实施例的又一个方面,还提供了一种存储介质。可选地,在本实施例中,上述存储介质可以用于执行本公开实施例中上述任一项组件间的消息传递方法的程序代码。
可选地,在本实施例中,上述存储介质可以位于上述实施例所示的网络中的多个网络设备中的至少一个网络设备上。
可选地,在本实施例中,存储介质被设置为存储用于执行以下步骤的程序代码:
S1,通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息;
S2,根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;
S3,在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件;
S4,根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件。
可选地,本实施例中的具体示例可以参考上述实施例中所描述的示例,本实施例中对此不再赘述。
可选地,在本实施例中,上述存储介质可以包括但不限于:U盘、ROM、RAM、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
根据本公开实施例的又一个方面,还提供了一种用于实施上述组件间的消息传递方法的电子装置,该电子装置可以是服务器、终端、或者其组合。
图7是根据本公开实施例的一种可选的电子装置的结构框图,如图7所示,包括处理器702、通信接口704、存储器706和通信总线708,其中,处理器702、通信接口704和存储器706通过通信总线708完成相互间的通信,其中,
存储器706,用于存储计算机程序;
处理器702,用于执行存储器706上所存放的计算机程序时,实现如下步骤:
S1,通过目标设备的消息传递组件获取目标设备的消息发布组件所发布的目标发布消息,其中,消息传递组件用于在目标设备的不同组件之间传递消息;
S2,根据目标发布消息的目标消息标识,确定目标设备中是否存在订阅了目标发布消息的消息订阅组件;
S3,在确定目标设备中存在订阅了目标发布消息的消息订阅组件、且消息发布组件指示将目标发布消息的发布结果反馈给消息发布组件的情况下,通过消息传递组件将目标发布消息传递给订阅了目标发布消息的每个消息订阅组件;
S4,根据在预设时间内目标发布消息已发布给的消息订阅组件,向消息发布组件反馈第一发布结果,其中,第一发布结果用于指示目标发布消息是否已发布给了目标发布消息的所有消息订阅组件。
可选地,通信总线可以是PCI(Peripheral Component Interconnect,外设部件互连标准)总线、或EISA(Extended Industry Standard Architecture,扩展工业标准结构)总线等。该通信总线可以分为地址总线、数据总线、控制总线等。为便于表示,图7中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。通信接口用于上述电子装置与其他设备之间的通信。
存储器可以包括RAM,也可以包括非易失性存储器(non-volatile memory),例如,至少一个磁盘存储器。可选地,存储器还可以是至少一个位于远离前述处理器的存储装置。
作为一种示例,上述存储器706中可以但不限于包括上述组件间的消息传递装置中的获取单元602、第一确定单元604、传递单元606和第一反馈单元608。此外,还可以包括但不限于上述组件间的消息传递装置中的其他模块单元,本示例中不再赘述。
上述处理器可以是通用处理器,可以包含但不限于:CPU(Central Processing Unit,中央处理器)、NP(Network Processor,网络处理器)等;还可以是DSP(Digital Signal Processing,数字信号处理器)、ASIC(Application Specific Integrated Circuit,专用集成电路)、FPGA(Field-Programmable Gate Array,现场可编程门阵列)或 者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。
可选地,本实施例中的具体示例可以参考上述实施例中所描述的示例,本实施例在此不再赘述。
本领域普通技术人员可以理解,图7所示的结构仅为示意,实施上述组件间的消息传递方法的设备可以是终端设备,该终端设备可以是智能手机(如Android手机、iOS手机等)、平板电脑、掌上电脑以及移动互联网设备(Mobile Internet Devices,MID)、PAD等终端设备。图7其并不对上述电子装置的结构造成限定。例如,电子装置还可包括比图7中所示更多或者更少的组件(如网络接口、显示装置等),或者具有与图7所示的不同的配置。
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令终端设备相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:闪存盘、ROM、RAM、磁盘或光盘等。
上述本公开实施例序号仅仅为了描述,不代表实施例的优劣。
上述实施例中的集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在上述计算机可读取的存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在存储介质中,包括若干指令用以使得一台或多台计算机设备(可为个人计算机、服务器或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。
在本公开的上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。
在本公开所提供的几个实施例中,应该理解到,所揭露的客户端,可通过其它的方式实现。其中,以上所描述的装置实施例仅仅是示意性的,例如所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通 过一些接口,单元或模块的间接耦合或通信连接,可以是电性或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例中所提供的方案的目的。
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以至少两个单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
以上所述仅是本公开的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本公开原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本公开的保护范围。
Claims (22)
- 一种组件间的消息传递方法,包括:通过目标设备的消息传递组件获取所述目标设备的消息发布组件所发布的目标发布消息,其中,所述消息传递组件用于在所述目标设备的不同组件之间传递消息;根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件;在确定所述目标设备中存在订阅了所述目标发布消息的消息订阅组件、且所述消息发布组件指示将所述目标发布消息的发布结果反馈给所述消息发布组件的情况下,通过所述消息传递组件将所述目标发布消息传递给订阅了所述目标发布消息的每个消息订阅组件;根据在预设时间内所述目标发布消息已发布给的消息订阅组件,向所述消息发布组件反馈第一发布结果,其中,所述第一发布结果用于指示所述目标发布消息是否已发布给了所述目标发布消息的所有消息订阅组件。
- 根据权利要求1所述的方法,其中,所述根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件,包括:使用所述目标消息标识查找订阅表,其中,所述订阅表用于记录已订阅消息的消息标识和与所述已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系,与所述已订阅消息的消息标识对应的信息链表用于存储与所述已订阅消息的消息订阅组件对应的订阅信息;在所述订阅表中查找到与所述目标消息标识对应的信息链表的表头地址的情况下,确定所述目标设备中存在订阅了所述目标发布消息的消息订阅组件;在所述订阅表中未查找到与所述目标消息标识对应的信息链表的表头地址的情况下,确定所述目标设备中不存在订阅了所述目标发布消息的消息订阅组件。
- 根据权利要求1所述的方法,其中,所述通过所述消息传递组件将所述目标发 布消息传递给订阅了所述目标发布消息的每个消息订阅组件,包括:在所述预设时间内,通过所述消息传递组件为所述每个消息订阅组件执行以下消息传递操作,以将所述目标发布消息传递给所述每个消息订阅组件,其中,在执行以下消息传递操作的过程中,所述每个消息订阅组件为当前订阅组件:注册与所述当前订阅组件对应的执行函数体和与所述执行函数体对应的应答函数体,其中,所述执行函数体包含所述当前订阅组件注册的消息处理函数,所述执行函数体的参数包括所述目标发布消息中的发布信息;依次执行所述执行函数体和所述应答函数体,其中,所述执行函数体用于按照所述消息处理函数对所述目标发布消息中的发布信息进行处理,所述应答函数体用于在所述执行函数体执行完成之后,将与所述当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
- 根据权利要求3所述的方法,其中,所述依次执行所述执行函数体和所述应答函数体,包括:在所述当前订阅组件的运行时环境有效的情况下,通过调用所述当前订阅组件的运行时环境的接口将所述执行函数体和所述应答函数体传入所述当前订阅组件的运行时环境,以由所述当前订阅组件的运行时环境依次执行所述执行函数体和所述应答函数体;在所述当前订阅组件的运行时环境无效的情况下,由所述消息传递组件的运行时环境代理执行所述执行函数体和所述应答函数体。
- 根据权利要求3所述的方法,其中,所述依次执行所述执行函数体和所述应答函数体,包括:将所述目标发布消息中的发布信息以及所述当前订阅组件所指定的参数传入所述执行函数体,以执行所述执行函数体;在所述执行函数体执行完成之后,触发执行所述应答函数体,以将与所述当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
- 根据权利要求3所述的方法,其中,所述依次执行所述执行函数体和所述应答 函数体,包括:执行所述执行函数体,以按照所述消息处理函数对所述目标发布消息中的发布信息进行处理;在所述执行函数体执行完成之后,触发执行所述应答函数体,以将发布统计结果中与所述当前订阅组件对应的比特位的值由第一值调整为第二值,其中,所述发布统计结果中的一个比特位对应于所述目标发布消息的一个消息订阅组件,所述第一值用于指示所述目标发布消息未发布给对应的消息订阅组件,所述第二值用于指示所述目标发布消息已发布给了对应的消息订阅组件。
- 根据权利要求6所述的方法,其中,在触发执行所述应答函数体之后,所述方法还包括:根据所述目标发布消息的目标序列号在发布表中查找与所述目标序列号对应的发布句柄,其中,所述目标序列号用于唯一标识所述目标发布消息的发布流程,所述发布表用于记录发布消息的序列号和发布消息的发布句柄之间的映射关系,所述发布句柄用于指示对应的发布消息的内存地址;在查找到与所述目标发布消息对应的目标发布句柄的情况下,跳转至所述目标发布句柄所关联的目标内存指针所指向的内存,得到所述发布统计结果,其中,所述目标内存指针为存储所述发布统计结果的内存的指针;根据所述当前订阅组件所对应的当前索引值,将所述发布统计结果中与所述当前索引值对应的比特位的值由所述第一值调整为所述第二值,其中,所述当前索引值用于表示与所述当前索引值对应的比特位在所述发布统计结果中的位置;其中,所述应答函数体的参数包括所述目标序列号和所述当前索引值。
- 根据权利要求7所述的方法,其中,所述方法还包括:依次遍历与所述目标消息标识对应的目标信息链表的每个链表节点,得到与所述每个消息订阅组件对应的订阅信息、以及与所述每个消息订阅组件对应的索引值,其中,所述每个链表节点中存储有与所述目标消息标识所标识的消息的一个消息订阅组件对应的订阅信息,所述与所述每个消息订阅组件对应的 索引值是根据所述每个消息订阅组件遍历到的顺序生成的。
- 根据权利要求6所述的方法,其中,在所述触发执行所述应答函数体之后,所述方法还包括:在所述发布统计结果中的所有比特位均为所述第二值的情况下,确定所述目标发布消息已发布给了所述目标发布消息的所有消息订阅组件;在所述发布统计结果中的至少部分比特位为所述第一值的情况下,确定所述目标发布消息未发布给所述目标发布消息的至少部分消息订阅组件。
- 根据权利要求1至9中任一所述的方法,其中,在所述根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件之后,所述方法还包括:在确定所述目标设备中不存在订阅了所述目标发布消息的消息订阅组件、且所述消息发布组件指示将所述目标发布消息的发布结果反馈给所述消息发布组件的情况下,通过所述消息传递组件向所述消息发布组件反馈第二发布结果,其中,所述第二发布结果用于指示所述目标设备中没有组件订阅所述目标发布消息。
- 一种组件间的消息传递装置,包括:获取单元,设置为通过目标设备的消息传递组件获取所述目标设备的消息发布组件所发布的目标发布消息,其中,所述消息传递组件用于在所述目标设备的不同组件之间传递消息;第一确定单元,设置为根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件;传递单元,设置为在确定所述目标设备中存在订阅了所述目标发布消息的消息订阅组件、且所述消息发布组件指示将所述目标发布消息的发布结果反馈给所述消息发布组件的情况下,通过所述消息传递组件将所述目标发布消息分发传递给订阅了所述目标发布消息的每个消息订阅组件;第一反馈单元,设置为根据在预设时间内所述目标发布消息已发布给的消息订阅组件,向所述消息发布组件反馈第一发布结果,其中,所述第一发布结 果用于指示所述目标发布消息是否已发布给了所述目标发布消息的所有消息订阅组件。
- 根据权利要求11所述的装置,其中,所述第一确定单元包括:查找模块,设置为使用所述目标消息标识查找订阅表,其中,所述订阅表用于记录已订阅消息的消息标识和与所述已订阅消息的消息标识对应的信息链表的表头地址之间的映射关系,与所述已订阅消息的消息标识对应的信息链表用于存储与所述已订阅消息的消息订阅组件对应的订阅信息;第一确定模块,设置为在所述订阅表中查找到与所述目标消息标识对应的信息链表的表头地址的情况下,确定所述目标设备中存在订阅了所述目标发布消息的消息订阅组件;第二确定模块,设置为在所述订阅表中未查找到与所述目标消息标识对应的信息链表的表头地址的情况下,确定所述目标设备中不存在订阅了所述目标发布消息的消息订阅组件。
- 根据权利要求11所述的装置,其中,所述传递单元包括:执行模块,设置为在所述预设时间内,通过所述消息传递组件为所述每个消息订阅组件执行以下消息传递操作,以将所述目标发布消息传递给所述每个消息订阅组件,其中,在执行以下消息传递操作的过程中,所述每个消息订阅组件为当前订阅组件:注册与所述当前订阅组件对应的执行函数体和与所述执行函数体对应的应答函数体,其中,所述执行函数体包含所述当前订阅组件注册的消息处理函数,所述执行函数体的参数包括所述目标发布消息中的发布信息;依次执行所述执行函数体和所述应答函数体,其中,所述执行函数体用于按照所述消息处理函数对所述目标发布消息中的发布信息进行处理,所述应答函数体用于在所述执行函数体执行完成之后,将与所述当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
- 根据权利要求13所述的装置,其中,所述执行模块包括:第一传入子模块,设置为在所述当前订阅组件的运行时环境有效的情况下, 通过调用所述当前订阅组件的运行时环境的接口将所述执行函数体和所述应答函数体传入所述当前订阅组件的运行时环境,以由所述当前订阅组件的运行时环境依次执行所述执行函数体和所述应答函数体;第一执行子模块,设置为在所述当前订阅组件的运行时环境无效的情况下,由所述消息传递组件的运行时环境代理执行所述执行函数体和所述应答函数体。
- 根据权利要求13所述的装置,其中,所述执行模块包括:第二传入子模块,设置为将所述目标发布消息中的发布信息以及所述当前订阅组件所指定的参数传入所述执行函数体,以执行所述执行函数体;第二执行子模块,设置为在所述执行函数体执行完成之后,触发执行所述应答函数体,以将与所述当前订阅组件对应的发布指示标识调整为发布完成的指示标识。
- 根据权利要求13所述的装置,其中,所述执行模块包括:第三执行子模块,设置为执行所述执行函数体,以按照所述消息处理函数对所述目标发布消息中的发布信息进行处理;第四执行子模块,设置为在所述执行函数体执行完成之后,触发执行所述应答函数体,以将发布统计结果中与所述当前订阅组件对应的比特位的值由第一值调整为第二值,其中,所述发布统计结果中的一个比特位对应于所述目标发布消息的一个消息订阅组件,所述第一值用于指示所述目标发布消息未发布给对应的消息订阅组件,所述第二值用于指示所述目标发布消息已发布给了对应的消息订阅组件。
- 根据权利要求16所述的装置,其中,所述装置还包括:查找单元,设置为在触发执行所述应答函数体之后,根据所述目标发布消息的目标序列号在发布表中查找与所述目标序列号对应的发布句柄,其中,所述目标序列号用于唯一标识所述目标发布消息的发布流程,所述发布表用于记录发布消息的序列号和发布消息的发布句柄之间的映射关系,所述发布句柄用于指示对应的发布消息的内存地址;跳转单元,设置为在查找到与所述目标发布消息对应的目标发布句柄的情况下,跳转至所述目标发布句柄所关联的目标内存指针所指向的内存,得到所述发布统计结果,其中,所述目标内存指针为存储所述发布统计结果的内存的指针;调整单元,设置为根据所述当前订阅组件所对应的当前索引值,将所述发布统计结果中与所述当前索引值对应的比特位的值由所述第一值调整为所述第二值,其中,所述当前索引值用于表示与所述当前索引值对应的比特位在所述发布统计结果中的位置;其中,所述应答函数体的参数包括所述目标序列号和所述当前索引值。
- 根据权利要求17所述的装置,其中,所述装置还包括:遍历单元,设置为依次遍历与所述目标消息标识对应的目标信息链表的每个链表节点,得到与所述每个消息订阅组件对应的订阅信息、以及与所述每个消息订阅组件对应的索引值,其中,所述每个链表节点中存储有与所述目标消息标识所标识的消息的一个消息订阅组件对应的订阅信息,所述与所述每个消息订阅组件对应的索引值是根据所述每个消息订阅组件遍历到的顺序生成的。
- 根据权利要求16所述的装置,其中,所述装置还包括:第二确定单元,设置为在所述触发执行所述应答函数体之后,在所述发布统计结果中的所有比特位均为所述第二值的情况下,确定所述目标发布消息已发布给了所述目标发布消息的所有消息订阅组件;第三确定单元,设置为在所述发布统计结果中的至少部分比特位为所述第一值的情况下,确定所述目标发布消息未发布给所述目标发布消息的至少部分消息订阅组件。
- 根据权利要求11至19中任一所述的装置,其中,所述装置还包括:第二反馈单元,设置为在所述根据所述目标发布消息的目标消息标识,确定所述目标设备中是否存在订阅了所述目标发布消息的消息订阅组件之后,在确定所述目标设备中不存在订阅了所述目标发布消息的消息订阅组件、且所述消息发布组件指示将所述目标发布消息的发布结果反馈给所述消息发布组件 的情况下,通过所述消息传递组件向所述消息发布组件反馈第二发布结果,其中,所述第二发布结果用于指示所述目标设备中没有组件订阅所述目标发布消息。
- 一种计算机可读的存储介质,所述计算机可读的存储介质包括存储的程序,其中,所述程序运行时执行权利要求1至10中任一项所述的方法。
- 一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行权利要求1至10中任一项所述的方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211366283.2A CN115766318A (zh) | 2022-10-31 | 2022-10-31 | 组件间的消息传递方法和装置、存储介质及电子装置 |
CN202211366283.2 | 2022-10-31 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2024092938A1 true WO2024092938A1 (zh) | 2024-05-10 |
Family
ID=85356049
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/135687 WO2024092938A1 (zh) | 2022-10-31 | 2022-11-30 | 组件间的消息传递方法和装置、存储介质及电子装置 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN115766318A (zh) |
WO (1) | WO2024092938A1 (zh) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101960825A (zh) * | 2008-03-05 | 2011-01-26 | 国际商业机器公司 | 发布/订阅消息中介 |
CN102859541A (zh) * | 2010-04-19 | 2013-01-02 | 国际商业机器公司 | 在发布/订阅通讯中控制消息传递 |
US20160205210A1 (en) * | 2013-08-30 | 2016-07-14 | International Business Machines Corporation | Control method and apparatus for publish/subscribe systems |
CN107360082A (zh) * | 2017-07-28 | 2017-11-17 | 郑州云海信息技术有限公司 | 一种发布/订阅方法及装置 |
-
2022
- 2022-10-31 CN CN202211366283.2A patent/CN115766318A/zh active Pending
- 2022-11-30 WO PCT/CN2022/135687 patent/WO2024092938A1/zh unknown
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101960825A (zh) * | 2008-03-05 | 2011-01-26 | 国际商业机器公司 | 发布/订阅消息中介 |
CN102859541A (zh) * | 2010-04-19 | 2013-01-02 | 国际商业机器公司 | 在发布/订阅通讯中控制消息传递 |
US20160205210A1 (en) * | 2013-08-30 | 2016-07-14 | International Business Machines Corporation | Control method and apparatus for publish/subscribe systems |
CN107360082A (zh) * | 2017-07-28 | 2017-11-17 | 郑州云海信息技术有限公司 | 一种发布/订阅方法及装置 |
Also Published As
Publication number | Publication date |
---|---|
CN115766318A (zh) | 2023-03-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109510846B (zh) | Api调用系统、方法、装置、电子设备及存储介质 | |
US11240332B2 (en) | Subscription based event notifications | |
JP6732899B2 (ja) | メッセージデータを格納するためのシステム及び方法 | |
CN110677405B (zh) | 一种数据处理方法、装置、电子设备及存储介质 | |
CN113326155B (zh) | 一种信息处理方法、装置、系统和存储介质 | |
US20140215492A1 (en) | Dynamic provisioning of message groups | |
JP5744717B2 (ja) | ディレクトリへのアクセスのための方法及びデバイス | |
CN115766314A (zh) | 组件间的消息传递方法和装置、存储介质及电子装置 | |
US20130066980A1 (en) | Mapping raw event data to customized notifications | |
JP6663047B2 (ja) | アクセスポイント切り替え方法および装置 | |
WO2020125074A1 (zh) | 消息到达率确定方法、装置、数据统计服务器及存储介质 | |
US7434230B2 (en) | Method and system for time bounding notification delivery in an event driven system | |
WO2019056203A1 (zh) | 一种低延时音视频传输方法、装置及计算机可读存储介质 | |
US20140059152A1 (en) | Support server for redirecting task results to a wake-up server | |
WO2015004550A1 (en) | Framework for application to application interworking in the m2m world | |
WO2024092940A1 (zh) | 组件间的消息传递方法和装置、存储介质及电子装置 | |
CN111282263A (zh) | 事件消息的处理方法、装置、电子设备及可读存储介质 | |
WO2024092938A1 (zh) | 组件间的消息传递方法和装置、存储介质及电子装置 | |
CN110309028B (zh) | 监控信息获取方法、服务监控方法、装置及系统 | |
EP4044542A1 (en) | Method and apparatus for subscribing to resource | |
WO2024092941A1 (zh) | 组件信息的处理方法和装置、存储介质及电子装置 | |
CN105068430B (zh) | 一种家电组操作方法及装置 | |
WO2023134247A1 (zh) | 容器管理方法及容器管理系统 | |
WO2020220272A1 (zh) | 更改资源状态的方法、系统、终端及存储介质 | |
CN112511440B (zh) | 报文转发方法、系统、存储介质和电子设备 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22964233 Country of ref document: EP Kind code of ref document: A1 |