Message subscription method, system, electronic device and storage medium based on Netty framework
By establishing a message push center based on the subsystems in large systems, the problem of high data transmission coupling between subsystems is solved, and the effect of reducing development costs and maintenance costs is achieved.
Patent Information
- Application Number
- CN202211313777.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-25
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2042-10-25
AI Technical Summary
The lack of unified interactive protocols between subsystems in large systems leads to high coupling of data transmission and high development costs.
A message subscription method based on the Netty framework is based on the establishment of a message push center between the message client and the message server.
It reduces the coupling of data transmission, reduces development costs, and reduces the number of data transmission channels and maintenance costs.
Smart Images

Figure CN115665239B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of business management, and in particular to a message subscription method, system, electronic device and storage medium based on a Netty framework. Background Art
[0002] At present, for large systems with multiple subsystems, there is no unified interaction protocol between subsystems. Different data transmission methods such as polling and blocking sockets are used for real-time data transmission between subsystems. As a result, the degree of coupling between subsystems in data transmission is high. If developers need to continue to develop systems and new access services, they need to develop and maintain different channels, which results in high development costs. Summary of the invention
[0003] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0004] In view of the above-mentioned shortcomings of the prior art, the present invention discloses a message subscription method, system, electronic device and storage medium based on the Netty framework to reduce the coupling degree of data transmission, thereby reducing development costs.
[0005] The present invention discloses a message subscription method based on a Netty framework, comprising: obtaining a message client and a message server corresponding to a target topic; establishing a message push center between the message client and the message server, wherein the message push center comprises a Netty server and a message queue middleware; establishing a message push channel corresponding to the target topic between the message client and the Netty server, and sending a topic message request corresponding to the target topic to the message server, so that the message server sends the topic message corresponding to the target topic to the message queue middleware; using the message queue middleware to send a message queue carrying the topic message to the Netty server, so that the Netty server pushes the topic message to the message client through the message push channel.
[0006] Optionally, establishing a message push channel corresponding to the target topic between the message client and the Netty server includes: obtaining a topic type corresponding to the target topic, wherein the topic type includes a public topic or a private topic; establishing a communication connection between the message client and the Netty server, so that the Netty server generates a connection identifier corresponding to the communication connection; if the topic type includes a public topic, sending a channel cache request carrying the connection identifier and the target topic to the Netty server, so that the Netty server uses the communication connection corresponding to the connection identifier as the message push channel corresponding to the target topic, and caches the message push channel; if the topic type includes a private topic, applying for an access signature corresponding to the target topic from the message server, sending a channel cache request carrying the connection identifier, the target topic and the access signature to the Netty server, so that the Netty server performs a signature verification on the access signature according to a preset verification key, and after the signature verification passes, uses the communication connection corresponding to the connection identifier as the message push channel corresponding to the target topic, and caches the message push channel.
[0007] Optionally, a message client corresponding to the target topic is obtained in the following manner: a Web client is obtained, the Web client includes a client tool module, a target topic, and a message consumption application corresponding to the target topic, wherein the client tool module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server; a message client corresponding to the target topic is established, wherein the target topic and the message consumption application are passed into the message client; if the topic type includes a private topic, a preset authentication interface address is passed into the message client, wherein the authentication interface address is located on the message server side.
[0008] Optionally, applying to the message server for an access signature corresponding to the target subject includes: obtaining an identity authentication token, wherein the identity authentication token is used to represent the Web client; using the client tool module to send the identity authentication token, the connection identifier and the target subject to the authentication interface address of the message server, so that the message server performs identity authentication based on the identity authentication token, and after the identity authentication is passed, encrypting at least one of the identity authentication token, the connection identifier and the target subject according to a preset encryption private key to obtain an access signature corresponding to the target subject; and receiving the access signature fed back by the authentication interface address.
[0009] Optionally, the message server sends the topic message corresponding to the target topic to the message queue middleware in the following manner: the message server is provided with a server-side tool module, and the message push center also includes a push service; the server-side tool module is used to compress the topic message corresponding to the target topic to obtain an information summary, and the information summary is encrypted according to a preset encryption private key to obtain a push signature corresponding to the topic message, and the push signature and the topic message are sent to the push service; the push service is used to perform signature verification on the push signature based on a preset encryption public key, and the topic message is pushed to the message queue middleware after the signature verification passes.
[0010] Optionally, after establishing a message push center between the message client and the message server, the method further includes: obtaining the number of topics of the target topic; if the number of topics is less than a preset number threshold, using the preset minimum number as the number of servers of the Netty server; if the number of topics is greater than or equal to the preset number threshold, using the number of topics as the number of servers of the Netty server, wherein the target topic, the Netty server, and the message push channel correspond one to one.
[0011] Optionally, after establishing a message push center between the message client and the message server, the method further includes: performing a heartbeat detection on the Netty server to obtain a heartbeat detection result, and monitoring the subscription status of the target topic; if a first cleaning condition or a second cleaning condition is met, cleaning the message push channel between the message client and the Netty server, wherein the first cleaning condition includes that the heartbeat detection result includes a heartbeat timeout, and the second cleaning condition includes that monitoring the subscription status includes unsubscribed.
[0012] The present invention discloses a message subscription system based on a Netty framework, comprising: an acquisition module, used for acquiring a message client and a message server corresponding to a target topic; an establishment module, used for establishing a message push center between a message client and a message server, wherein the message push center comprises a Netty server and a message queue middleware; a subscription module, used for establishing a message push channel corresponding to the target topic between the message client and the Netty server, and sending a topic message request corresponding to the target topic to the message server, so that the message server sends the topic message corresponding to the target topic to the message queue middleware; a push module, used for sending a message queue carrying the topic message to the Netty server by using the message queue middleware, so that the Netty server pushes the topic message to the message client through the message push channel.
[0013] The present invention discloses an electronic device, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.
[0014] The present invention discloses a computer-readable storage medium, on which a computer program is stored: when the computer program is executed by a processor, the above method is implemented.
[0015] Beneficial effects of the present invention:
[0016] By establishing a message push center between the message client and the message server, and through the topic message request, the message server sends the topic message corresponding to the target topic to the message queue middleware, and then uses the message queue middleware to send the message queue carrying the topic message to the Netty server, and then pushes the topic message to the message client through the message push channel. In this way, compared with the system transmitting data through their own data transmission channels, the data transmission method between the message client and the message server is unified through the message push center, which reduces the coupling degree of the system in data transmission, thereby reducing the development cost of the access service, and reducing the number of data transmission channels and channel maintenance costs.
[0017] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0019] Figure 1 It is a flow chart of a message subscription method based on the Netty framework in an embodiment of the present invention;
[0020] Figure 2 It is a schematic diagram of the structure of a message subscription framework based on the Netty framework in an embodiment of the present invention;
[0021] Figure 3 It is a flowchart of another message subscription method based on the Netty framework in an embodiment of the present invention;
[0022] Figure 4 It is a schematic diagram of the structure of a message subscription system based on the Netty framework in an embodiment of the present invention;
[0023] Figure 5 It is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The following describes the embodiments of the present invention through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and sub-samples in the embodiments can be combined with each other without conflict.
[0025] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0026] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.
[0027] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0028] Unless otherwise stated, the term "plurality" means two or more.
[0029] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.
[0030] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0031] Combination Figure 1As shown, the embodiment of the present disclosure provides a message subscription method based on the Netty framework, including:
[0032] Step S101, obtaining the message client and message server corresponding to the target topic;
[0033] Step S102, establishing a message push center between the message client and the message server;
[0034] Among them, the message push center includes Netty server and message queue middleware;
[0035] Step S103, establishing a message push channel corresponding to the target topic between the message client and the Netty server, and sending a topic message request corresponding to the target topic to the message server, so that the message server sends the topic message corresponding to the target topic to the message queue middleware;
[0036] Step S104, using the message queue middleware to send the message queue carrying the subject message to the Netty server, so that the Netty server pushes the subject message to the message client through the message push channel.
[0037] The message subscription method based on the Netty framework provided by the embodiment of the present disclosure is adopted, by establishing a message push center between the message client and the message server, and through the topic message request, the message server sends the topic message corresponding to the target topic to the message queue middleware, and then uses the message queue middleware to send the message queue carrying the topic message to the Netty server, and then pushes the topic message to the message client through the message push channel. In this way, compared with the system transmitting data through respective data transmission channels, the data transmission method between the message client and the message server is unified through the message push center, which reduces the coupling degree of the system in data transmission, thereby reducing the development cost of the access service, and reducing the number of data transmission channels and the channel maintenance cost.
[0038] In some embodiments, the Netty server is built on JAVA NIO (non-blocking IO, non-blocking input / output), which is an asynchronous, event-driven (i.e., Netty will respond to client connection requests, read, write and other events) network application framework with high performance and high concurrency. It is used to develop network IO (input / output) programs based on TCP (Transmission Control Protocol, Transmission Control Protocol) protocol, and also supports UDP (User Datagram Protocol, User Datagram Protocol), HTTP (Hyper Text Transfer Protocol, Hypertext Transfer Protocol), WebSocket (full-duplex communication protocol based on TCP) and other mainstream protocols. Among them, the scalable event model provided by Netty is convenient for adding custom business logic, and the general communication API (Application Programming Interface) provided by Netty is used to simplify the cumbersome code of JAVA NIO.
[0039] In some embodiments, the Netty server supports zero-copy function, so that Netty's receiving and sending ByteBuffer (byte buffer) adopts DIRECTBUFFERS (memory recycling mechanism), and uses off-heap direct memory for Socket reading and writing, without the need for a second copy of the byte buffer. If the traditional heap memory (HEAPBUFFERS) is used for Socket reading and writing, the JVM will copy the heap memory Buffer (buffer class) to the direct memory before writing it to the Socket. Compared with off-heap direct memory, the message has one more memory copy of the buffer during the sending process. Netty provides a combined Buffer object that can aggregate multiple ByteBuffer objects. Users can operate the combined Buffer as easily as operating a Buffer, avoiding the traditional memory copy method of merging several small Buffers into a large Buffer. Netty's file transfer uses the Transfer To method, which can directly send the data of the file buffer to the target channel, avoiding the memory copy problem caused by the traditional circular writing method, thereby improving the transmission efficiency.
[0040] Optionally, a message push channel corresponding to the target topic is established between the message client and the Netty server, including: obtaining the topic type corresponding to the target topic, wherein the topic type includes a public topic or a private topic; establishing a communication connection between the message client and the Netty server, so that the Netty server generates a connection identifier corresponding to the communication connection; if the topic type includes a public topic, a channel cache request carrying the connection identifier and the target topic is sent to the Netty server, so that the Netty server uses the communication connection corresponding to the connection identifier as the message push channel corresponding to the target topic, and caches the message push channel; if the topic type includes a private topic, an access signature corresponding to the target topic is applied to the message server, and a channel cache request carrying the connection identifier, the target topic and the access signature is sent to the Netty server, so that the Netty server performs signature verification on the access signature according to a preset verification key, and after the signature verification passes, uses the communication connection corresponding to the connection identifier as the message push channel corresponding to the target topic, and caches the message push channel.
[0041] Optionally, a message client corresponding to the target topic is obtained in the following manner: a Web (World Wide Web) client is obtained, the Web client includes a client tool module, a target topic and a message consumption application corresponding to the target topic, wherein the client tool module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server; a message client corresponding to the target topic is established, wherein the target topic and the message consumption application are passed into the message client; if the topic type includes a private topic, a preset authentication interface address is passed into the message client, wherein the authentication interface address is located on the message server side.
[0042] In some embodiments, the client tool module is set up through SDK (Software Development Kit).
[0043] Optionally, applying for an access signature corresponding to the target topic from the message server includes: obtaining an identity authentication token, wherein the identity authentication token is used to represent the Web client; using the client tool module to send the identity authentication token, the connection identifier and the target topic to the authentication interface address of the message server, so that the message server performs identity authentication based on the identity authentication token, and after the identity authentication is passed, encrypting at least one of the identity authentication token, the connection identifier and the target topic according to a preset encryption private key to obtain an access signature corresponding to the target topic; receiving the access signature fed back by the authentication interface address.
[0044] In this way, if the topic type subscribed by the message client is a private topic, the message client first applies to the message server for the access signature corresponding to the target topic, and then makes the Netty server perform signature verification on the access signature according to the preset verification key, and caches the message push channel after the signature verification passes, thereby realizing data transmission. Among them, the topic types are divided into public topics and private topics, which improves the flexibility and security of topic subscription.
[0045] In some embodiments, the message server is provided with Redis (Remote Dictionary Server), and a preset encryption private key and a preset encryption public key are stored through Redis.
[0046] Optionally, the message server sends the topic message corresponding to the target topic to the message queue middleware in the following manner: the message server is provided with a server-side tool module, and the message push center also includes a push service; the server-side tool module is used to compress the topic message corresponding to the target topic to obtain an information summary, and the information summary is encrypted according to a preset encryption private key to obtain a push signature corresponding to the topic message, and the push signature and the topic message are sent to the push service; the push service is used to perform signature verification on the push signature based on a preset encryption public key, and the topic message is pushed to the message queue middleware after the signature verification passes.
[0047] In some embodiments, the server-side tool module is set up through the SDK.
[0048] Optionally, after establishing a message push center between the message client and the message server, the method also includes: obtaining the number of topics of the target topic; if the number of topics is less than a preset number threshold, using the preset minimum number as the number of servers of the Netty server; if the number of topics is greater than or equal to the preset number threshold, using the number of topics as the number of servers of the Netty server, wherein there is a one-to-one correspondence between the target topic, the Netty server, and the message push channel.
[0049] In this way, a corresponding number of Netty servers are provided according to the number of target topics, thereby improving data transmission efficiency. At the same time, when the number of target topics decreases, the corresponding number of Netty servers is reduced to reduce transmission costs.
[0050] Optionally, after establishing a message push center between the message client and the message server, the method also includes: performing a heartbeat detection on the Netty server to obtain a heartbeat detection result, and monitoring the subscription status of the target topic; if the first cleaning condition or the second cleaning condition is met, cleaning the message push channel between the message client and the Netty server, wherein the first cleaning condition includes that the heartbeat detection result includes a heartbeat timeout, and the second cleaning condition includes that the subscription status monitored includes unsubscribed.
[0051] In some embodiments, heartbeat detection includes the client and the server periodically sending data packets to each other in the TCP long connection, which can ensure the correct operation of the service and the reliability of the service online and the TCP long connection; the usual heartbeat implementation mechanism is that the client periodically sends data packets to the server, and the server responds after receiving the data, thus ensuring the TCP long connection. If the client does not respond, the corresponding connection is closed to save resources.
[0052] Combination Figure 2 As shown, the embodiment of the present disclosure provides a message subscription framework based on the Netty framework, including a Web client 201, a message push center 202, and a message server 203, wherein the Web client includes a message client (such as a Web browser, etc.), a client tool module (PushClientSDK); the message client is used to obtain a target topic and receive a topic message corresponding to the target topic, wherein the topic type corresponding to the target topic includes a public topic or a private topic; the client tool module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server, and receive the topic message pushed by the Netty server, and is also used to perform authentication tasks corresponding to the private topic, perform heartbeat detection on the Netty server, and send topic messages corresponding to the target topic to the message server. message request; the message push center includes push service, message queue middleware (MQ cluster), and Netty server; the push service is used to verify the push signature based on the preset encrypted public key, and push the topic message to the message queue middleware after the signature verification passes; the message queue middleware is used to send the message queue carrying the topic message to the Netty server; the Netty server is used to push the topic message to the message client through the message push channel; the message server side includes the business system, the server-side tool module (PushServerSDK / API), the capability platform, and Redis; the business system is used to obtain the topic message corresponding to the target topic; the server-side tool module is used to push the topic message; the capability platform is used to verify the access signature; Redis is used to store the preset encrypted private key and the preset encrypted public key.
[0053] The message subscription method based on the Netty framework provided by the embodiment of the present disclosure is adopted, by establishing a message push center between the message client and the message server, and through the topic message request, the message server sends the topic message corresponding to the target topic to the message queue middleware, and then uses the message queue middleware to send the message queue carrying the topic message to the Netty server, and then pushes the topic message to the message client through the message push channel. In this way, compared with the system transmitting data through respective data transmission channels, the data transmission method between the message client and the message server is unified through the message push center, which reduces the coupling degree of the system in data transmission, thereby reducing the development cost of the access service, and reducing the number of data transmission channels and the channel maintenance cost.
[0054] Combination Figure 3 As shown, the embodiment of the present disclosure provides a message subscription method based on the Netty framework, including:
[0055] Step S301, the client obtains the target topic and establishes a message client corresponding to the target topic;
[0056] Step S302, the client establishes a WebSocket connection between the message client and the Netty server;
[0057] Step S303, the client sends a signature acquisition request to the message server;
[0058] The token acquisition request includes an identity authentication token, a connection identifier, and a target subject;
[0059] Step S304, the message server performs identity authentication based on the identity authentication token, and after the identity authentication is passed, generates an access signature corresponding to the target subject;
[0060] Step S305, the message server sends an access signature to the client;
[0061] Step S306, the client sends a channel cache request to the Netty server;
[0062] Among them, the channel cache request carries the connection identifier, the target subject and the access signature;
[0063] Step S307, the Netty server performs signature verification on the access signature according to the preset verification key, and caches the message push channel after the signature verification passes;
[0064] Step S308, the client sends a topic message request corresponding to the target topic to the message server;
[0065] Step S309, the message server obtains the topic message corresponding to the target topic;
[0066] Step S310, the message server generates a push signature corresponding to the topic message according to the topic message corresponding to the target topic;
[0067] Step S311, the message server sends a push signature and a subject message to the push service;
[0068] Step S312: The push service verifies the push signature based on the preset encryption public key, and pushes the topic message to the message queue middleware after the signature verification passes;
[0069] Step S313, the message queue middleware sends a message queue carrying the topic message to the Netty server;
[0070] Step S314: The Netty server pushes the topic message to the message client through the message push channel.
[0071] The message subscription method based on the Netty framework provided by the embodiment of the present disclosure is adopted, by establishing a message push center between the message client and the message server, and by using a topic message request, the message server sends the topic message corresponding to the target topic to the message queue middleware, and then uses the message queue middleware to send the message queue carrying the topic message to the Netty server, and then pushes the topic message to the message client through the message push channel, which has the following advantages:
[0072] First, compared with the data transmission through the respective data transmission channels of the system, the data transmission method between the message client and the message server is unified through the message push center, which reduces the coupling degree of the system in data transmission, thereby reducing the development cost of access services;
[0073] Second, it reduces the number of data transmission channels and reduces channel maintenance costs;
[0074] Third, if the topic type subscribed by the message client is a private topic, the message client first applies to the message server for the access signature corresponding to the target topic, and then makes the Netty server perform signature verification on the access signature according to the preset verification key, and caches the message push channel after the signature verification passes, thereby realizing data transmission. Among them, the topic type is divided into public topics and private topics, which improves the flexibility and security of topic subscription;
[0075] Fourth, provide a corresponding number of Netty servers according to the number of target topics, thereby improving data transmission efficiency. At the same time, when the number of target topics decreases, reduce the corresponding number of Netty servers to reduce transmission costs.
[0076] Combination Figure 4 As shown, the embodiment of the present disclosure provides a message subscription system based on the Netty framework, including an acquisition module 401, an establishment module 402, a subscription module 403 and a push module 404. The acquisition module 401 is used to acquire the message client and the message server corresponding to the target topic; the establishment module 402 is used to establish a message push center between the message client and the message server, wherein the message push center includes a Netty server and a message queue middleware; the subscription module 403 is used to establish a message push channel corresponding to the target topic between the message client and the Netty server, and send a topic message request corresponding to the target topic to the message server, so that the message server sends the topic message corresponding to the target topic to the message queue middleware; the push module 404 is used to use the message queue middleware to send the message queue carrying the topic message to the Netty server, so that the Netty server pushes the topic message to the message client through the message push channel.
[0077] The message subscription system based on the Netty framework provided by the embodiment of the present disclosure is adopted, by establishing a message push center between the message client and the message server, and through the topic message request, the message server sends the topic message corresponding to the target topic to the message queue middleware, and then uses the message queue middleware to send the message queue carrying the topic message to the Netty server, and then pushes the topic message to the message client through the message push channel. In this way, compared with the system transmitting data through respective data transmission channels, the data transmission method between the message client and the message server is unified through the message push center, which reduces the coupling degree of the system in data transmission, thereby reducing the development cost of the access service, and reducing the number of data transmission channels and the channel maintenance cost.
[0078] Figure 5 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 5 The computer system 500 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0079] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage part 508 to the random access memory (RAM) 503, such as executing the method in the above embodiment. In RAM503, various programs and data required for system operation are also stored. CPU501, ROM502 and RAM503 are connected to each other through a bus 504. Input / output (I / O) interface 505 is also connected to bus 504.
[0080] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed so that a computer program read therefrom is installed into the storage section 508 as needed.
[0081] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 509, and / or installed from a removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, various functions defined in the system of the present application are executed.
[0082] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0083] The embodiments of the present disclosure further provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, any one of the methods in the embodiments is implemented.
[0084] The computer-readable storage medium in the embodiments of the present disclosure can be understood by ordinary technicians in the field: all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the execution includes the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0085] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run the computer program so that the electronic device executes each step of the above method.
[0086] In this embodiment, the memory may include a random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0087] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0088] The above description and accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. Parts and subsamples of some embodiments may be included in or replace parts and subsamples of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of a stated sub-sample, whole, step, operation, element, and / or component, but do not exclude the presence or addition of one or more other sub-samples, wholes, steps, operations, elements, components and / or groups of these. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0089] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0090] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0091] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A message subscription method based on Netty framework, characterized in that: include: Get the message client and message server corresponding to the target topic; Establish a message push center between the message client and the message server, wherein the message push center includes a Netty server and a message queue middleware; Establishing a message push channel corresponding to the target topic between the message client and the Netty server, and sending a topic message request corresponding to the target topic to the message server, so that the message server sends the topic message corresponding to the target topic to the message queue middleware; Using the message queue middleware, the message queue carrying the subject message is sent to the Netty server, so that the Netty server pushes the subject message to the message client through the message push channel; After establishing a message push center between the message client and the message server, the method further includes obtaining the number of topics of the target topic; if the number of topics is less than a preset number threshold, using the preset minimum number as the number of servers of the Netty server; if the number of topics is greater than or equal to the preset number threshold, using the number of topics as the number of servers of the Netty server, wherein the target topic, the Netty server, and the message push channel correspond one to one; Set the client tool module corresponding to the message client through the SDK tool. The client tool module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server, receive the topic message pushed by the Netty server, perform the authentication task corresponding to the private topic, perform heartbeat detection on the Netty server, and send the topic message request corresponding to the target topic to the message server. A server-side tool module is set on the message server through the SDK tool, wherein the server-side tool module is used to push topic messages.
2. The method according to claim 1, characterized in that Establishing a message push channel corresponding to the target topic between the message client and the Netty server includes: Acquire a topic type corresponding to the target topic, wherein the topic type includes a public topic or a private topic; Establishing a communication connection between the message client and the Netty server, so that the Netty server generates a connection identifier corresponding to the communication connection; If the topic type includes a public topic, a channel cache request carrying the connection identifier and the target topic is sent to the Netty server, so that the Netty server uses the communication connection corresponding to the connection identifier as a message push channel corresponding to the target topic, and caches the message push channel; If the topic type includes a private topic, an access signature corresponding to the target topic is applied to the message server, and a channel cache request carrying the connection identifier, the target topic and the access signature is sent to the Netty server, so that the Netty server performs signature verification on the access signature according to a preset verification key, and after the signature verification passes, the communication connection corresponding to the connection identifier is used as the message push channel corresponding to the target topic, and the message push channel is cached.
3. The method according to claim 2, characterized in that Get the message client corresponding to the target topic in the following ways: Obtain a Web client, the Web client comprising a client tool module, a target topic, and a message consumption application corresponding to the target topic, wherein the client tool module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server; Establishing a message client corresponding to the target topic, wherein the target topic and the message consumption application are transmitted to the message client; If the topic type includes a private topic, a preset authentication interface address is transmitted to the message client, wherein the authentication interface address is located on the message server.
4. The method according to claim 3, characterized in that Applying for the access signature corresponding to the target topic from the message server includes: Obtaining an identity authentication token, wherein the identity authentication token is used to represent the Web client; Utilize the client tool module to send the identity authentication token, the connection identifier and the target subject to the authentication interface address of the message server, so that the message server performs identity authentication according to the identity authentication token, and after the identity authentication is passed, encrypt at least one of the identity authentication token, the connection identifier and the target subject according to a preset encryption private key to obtain an access signature corresponding to the target subject; Receive the access signature fed back by the authentication interface address.
5. The method according to any one of claims 1 to 4, characterized in that: The message server sends the topic message corresponding to the target topic to the message queue middleware in the following manner: The message server is provided with a server tool module, and the message push center also includes a push service; Compress the subject message corresponding to the target subject using the server-side tool module to obtain an information summary, and encrypt the information summary according to a preset encryption private key to obtain a push signature corresponding to the subject message, and send the push signature and the subject message to the push service; The push service is used to perform signature verification on the push signature based on a preset encryption public key, and the subject message is pushed to the message queue middleware after the signature verification passes.
6. The method according to any one of claims 1 to 4, characterized in that: After establishing a message push center between the message client and the message server, the method further includes: Perform a heartbeat test on the Netty server to obtain a heartbeat test result and monitor the subscription status of the target topic; If the first cleaning condition or the second cleaning condition is met, the message push channel between the message client and the Netty server is cleaned up, wherein the first cleaning condition includes that the heartbeat detection result includes a heartbeat timeout, and the second cleaning condition includes that the subscription status is monitored to include unsubscribed.
7. A message subscription system based on Netty framework, characterized in that: include: The acquisition module is used to obtain the message client and message server corresponding to the target topic; Establish a module for establishing a message push center between a message client and a message server, wherein the message push center includes a Netty server and a message queue middleware; A subscription module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server, and send a topic message request corresponding to the target topic to the message server, so that the message server sends the topic message corresponding to the target topic to the message queue middleware; A push module, used to send the message queue carrying the subject message to the Netty server by using the message queue middleware, so that the Netty server pushes the subject message to the message client through the message push channel; After establishing a message push center between the message client and the message server, the establishment module is further used to obtain the number of topics of the target topic; if the number of topics is less than a preset number threshold, the preset minimum number is used as the number of servers of the Netty server; if the number of topics is greater than or equal to the preset number threshold, the number of topics is used as the number of servers of the Netty server, wherein the target topic, the Netty server, and the message push channel correspond one to one; The acquisition module is also used to set the client tool module corresponding to the message client through the SDK tool, wherein the client tool module is used to establish a message push channel corresponding to the target topic between the message client and the Netty server, and receive the topic message pushed by the Netty server, and is also used to perform the authentication task corresponding to the private topic, perform heartbeat detection on the Netty server, and send a topic message request corresponding to the target topic to the message server; The acquisition module is also used to set a server-side tool module on the message server side through the SDK tool, wherein the server-side tool module is used to push the topic message.
8. An electronic device, characterized in that: include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
High availability distributed queues
CN111309501A
Message processing method and device and message cluster server
CN112307487A