CN113656201A - Message model with message proxy function and message processing method - Google Patents
Message model with message proxy function and message processing method Download PDFInfo
- Publication number
- CN113656201A CN113656201A CN202110987595.4A CN202110987595A CN113656201A CN 113656201 A CN113656201 A CN 113656201A CN 202110987595 A CN202110987595 A CN 202110987595A CN 113656201 A CN113656201 A CN 113656201A
- Authority
- CN
- China
- Prior art keywords
- message
- module
- agent
- messages
- response
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 13
- 230000005540 biological transmission Effects 0.000 claims abstract description 18
- 238000012545 processing Methods 0.000 claims abstract description 8
- 230000004044 response Effects 0.000 claims description 33
- 238000005316 response function Methods 0.000 claims description 17
- 238000003860 storage Methods 0.000 claims description 12
- 230000007274 generation of a signal involved in cell-cell signaling Effects 0.000 claims description 5
- 238000004519 manufacturing process Methods 0.000 claims description 4
- 238000009826 distribution Methods 0.000 claims description 2
- 238000004891 communication Methods 0.000 abstract description 3
- 238000010586 diagram Methods 0.000 description 6
- 238000000034 method Methods 0.000 description 5
- 230000008569 process Effects 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004043 responsiveness Effects 0.000 description 1
- 230000007704 transition Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/548—Queue
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer And Data Communications (AREA)
Abstract
A message model with message broker functionality comprising a publisher unit, a message transport layer, and a subscriber unit, wherein the publisher unit is configured to publish and produce messages, publishing messages to the message transport layer; the message transmission layer is used for transmitting and managing the messages issued by the issuer unit; the subscriber unit is used for subscribing messages, message agents, receiving messages and responding messages. The invention also provides a message processing method, which completes the communication between the thread and the message model by adding the message agent without modifying the message processing function, avoids thread contention and deadlock, simplifies the code and ensures the real-time property of the system.
Description
Technical Field
The invention relates to the technical field of software communication, in particular to a message model with a message agent function.
Background
In the field of software communications, software developers often use both a worker thread and a UI thread to improve the responsiveness of the UI. The UI draws through the UI thread, which maintains a "message queue" that the worker thread is essentially without, and thus is the greatest difference between the UI thread and the worker thread.
Currently, most UI software adopts a message model implemented by thread lock, critical point, and the like to solve the problem of communication between a worker thread and a UI thread, or to execute an operation that the UI thread wants to execute in the worker thread. This method of securing threads has inherent disadvantages: firstly, the code is cumbersome, and secondly, deadlock and contention among threads are easily generated.
Disclosure of Invention
In order to solve the defects in the prior art, the invention aims to provide a message model with a message agent function and a message processing method.
To achieve the above object, the present invention provides a message model with message broker function, which comprises a publisher unit, a message transport layer, and a subscriber unit, wherein,
the publisher unit is used for publishing and producing messages and publishing the messages to the message transmission layer;
the message transmission layer is used for transmitting and managing the messages issued by the issuer unit;
the subscriber unit is used for subscribing messages, message agents, receiving messages and responding messages.
Further, the publisher unit further comprises a publish information module and a produce message module, wherein,
the message issuing module calls a registration message interface to register the message;
and the production message module calls a message pushing interface to push the issued message to the message transmission layer.
Further, the message transmission layer further comprises a message management module and a message queue module, wherein,
the message management module is used for managing the corresponding relation between the messages published by the publisher unit and the messages subscribed by the subscriber unit;
and the message queue module is used for storing the latest state of the current message.
Further, the message queue module further includes a message agent storage module for storing a message agent and a message response storage module for storing a message response function.
Further, the subscriber unit further comprises a subscription message module, a consumption message module, a message agent interface module, a non-agent message response module, and a message agent module, wherein,
the subscription message module provides a message subscription interface for the subscriber unit, and is used for subscribing messages and registering message agents;
the consumption message module is responsible for scheduling message agents and message distribution;
the message agent interface module is responsible for providing a message transmission interface for transmitting messages and message processing functions;
the agent-free message response module responds to the message of the unregistered agent;
the message agent module respectively responds to the messages of different registration agents.
Furthermore, the message agent module further comprises a trigger signal generation module, a trigger signal response module, and a message sending module, wherein,
the signal generating module is used for generating a trigger signal for triggering a message response;
the signal response module responds to the trigger signal by using a slot function.
In order to achieve the above object, the present invention further provides a message processing method, including the following steps:
1) the publisher unit publishes and produces messages;
2) the message transmission layer transmits the message;
3) subscribing to messages and registering for message brokers;
4) receiving a message from the message transmission layer, and directly responding to the message if an associated empty message agent exists; otherwise, the message is transmitted to the corresponding message agent through the message agent interface and responds to the message.
Further, the step 1) further comprises the step of,
calling a registration message interface to register the message;
and calling a push message interface to push the issued message to the message transmission layer.
Further, the step 3) further comprises the step of,
calling a message subscription interface to subscribe the message and register a message agent, registering the message agent and a message processing function, associating the message agent if the message agent is registered, and associating the empty message agent if the message agent is not registered;
and calling the connect function to associate the trigger signal and the trigger response signal.
Furthermore, the method also comprises the following steps of,
receiving a message through a Recv function;
the message agent and the message response function are taken out from the message consumption module;
transmitting the message agent and the message response function to a message agent module through a message agent interface;
triggering a signal in the message agent module through a signal generation module;
and the signal response module responds to the trigger signal and utilizes the slot function to call the message response function to perform message response.
Compared with the prior art, the message model with the message agent function and the message processing method have the following beneficial effects: the communication between the threads and the message model is completed by adding the message agent without modifying the message processing function, so that thread contention and deadlock are avoided, the code is simplified, and the real-time performance of the system is ensured.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention.
Drawings
The accompanying drawings are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the principles of the invention and not to limit the invention. In the drawings:
FIG. 1 is a diagram illustrating a message model architecture with message brokering functionality in accordance with the present invention;
FIG. 2 is a flow chart of a message processing method according to the present invention;
FIG. 3 is a schematic diagram of a message model interface relationship with QT message broker functionality according to the present invention;
FIG. 4 is a message model workflow diagram with QT message broker functionality according to the present invention.
Detailed Description
The preferred embodiments of the present invention will be described in conjunction with the accompanying drawings, and it will be understood that they are described herein for the purpose of illustration and explanation and not limitation.
Example 1
Fig. 1 is a schematic diagram illustrating a message model with a message broker function according to the present invention, and as shown in fig. 1, the message model with a message broker function of the present invention includes a publisher unit 10, a message transport layer 20, and a subscriber unit 30, wherein,
a publisher unit 10, for publishing and producing messages, publishes the messages to a message transport layer 20.
And the message transmission layer 20 is used for transmitting and managing messages, and processing the messages produced by the publisher unit 10 to form a message queue and transmitting the message queue to the subscriber unit 30.
A subscriber unit 30 for subscribing to messages, associating message brokers, receiving messages and responding messages.
In the embodiment of the present invention, the publisher unit 10 includes a publishing information module and a production information module, wherein the publishing information module calls a registration information interface (register function) to publish (register) a message; the production message module calls a push message interface (pub function) to push the published message to the message transport layer 20.
In this embodiment of the present invention, the message transport layer 20 further includes a message management module 21 and a message queue module 22, wherein,
and the message management module 21 is configured to manage a correspondence relationship between the messages published by the publisher unit 10 and the messages subscribed by the subscriber unit 30.
A message queue module 22, configured to store the latest status of the current message.
In the embodiment of the present invention, the subscriber unit 30 further includes a subscribe message module 31, a consume message module 32, a message agent interface module 33, an empty message agent module 34, and a message agent module 35, wherein,
a subscribe message module 31 that provides a message subscription interface (sub-function) for the subscriber unit 30 to subscribe to messages and register for message brokers.
In the embodiment of the present invention, the subscribe message module 31 may register a message broker when subscribing to a message, associate the message with the message broker if the message broker is registered, and associate an empty message broker if the message broker is not registered.
And a message consumption module 32 for storing and scheduling the messages and their associated message brokers and message response functions.
A message broker interface module 33 that provides a message passing interface for passing messages and message handling functions.
An empty message broker module 34 that responds to messages for unregistered brokers.
The message agent module 35 responds to messages of different registration agents respectively, including QT message agent and response, MFC message agent and response, ISO system message agent and response, Android system message agent and response, and other thread message agent and response.
Example 2
Fig. 2 is a flowchart of a message processing method according to the present invention, and the message processing method of the present invention will be described in detail with reference to fig. 2.
First, in step 201, a message broker type and a message broker interface with a pass message and message handling functions are defined.
At step 202, different message brokers are implemented according to message broker type and message broker interface.
At step 203, the message, the subscription message, the message handling function and the message broker are registered.
In the embodiment of the present invention, the publisher unit 10 provides an interface for registering messages and pushing messages, and the subscriber unit 30 provides an interface for subscribing messages. The registration message interface is used for registering messages issued by the publishers; the push message interface is used for the publisher unit 10 to send published messages; message subscription interface (sub-function) for subscribing messages and registering message brokers
At step 204, it is determined whether the subscriber registers a message broker in subscribing to the message, and if not, go to step 205, and if so, go to step 206.
At step 205, an empty message broker is associated, and the process goes to step 207.
At step 206, the message is associated with a message broker.
At step 207, the association message is stored to a message list.
At step 208, a message is received.
At step 209, a determination is made as to whether the subscriber unit 30 has received a message, and if not, a transition is made to step 208, and if a message is received, the next step is taken.
At step 210 it is determined whether the message is on the message list and if not, go to step 208 and if the message is on the message list, proceed to the next step.
In step 211, it is determined whether the message agent associated with the message is empty, if the message agent is empty, go to step 213, and if the message agent is not empty, go to the next step;
if the message agent is not empty, step 212, the agent associated with the message is fetched, and the associated message processing function is responded by the agent, and then the step 208 is carried out;
if the message broker is empty, step 213, the message handling function is invoked directly and then goes to step 208.
Example 3
In the embodiment of the invention, the publisher and the subscriber are combined in the message model amq, and the transport layer uses a UDP multicast protocol. The message model amq can communicate across processes, and when a message is received, the message is responded to through a message proxy.
Fig. 3 is a schematic diagram of the relationship between message model interfaces with QT message broker function according to the present invention, and as shown in fig. 3, the message model with QT message broker function of the present invention comprises a message registration module 301, a push message module 302, a subscribe message module 303, a distribute message module 304, a message broker storage module 305, a response message storage module 306, a message broker interface 33, and a message broker module 35, wherein,
a message registration module (register) 301, responsible for registering the message msg.
And a push message module (Pub)302, which is responsible for pushing the message msg.
And a subscribe message module (Sub)303, which is responsible for subscribing to the message msg, the message response function OnMsg and the message Proxy.
A distribute message module (MsgLoop)304, which distributes messages using a message loop function MsgLoop ().
A message broker storage module (ProxyMap)305 for storing a message broker.
A response message storage module (MsgMap)306 for storing a message response function.
The message broker interface (Proxy)33 is a standard message broker interface, and a standard interface function MessageCallback (OnMsg, Msg) is defined in the message broker interface for message passing.
And the message agent module 35 is a QT UI message agent QTproxy and is used for data transmission between the message model and the QT UI, and the QT UI message agent QTproxy inherits the self-message agent interface Proxy.
In this embodiment of the present invention, the message agent module 35 further includes,
a signal generating module 307, configured to generate a trigger signal UIMessage for triggering a message response.
A signal response module (OnUIMessage)308 that responds to the trigger signal UIMessage with a bin function OnUIMessage (OnMsg, Msg).
Example 4
Fig. 4 is a message model workflow diagram having a QT message broker function according to the present invention, and the message model workflow having the QT message broker function of the present invention will be described in detail with reference to fig. 2.
In the embodiment of the invention, a sending program sends a message Msg to a receiving program, and after the receiving program receives the message by using amq, the message is transmitted to a QT UI through a QT message proxy (QTproxy) and corresponds to the message in the QT UI.
In step 401, a message model is defined and initialized.
In step 402, the Register function is called, registering the message msg in the message model.
In the embodiment of the present invention, the message registration module 301 is used to call a Register function, and Register a message msg in a message model.
In step 403, call pub function, send message msg.
In the embodiment of the present invention, the message pushing module 302 is utilized to call a pub function to send a message msg.
In step 404, a sub function is called to subscribe to the message msg.
In the embodiment of the invention, a sub function subscription message msg is called by adopting a subscription message module 303, a message response function OnMsg and a message proxy QTproxy are transmitted to a message model, the QTproxy is called by the message model for initialization, and a connect is called in the process of initializing the QTproxy for associating a trigger signal UIMessage and a response signal OnUIMessage. After QTproxy initialization is complete, the message model will store and associate the message, message response function, and message proxy via a message proxy storage module (ProxyMap)305 and a response message storage module (MsgMap) 306.
In step 405, a message msg is received via the Recv function.
In step 406, a message msg and a message response function (OnMsg) are passed in response to the trigger signal.
In the embodiment of the present invention, after receiving a message Msg, a message model takes out a QT message Proxy (QTProxy) and a message response function (OnMsg) through a message Proxy storage module 305 and a response message storage module 306, and transfers information to the QT message Proxy (QTProxy) through an interface function MessageCallback (OnMsg, Msg) in a message Proxy interface (Proxy)33 by using the OnMsg and the Msg as parameters, and triggers a signal UIMessage through a signal generation module 307 in the QT message Proxy (QTProxy), and transfers the information to a QT UI layer, wherein the signal generation module 307 uses an emit trigger signal.
In step 407, a message response function is called by using the slot function OnUIMessage (OnMsg, Msg) to respond to the message.
In the embodiment of the present invention, the signal response module 308 responds to the trigger signal UIMessage, and invokes a message response function by using a slot function oneuimessage (OnMsg, Msg), so as to perform message response on the QT UI layer.
Those of ordinary skill in the art will understand that: although the present invention has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that changes may be made in the embodiments and/or equivalents thereof without departing from the spirit and scope of the invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. A message model with message broker functionality comprising, a publisher unit, a message transport layer, and a subscriber unit, wherein,
the publisher unit is used for publishing and producing messages and publishing the messages to the message transmission layer;
the message transmission layer is used for transmitting and managing the messages issued by the issuer unit;
the subscriber unit is used for subscribing messages, message agents, receiving messages and responding messages.
2. The message model with message brokering functionality according to claim 1, wherein said publisher unit further comprises, a publish information module and a produce message module, wherein,
the message issuing module calls a registration message interface to register the message;
and the production message module calls a message pushing interface to push the issued message to the message transmission layer.
3. The message model with message brokering functionality according to claim 1, wherein said message transport layer further comprises, a message management module and a message queue module, wherein,
the message management module is used for managing the corresponding relation between the messages published by the publisher unit and the messages subscribed by the subscriber unit;
and the message queue module is used for storing the latest state of the current message.
4. The message model with message broker function of claim 1 wherein the message queue module further comprises a message broker storage module storing message brokers and a message response storage module storing message response functions.
5. The message model with message brokering functionality of claim 1, wherein said subscriber unit further comprises, a subscribe message module, a consume message module, a message broker interface module, a no broker message response module, and a message broker module, wherein,
the subscription message module provides a message subscription interface for the subscriber unit, and is used for subscribing messages and registering message agents;
the consumption message module is responsible for scheduling message agents and message distribution;
the message agent interface module is responsible for providing a message transmission interface for transmitting messages and message processing functions;
the agent-free message response module responds to the message of the unregistered agent;
the message agent module respectively responds to the messages of different registration agents.
6. The message model with message brokering functionality according to claim 5, wherein said message brokering module further comprises a trigger generation module, a trigger response module, and a message sending module, wherein,
the signal generating module is used for generating a trigger signal for triggering a message response;
the signal response module responds to the trigger signal by using a slot function.
7. A message processing method using the message model with message broker function of any of claims 1-6, comprising the steps of,
1) the publisher unit publishes and produces messages;
2) the message transmission layer transmits the message;
3) subscribing to messages and registering for message brokers;
4) receiving a message from the message transmission layer, and directly responding to the message if an associated empty message agent exists; otherwise, the message is transmitted to the corresponding message agent through the message agent interface and responds to the message.
8. The message processing method according to claim 7, wherein the step 1), further comprises,
calling a registration message interface to register the message;
and calling a push message interface to push the issued message to the message transmission layer.
9. The message processing method according to claim 7, wherein the step 3), further comprises,
calling a message subscription interface to subscribe the message and register a message agent, registering the message agent and a message processing function, associating the message agent if the message agent is registered, and associating the empty message agent if the message agent is not registered;
and calling the connect function to associate the trigger signal and the trigger response signal.
10. The message processing method of claim 9, further comprising,
receiving a message through a Recv function;
the message agent and the message response function are taken out from the message consumption module;
transmitting the message agent and the message response function to a message agent module through a message agent interface;
triggering a signal in the message agent module through a signal generation module;
and the signal response module responds to the trigger signal and utilizes the slot function to call the message response function to perform message response.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110987595.4A CN113656201A (en) | 2021-08-26 | 2021-08-26 | Message model with message proxy function and message processing method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110987595.4A CN113656201A (en) | 2021-08-26 | 2021-08-26 | Message model with message proxy function and message processing method |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113656201A true CN113656201A (en) | 2021-11-16 |
Family
ID=78492926
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110987595.4A Pending CN113656201A (en) | 2021-08-26 | 2021-08-26 | Message model with message proxy function and message processing method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113656201A (en) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102859541A (en) * | 2010-04-19 | 2013-01-02 | 国际商业机器公司 | Controlling message delivery in publish/subscribe messaging |
CN103037000A (en) * | 2012-12-21 | 2013-04-10 | 北京邮电大学 | Publish-subscribe system and notification message processing method thereof |
CN106648816A (en) * | 2016-12-09 | 2017-05-10 | 武汉斗鱼网络科技有限公司 | Multithread processing system and multithread processing method |
-
2021
- 2021-08-26 CN CN202110987595.4A patent/CN113656201A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102859541A (en) * | 2010-04-19 | 2013-01-02 | 国际商业机器公司 | Controlling message delivery in publish/subscribe messaging |
CN103037000A (en) * | 2012-12-21 | 2013-04-10 | 北京邮电大学 | Publish-subscribe system and notification message processing method thereof |
CN106648816A (en) * | 2016-12-09 | 2017-05-10 | 武汉斗鱼网络科技有限公司 | Multithread processing system and multithread processing method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7665096B2 (en) | DDS-assisted CORBA discovery | |
CN105472042B (en) | The message-oriented middleware system and its data transferring method of WEB terminal control | |
Bellifemine et al. | Jade programmer’s guide | |
US5999986A (en) | Method and system for providing an event system infrastructure | |
CN109815025B (en) | Service model calling method, device and storage medium | |
US20040068479A1 (en) | Exploiting asynchronous access to database operations | |
US7634777B2 (en) | Queued component interface passing for results outflow from queued method invocations | |
CN111212085B (en) | Method for synchronously calling Internet of things platform, internet of things system and network equipment | |
US8533748B2 (en) | Contained command invocation framework | |
US20090064207A1 (en) | Multiplex transport | |
CN110062041B (en) | Method and device for changing IOT (input/output) equipment based on block chain | |
CN102520936A (en) | Method for realizing sharing of Socket communication service on Android platform | |
CN112596931B (en) | Cross-process communication method and device, electronic equipment and storage medium | |
CN113032166A (en) | Inter-core communication method, processor, inter-core communication system, and computer-readable storage medium | |
CN109062650B (en) | Bullet screen message distribution method, device, equipment and storage medium | |
US6389470B1 (en) | Telecommunication controller messaging system using middlewares to decouple applications from system resources | |
US20090307712A1 (en) | Actor virtual machine | |
CN113656201A (en) | Message model with message proxy function and message processing method | |
Meier | State of the art review of distributed event models | |
CN109005468B (en) | Bullet screen message distribution method, device, equipment and storage medium | |
CN108881991B (en) | Bullet screen message distribution method, device, equipment and storage medium | |
Goel et al. | Message-oriented-middleware in a distributed environment | |
CN109086107B (en) | Bullet screen message distribution method, device, equipment and storage medium | |
CN112667387B (en) | DDS-based design model for synchronization of persistent data objects | |
CN109246484B (en) | Barrage message transmission method, device, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20220112 Address after: 100190 inside 37 Xueyuan Road, Haidian District, Beijing Applicant after: Beijing northern sky long hawk UAV Technology Co.,Ltd. Address before: Room 201, floor 2, block C, Zhizhen building, No. 7, Zhichun Road, Haidian District, Beijing 100086 Applicant before: Beijing Yushi Hangtong Technology Co.,Ltd. |
|
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20211116 |