SIP communication method and system based on asynchronous message processing, electronic equipment and storage medium

By adopting asynchronous message processing method in SIP communication technology, using non-blocking I/O model and dynamic scaling mechanism, the problems of complexity, scalability and concurrency capabilities in existing SIP communication technologies are solved, and an efficient and flexible SIP communication system is realized.

CN120166097APending Publication Date: 2025-06-17SHENZHEN CORERAIN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510190198.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-06-17

AI Technical Summary

Technical Problem

The existing SIP communication technology has problems such as complex implementation, insufficient scalability, limited concurrency capability and lack of dynamic configuration capabilities.

Method used

The SIP communication method based on asynchronous message processing is adopted, and the client's SIP request message is received asynchronously through a non-blocking I/O model, and the SIP request message is parsed and responded with the preset dynamic expansion mechanism and load balancing and clustering mechanism, and distributed and processed through asynchronous sending.

Benefits of technology

It improves the system's concurrency capability and response speed, supports tens of thousands of concurrent connections, meets the needs of high-concurrency scenarios, and reduces code coupling and resource usage through dynamic scaling mechanisms and load balancing mechanisms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120166097A_ABST
    Figure CN120166097A_ABST
Patent Text Reader

Abstract

The invention provides an SIP (Session Initiation Protocol) communication method and system based on asynchronous message processing, electronic equipment and a storage medium. Relates to the technical field of SIP communication. The SIP communication method comprises the following steps: asynchronously receiving an SIP request message of a client based on a non-blocking I / O model; analyzing and responding to the SIP request message based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to obtain an SIP response message; and carrying out asynchronous distribution processing on the SIP response message based on a preset asynchronous sending mode.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of SIP communication, and in particular, to a SIP communication method and system, an electronic device, and a storage medium based on asynchronous message processing. Background Art

[0002] SIP (Session Initiation Protocol) is a text-based application layer protocol (session initiation protocol), which is widely used to establish, modify, and terminate multimedia sessions, and has the characteristics of flexibility, modularity, and openness. SIP can support multiple session types (such as voice, video, instant messaging, etc.) and is compatible with multiple transport protocols. SIP consists of multiple functional modules, including user agents, proxy servers, redirect servers, and registration servers, etc., and each functional module works together through standard interfaces.

[0003] Currently, SIP can be developed based on open-source SIP servers, but the inventors of the present invention have found that the current SIP still faces the following technical problems:

[0004] 1. Complex implementation: Traditional SIP services are usually developed based on low-level languages (such as C / C++), with high code complexity and high maintenance costs.

[0005] 2. Insufficient scalability: The plug-in mechanism and function expansion often require in-depth customization, with a long development cycle and difficulty in quickly responding to business requirements.

[0006] 3. Concurrency capacity limitation: The blocking model is difficult to efficiently handle a large number of connections and concurrent sessions, with obvious performance bottlenecks.

[0007] 4. Lack of dynamic configuration ability: Most implementations lack the ability of dynamic expansion and cannot quickly adapt to changes in business requirements.

[0008] The content of the background art section is only the technology known to the applicant and does not necessarily represent the prior art in this field. Summary of the Invention

[0009] The present invention provides a SIP communication method and system, an electronic device, and a storage medium based on asynchronous message processing, which are used to solve the problems of complex implementation, insufficient scalability, concurrency capacity limitation, and lack of dynamic configuration ability existing in the current SIP protocol.

[0010] In one aspect of the present invention, there is provided a SIP communication method based on asynchronous message processing, including: asynchronously receiving a SIP request message from a client based on a non-blocking I / O model; parsing and responding to the SIP request message based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to obtain a SIP response message; and asynchronously distributing and processing the SIP response message based on a preset asynchronous sending method.

[0011] According to some embodiments of the present invention, when the SIP request message includes a TCP message type, asynchronously receiving the SIP request message from the client based on a non-blocking I / O model includes: starting a target asynchronous TCP server; and asynchronously reading the SIP request message through a first asynchronous reading method based on the coroutine of the target asynchronous TCP server.

[0012] According to some embodiments of the present invention, when the SIP request message includes a UDP message type, asynchronously receiving the SIP request message from the client based on a non-blocking I / O model includes: starting a UDP listener; and asynchronously reading the SIP request message through a second asynchronous reading method based on the UDP listener.

[0013] According to some embodiments of the present invention, the preset dynamic extension mechanism at least includes one of a core SIP engine, a plugin manager, a plugin module, and an event-driven architecture.

[0014] According to some embodiments of the present invention, the preset load balancing and clustering mechanism at least includes one of a load balancer, a SIP processing node, a Redis cluster, and a Kafka message queue.

[0015] According to some embodiments of the present invention, parsing and responding to the SIP request message based on the preset dynamic extension mechanism and the preset load balancing and clustering mechanism includes: parsing the request line, headers, and SDP message of the SIP request message to obtain a SIP parsed message; and performing asynchronous response processing based on the SIP parsed message under the preset dynamic extension mechanism and the preset load balancing and clustering mechanism to obtain a SIP response message.

[0016] According to some embodiments of the present invention, the SIP communication method may further include: parsing and responding to the SIP request message based on a high-concurrency scenario optimization mechanism to obtain a SIP response message; wherein the high-concurrency scenario optimization mechanism at least includes one of event loop optimization, connection pool management, and traffic control.

[0017] On one aspect of the present invention, there is also provided a SIP communication system based on asynchronous message processing, including an asynchronous message receiving module, an asynchronous message processing module, and an asynchronous message distribution module. The asynchronous message receiving module asynchronously receives SIP request messages from clients based on a non-blocking I / O model; the asynchronous message processing module parses and responds to the SIP request messages based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to obtain SIP response messages; the asynchronous message distribution module asynchronously distributes and processes the SIP response messages based on a preset asynchronous sending method.

[0018] On another aspect of the present invention, there is also provided an electronic device. The electronic device includes: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enable the one or more processors to implement the SIP communication method as described above.

[0019] On another aspect of the present invention, there is also provided a non-volatile computer-readable storage medium. A computer program is stored on the storage medium, and when the computer program is executed by a processor, it can implement the SIP communication method as described above.

[0020] On another aspect of the present invention, there is also provided a computer program product. The computer program product includes: a computer program stored on a computer-readable storage medium; the computer program includes program instructions, which, when executed by a computer, cause the computer to execute the SIP communication method as described above.

[0021] Beneficial effects

[0022] The present invention asynchronously receives SIP request messages from clients based on a non-blocking I / O model, parses and responds to the SIP request messages based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to obtain SIP response messages, and can asynchronously distribute and process the SIP response messages based on a preset asynchronous sending method.

[0023] The present invention can avoid the overhead of thread / process context switching based on the asynchronous message processing ability of the non-blocking I / O model, improve the system throughput, support tens of thousands of concurrent connections, and meet the requirements of high-concurrency scenarios. The reception, parsing, response, and forwarding of SIP request messages in the present invention can all be completed through asynchronous event processing, which can reduce resource occupancy and improve the response speed. Based on the preset dynamic extension mechanism, the present invention can quickly add functions through plugins, and different functional modules are independent of each other, which can reduce the coupling degree of the code. The present invention is also based on a preset load balancing and clustering mechanism for distributed deployment. Brief description of the drawings

[0024] To more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0025] Figure 1 Fig. 4 shows a schematic flowchart of the SIP communication method according to an embodiment of the present invention;

[0026] Figure 2 Fig. 5 shows another schematic flowchart of the SIP communication method according to an embodiment of the present invention;

[0027] Figure 3 Fig. 6 shows another schematic flowchart of the SIP communication method according to an embodiment of the present invention;

[0028] Figure 4 Fig. 7 shows another schematic flowchart of the SIP communication method according to an embodiment of the present invention;

[0029] Figure 5 Fig. 8 shows a schematic structural diagram of the SIP communication system according to an embodiment of the present invention.

[0030] Explanation of reference numerals:

[0031] SIP communication system 1; asynchronous message receiving module 10; asynchronous message processing module 20; asynchronous message distribution module 30. Detailed implementation manners

[0032] The following will clearly and completely describe the technical solutions of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, rather than all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.

[0033] The full names and Chinese interpretations of the English abbreviations involved in the present invention are as follows:

[0034] SIP: Session Initiation Protocol, session initiation protocol;

[0035] TCP: Transmission Control Protocol, transmission control protocol;

[0036] UDP: User Datagram Protocol, user datagram protocol;

[0037] TLS: Transport Layer Security, a transport layer security protocol;

[0038] HTTP: HyperText Transfer Protocol, a hypertext transfer protocol;

[0039] Redis Cluster: an open-source in-memory data structure storage system;

[0040] Kafka: a distributed message queue system;

[0041] SDP: Session Description Protocol, a protocol used to describe multimedia sessions.

[0042] According to one aspect of the present invention, the present invention provides a SIP communication method based on asynchronous message processing. Figure 1 A flowchart showing the SIP communication method according to an embodiment of the present invention is as follows. Figure 1 As shown, the SIP communication method may include steps S100 - S300.

[0043] Exemplarily, the SIP communication method may be executed by a SIP communication system with computing capabilities.

[0044] According to an exemplary embodiment, in step S100, the SIP communication system asynchronously receives a SIP request message from a client based on a non-blocking I / O model.

[0045] The non-blocking I / O model is a programming paradigm model that allows a program to continue executing other tasks while waiting for an I / O operation (such as reading / writing a file, network communication, etc.) to complete, rather than blocking the current thread until the operation is completed.

[0046] The implementation of the non-blocking I / O model may include polling, callbacks, event loops, and signal-driven I / O, etc. The non-blocking I / O model has characteristics such as high concurrency (allowing a single thread to handle multiple I / O operations), resource efficiency (not requiring a separate thread to be created for each I / O operation, saving system resources), and rapid response (the program can immediately respond to other tasks without waiting for the I / O operation to complete).

[0047] Exemplarily, common tools and libraries for the non-blocking I / O model include but are not limited to development languages such as Python, JavaScript, C / C++, and Java, etc. The present invention does not limit this.

[0048] As an embodiment, the present invention will hereinafter take Python as an example to introduce the technical solution of the present invention in detail.

[0049] Exemplarily, the non-blocking I / O model of Python can be the asyncio framework.

[0050] In step S100, the SIP communication system can receive a SIP request message from the client based on the asynchronous programming ability of the asyncio framework of Python.

[0051] Figure 2 Another flowchart showing the SIP communication method according to an embodiment of the present invention is as follows. Figure 2 As shown, step S100 may include steps S111 - S112.

[0052] According to an exemplary embodiment, SIP can support multiple transport protocols such as TCP, UDP, and TLS, and each transport protocol can be defined as a type of SIP message.

[0053] For example, the TCP transport protocol can correspond to the TCP message type, the UDP transport protocol can correspond to the UDP message type, and the TLS transport protocol can correspond to the TLS message type.

[0054] Optionally, when the SIP request message includes the TCP message type, in step S111, the SIP communication system starts a target asynchronous TCP server.

[0055] In step S112, the SIP communication system asynchronously reads the SIP request message based on the coroutine of the target asynchronous TCP server through a first asynchronous reading method.

[0056] For example, the SIP communication system starts an asynchronous TCP server through "asyncio.start_server", where the processing logic for each connection will be completed by a coroutine (such as "handle_client").

[0057] In this coroutine, the SIP communication system can asynchronously read the message sent by the client through the first asynchronous reading method without blocking the entire event loop. As an embodiment, the first asynchronous reading method can be the "reader.read" reading method.

[0058] Figure 3 Another flowchart showing the SIP communication method according to an embodiment of the present invention is as follows. Figure 3 As shown, step S100 may further include steps S121 - S122.

[0059] Optionally, when the SIP request message includes the UDP message type, in step S121, the SIP communication system starts a UDP listener.

[0060] In step S112, the SIP communication system asynchronously reads the SIP request message based on UDP listening through a second asynchronous reading method.

[0061] For example, the SIP communication system uses "asyncio.create_datagram_endpoint" to create a UDP listening endpoint and calls the second asynchronous reading method to asynchronously read the message sent by the client. As an embodiment, the second asynchronous reading method can be the "datagram_received" reading method.

[0062] In step S200, the SIP communication system parses and responds to the SIP request message based on a preset dynamic expansion mechanism and a preset load balancing and clustering mechanism to obtain a SIP response message.

[0063] Optionally, the preset dynamic expansion mechanism (framework) can at least include one of a core SIP engine, a plugin manager, a plugin module, and an event-driven architecture.

[0064] For example, the core SIP engine can receive, parse, route, and respond to the SIP request message, and at the same time can define a plugin interface for external plugin integration.

[0065] The plugin manager is responsible for registering, dynamically loading, and managing plugins, and establishing a connection between the SIP request message and the plugin logic through an event bus or a hooks mechanism. For example, plugin loading can dynamically load plugin modules from a specified directory, and the event bus can provide an event publishing and subscribing mechanism and can register plugins into the core SIP engine.

[0066] Each plugin module can implement specific functions (such as an authentication plugin, a log analysis plugin, a real-time monitoring plugin, etc.) and follow the standard interfaces defined by the core SIP engine (such as handling events, accessing message contexts, etc.). For example, the authentication plugin can verify the legality of the SIP request message (such as checking the username and password), the log analysis plugin can record the detailed information of the SIP request message, and the real-time monitoring plugin can monitor the traffic and status of the SIP request message, etc.

[0067] The event-driven architecture can trigger plugin logic in an event-driven manner to reduce coupling. And it can trigger events at specific lifecycle stages (such as "on_message_received", "on_message_parsed", etc.). For example, communication between the plugin and the core SIP engine is through events and there is no direct dependency.

[0068] As an embodiment, the implementation method of plugin registration (plugin extension mechanism) can include:

[0069] 1. The core SIP engine defines a unified plug-in interface that all plug-ins must implement, and the methods that the plug-ins need to implement are defined in the interface.

[0070] 2. The plug-in manager is responsible for the dynamic loading, unloading, and invocation of plug-ins. It can load plug-ins by scanning the plug-in directory or configuration file and register the plug-ins into the core SIP engine.

[0071] 3. The core SIP engine triggers events at key points and passes the message context to the plug-ins.

[0072] As another embodiment, the implementation of the dynamic loading of plug-ins may include:

[0073] 1. The plug-in configuration file defines the plug-ins to be loaded and their parameters.

[0074] 2. When the core SIP engine starts, it dynamically loads the plug-ins specified in the configuration file.

[0075] 3. Dynamically unload the unnecessary plug-ins.

[0076] Through the above embodiments, the preset dynamic extension mechanism provided by the present invention can be responsible for the core processing logic of SIP request messages through the core SIP engine, dynamically load and manage plug-ins through the plug-in manager, implement specific functions through the plug-in module, follow the standard interface, and execute event-triggered plug-in logic through the event-driven architecture, reducing coupling. With such settings, the present invention can expand the functions of the core SIP engine, such as adding plug-ins for authentication, log analysis, real-time monitoring, etc., and can maintain the flexibility and maintainability of the system.

[0077] Optionally, the preset load balancing and clustering mechanism includes at least one of a load balancer, SIP processing nodes, a Redis cluster, and a Kafka message queue.

[0078] According to the exemplary embodiment, when implementing the horizontal expansion mechanism and adapting to the distributed deployment, the setting of the load balancing and clustering mechanism (framework) is an important node.

[0079] The load balancer can distribute traffic to multiple backend service nodes to ensure the high availability and scalability of the system.

[0080] For example, the SIP communication system can use Nginx or HAProxy to achieve the initial distribution of SIP requests. Nginx is a high-performance HTTP and reverse proxy server, and also supports TCP and UDP load balancing. The load balancing of the SIP protocol can be achieved by configuring the stream module of Nginx. HAProxy is software for load balancing, supporting TCP and HTTP protocol load balancing. The configuration of HAProxy is relatively simple and has good support for the SIP protocol. In HAProxy, the TCP and UDP load balancing can be configured through the "mode tcp" and "mode udp" modules respectively.

[0081] The SIP processing node is a service node that actually processes SIP requests. By setting multiple SIP processing nodes, horizontal expansion can be achieved to improve the processing capacity of the system. Multiple SIP processing nodes can run simultaneously, and each SIP processing node can independently process SIP request messages. In the present invention, the session state and task queue can be shared among multiple SIP processing nodes to ensure seamless switching of SIP requests between different SIP processing nodes.

[0082] Each SIP processing node can independently run a SIP engine and can synchronize the session state (such as registration information, routing table, etc.) through a Redis cluster, so as to ensure that all SIP processing nodes can access consistent state information.

[0083] The Redis cluster is used to store and share the session state to ensure state consistency among multiple SIP processing nodes.

[0084] For example, the Redis cluster is used to store and share the SIP session state, such as user registration information, routing table, call status, etc. Through the Redis cluster, multiple SIP processing nodes can obtain and update the session state in real time to ensure the consistency of the system. In addition, the Redis cluster supports high availability and distributed deployment, and can achieve failover and data redundancy.

[0085] Kafka is a distributed message queue system that can handle high-throughput messages. SIP request messages (such as INVITE requests, BYE requests, etc.) can be asynchronously processed through the Kafka message queue, which can avoid blocking the SIP processing nodes.

[0086] In the present invention, through the Kafka message queue, SIP request messages can be asynchronously processed, which can improve the response speed and throughput of the system.

[0087] Through the above embodiments, the load balancing and clustering mechanism provided by the present invention can be responsible for distributing SIP requests to multiple SIP processing nodes through a load balancer (Nginx or HAProxy). The SIP processing nodes share session states through a Redis cluster, which can ensure consistency. The Redis cluster can provide high availability and distributed storage, supporting the sharing of session states. The Kafka message queue is used for asynchronous processing of SIP messages, which can improve the throughput and response speed of the system. With such settings, it can effectively handle high-concurrency and large-scale SIP request messages, and at the same time has good scalability and fault tolerance capabilities.

[0088] The SIP communication system can perform corresponding parsing and response on SIP request messages based on the above preset dynamic expansion mechanism and preset load balancing and clustering mechanism.

[0089] Figure 4 Another flowchart showing the SIP communication method according to an embodiment of the present invention is as follows Figure 4 As shown, step S200 may further include steps S210 - S220.

[0090] In step S210, the SIP communication system performs request line parsing, header parsing, and SDP message parsing on the SIP request message to obtain a SIP parsing message.

[0091] For example, request line parsing may include: extracting the method (such as INVITE), request URI, and protocol version from the first line of the SIP request message. Header parsing includes reading each header field (such as To, From, Via, etc.) line by line and storing them in a dictionary structure for subsequent use. SDP message parsing includes parsing the SDP media description part if the SIP request message contains "Content-Type: application / sdp". With such settings, the SIP request message can be efficiently parsed and can support expansion (such as parsing other types of message bodies).

[0092] In step S220, the SIP communication system performs asynchronous response processing based on the SIP parsing message under the preset dynamic expansion mechanism and preset load balancing and clustering mechanism to obtain a SIP response message.

[0093] For example, the SIP communication system can perform asynchronous response processing on the SIP parsing message based on the preset dynamic expansion mechanism and preset load balancing and clustering mechanism. This asynchronous response processing may include:

[0094] 1. Determine the response code. The SIP communication system can generate a corresponding response code according to the request type (such as 200 OK or 404 Not Found, etc.);

[0095] 2. Construct a response message. The response message generated by the SIP communication system needs to include fields such as the requested Call-ID and CSeq to ensure correlation.

[0096] In step S300, the SIP communication system performs asynchronous distribution processing on the SIP response message based on a preset asynchronous sending method.

[0097] For example, the SIP communication system can send the SIP response message corresponding to the TCP message type based on a preset asynchronous sending method such as "writer.write"; it can also send the SIP response message corresponding to the UDP message type based on a preset asynchronous sending method such as "transport.sendto".

[0098] For another example, the SIP communication system can also perform asynchronous message forwarding, including:

[0099] 1. Find the target address. The SIP communication system extracts the target user address from the To or Request-URI in the message header;

[0100] 2. Asynchronously connect to the target server. The SIP communication system uses "asyncio.open_connection" to create a connection;

[0101] 3. Forward the message and wait for a response. Asynchronously send the message to the target server and wait for the response from the target server before returning it to the original requester.

[0102] As an embodiment, taking the TCP message type as an example, the SIP communication process provided by the present invention can be as follows:

[0103] 1. Start an asynchronous TCP server based on "asyncio.start_server";

[0104] 2. The processing logic for each connection will be completed by a coroutine (such as "handle_client");

[0105] 3. Asynchronously receive TCP request messages based on the "reader.read" reading method;

[0106] 4. Parse the TCP request message based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to generate a SIP response message;

[0107] 5. Asynchronously send the SIP response message based on the "writer.write" asynchronous sending method.

[0108] In this communication process, all connections share the time loop. Such a setting can avoid the switching overhead of threads / processes.

[0109] As another embodiment, taking the UDP message type as an example, the SIP communication process provided by the present invention may be as follows:

[0110] 1. Start the UDP service based on "asyncio.create_datagram_endpoint";

[0111] 2. Listen on a specified port and receive data packets;

[0112] 3. Asynchronously receive UDP request messages based on the "datagram_received" reading method;

[0113] 4. Parse the UDP request message based on a preset dynamic expansion mechanism and a preset load balancing and clustering mechanism to generate a SIP response message;

[0114] 5. Asynchronously send the SIP response message based on the "transport.sendto" asynchronous sending method.

[0115] In this communication process, there is no need to maintain the session connection state and it can be directly processed and responded to.

[0116] As another embodiment, taking the TCP message type and the UDP message type as examples, the SIP communication process provided by the present invention may be as follows:

[0117] 1. Use "asyncio.gather" to concurrently start the TCP and UDP services;

[0118] 2. Process the communication of the two transport protocols in the same event loop.

[0119] Optionally, the SIP communication system can set the maximum number of connections, which can prevent the service from crashing due to overload.

[0120] Exemplarily, the maximum number of connections can be custom-set according to user requirements.

[0121] Through the above embodiments, the present invention can support the UDP and TCP transport layer protocols based on asynchronous I / O. It can be understood that in the case of high concurrency, the traditional blocking I / O model will have performance bottlenecks due to the high overhead of thread / process switching. The present invention can manage tens of thousands of concurrent connections within a single thread by using asynchronous I / O, which can improve the network communication efficiency.

[0122] Optionally, in step S200, the SIP communication system can also parse and respond to the SIP request message based on a high-concurrency scenario optimization mechanism.

[0123] The high-concurrency scenario optimization mechanism can at least include one of event loop optimization, connection pool management, and traffic control.

[0124] For example, event loop optimization can include: The SIP communication system can use uvloop to replace the default event loop. uvloop is an implementation of a high-performance event loop and is designed specifically for Python's asyncio framework. Compared with Python's default event loop, uvloop can improve the performance of I / O-intensive tasks, especially in high-concurrency scenarios.

[0125] Connection pool management can include: The SIP communication system reuses connections to the target server. In high-concurrency scenarios, frequent creation and destruction of connections incur significant overhead. Through connection pool management in the present invention, established connections can be reused, reducing connection overhead.

[0126] Traffic control can include: In high-concurrency scenarios, limit the number of request processing per second. For example, in high-concurrency scenarios, without control, it may cause server overload, thereby affecting system stability. Through rate-limiting algorithms or concurrency control mechanisms in the present invention, system overload can be prevented.

[0127] Through the above embodiments, the present invention asynchronously receives SIP request messages from clients based on a non-blocking I / O model, parses and responds to the SIP request messages based on a preset dynamic expansion mechanism and a preset load balancing and clustering mechanism to obtain SIP response messages, and can asynchronously distribute and process the SIP response messages based on a preset asynchronous sending method.

[0128] The present invention features high-performance optimization. For example, based on the asynchronous message processing ability of the non-blocking I / O model, the present invention avoids the overhead of thread / process context switching, can improve system throughput, support tens of thousands of concurrent connections, and meet the requirements of high-concurrency scenarios. The reception, parsing, response, and forwarding of SIP request messages in the present invention can all be completed through asynchronous event processing, which can reduce resource occupancy and improve response speed. Based on a preset dynamic expansion mechanism, the present invention can quickly add functions through plugins, and different functional modules are independent of each other, which can reduce code coupling. The present invention can also be distributedly deployed based on a preset load balancing and clustering mechanism.

[0129] The present invention features high flexibility and scalability. For example, through a state sharing mechanism based on a Redis cluster, it can be horizontally extended in a multi-node environment. And through a Kafka message queue, asynchronous message distribution can be achieved, further enhancing the scalability of the system. Also, the present invention can support multiple transport protocols such as UDP and TCP simultaneously, and can adapt to various application scenarios.

[0130] The present invention features high reliability. For example, through the Redis cluster, the present invention can achieve the sharing of SIP user registration information and session status, ensuring consistency among multiple nodes. And the data persistence mechanism (Redis persistence and Kafka logs) reduces the risk of accidental data loss. The present invention can also use Nginx / HAProxy for load balancing to ensure that a single point of failure will not affect the overall operation of the system. And the multi-replica mechanism of Kafka guarantees the high availability of message processing. Additionally, the plug-in architecture can support TLS encrypted transmission and custom authentication mechanisms, which can enhance communication security.

[0131] The present invention also features low development and operation costs. For example, the present invention can use the Python language, whose code is concise and easy to read, with high development efficiency, reducing the engineering complexity. And it can leverage high-performance libraries in the Python ecosystem to avoid developing underlying logic from scratch. The present invention can also support containerized deployment and can be quickly deployed to various environments (such as local and cloud). And the distributed deployment mechanism reduces the single-machine resource bottleneck and improves hardware utilization. And the plug-in design and modular structure facilitate system maintenance and function expansion.

[0132] The present invention also features high application value. For example, the present invention can support scenarios such as high-concurrency voice calls, video conferences, and instant messaging. And it can be used as a lightweight SIP server, suitable for the communication needs of small and medium-sized enterprises. It can also utilize the distributed architecture design and can be used as a core component of a large communication platform, supporting cross-region deployment. And it can also be compatible with mainstream SIP clients and relay services (such as Zoiper, Asterisk, Kamailio, etc.).

[0133] According to another aspect of the present invention, the present invention provides a SIP communication system based on asynchronous message processing. Figure 5 The structural schematic diagram of the SIP communication system showing the embodiments of the present invention is as follows. Figure 5 As shown, the SIP communication system 1 includes an asynchronous message receiving module 10, an asynchronous message processing module 20, and an asynchronous message distribution module 30.

[0134] According to the exemplary embodiment, the asynchronous message receiving module 10 asynchronously receives the SIP request message from the client based on the non-blocking I / O model.

[0135] The non-blocking I / O model is a programming paradigm model that allows the program to continue executing other tasks while waiting for I / O operations (such as reading and writing files, network communication, etc.) to complete, rather than blocking the current thread until the operation is completed.

[0136] The implementation of the non-blocking I / O model can include polling, callbacks, event loops, signal-driven I / O, etc. The non-blocking I / O model has characteristics such as high concurrency (allowing a single thread to handle multiple I / O operations), resource efficiency (not requiring the creation of separate threads for each I / O operation, saving system resources), and rapid response (the program can immediately respond to other tasks without waiting for the I / O operation to complete).

[0137] Exemplarily, common tools and libraries for the non-blocking I / O model include but are not limited to development languages such as Python, JavaScript, C / C++, and Java. The present invention does not limit this.

[0138] As an embodiment, the present invention will hereinafter take Python as an example to introduce the technical solution of the present invention in detail.

[0139] Exemplarily, the non-blocking I / O model of Python can be the asyncio framework.

[0140] The asynchronous message receiving module 10 can receive SIP request messages from the client based on the asynchronous programming ability of the asyncio framework of Python.

[0141] According to the example embodiment, SIP can support multiple transport protocols such as TCP, UDP, and TLS, and each transport protocol can be defined as a type of SIP message.

[0142] For example, the TCP transport protocol can correspond to the TCP message type, the UDP transport protocol can correspond to the UDP message type, and the TLS transport protocol can correspond to the TLS message type.

[0143] Optionally, when the SIP request message includes the TCP message type, the asynchronous message receiving module 10 starts a target asynchronous TCP server.

[0144] The asynchronous message receiving module 10 asynchronously reads the SIP request message through the first asynchronous reading method based on the coroutine of the target asynchronous TCP server.

[0145] For example, the asynchronous message receiving module 10 starts an asynchronous TCP server through "asyncio.start_server", where the processing logic for each connection will be completed by a coroutine (such as "handle_client").

[0146] In this coroutine, the asynchronous message receiving module 10 can asynchronously read the message sent by the client through the first asynchronous reading method without blocking the entire event loop. As an embodiment, the first asynchronous reading method can be the "reader.read" reading method.

[0147] Optionally, when the SIP request message includes a UDP message type, the asynchronous message receiving module 10 starts UDP listening.

[0148] Based on the UDP listening, the asynchronous message receiving module 10 asynchronously reads the SIP request message through a second asynchronous reading method.

[0149] For example, the asynchronous message receiving module 10 uses "asyncio.create_datagram_endpoint" to create a UDP listening endpoint and calls the second asynchronous reading method to asynchronously read the message sent by the client. As an embodiment, the second asynchronous reading method can be the "datagram_received" reading method.

[0150] According to the exemplary embodiment, the asynchronous message processing module 20 parses and responds to the SIP request message based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to obtain a SIP response message.

[0151] Optionally, the preset dynamic extension mechanism can at least include one of a core SIP engine, a plugin manager, a plugin module, and an event-driven architecture.

[0152] Optionally, the preset load balancing and clustering mechanism can at least include one of a load balancer, a SIP processing node, a Redis cluster, and a Kafka message queue.

[0153] The preset dynamic extension mechanism and the preset load balancing and clustering mechanism have been introduced in detail above, so they will not be elaborated here.

[0154] The asynchronous message processing module 20 can perform corresponding parsing and response on the SIP request message based on the above-mentioned preset dynamic extension mechanism and preset load balancing and clustering mechanism.

[0155] According to the exemplary embodiment, the asynchronous message processing module 20 performs request line parsing, header parsing, and SDP message parsing on the SIP request message to obtain a SIP parsing message.

[0156] For example, the request line parsing can include: extracting the method (such as INVITE), the request URI, and the protocol version from the first line of the SIP request message. The header parsing includes reading each header field (such as the To, From, Via, etc. fields) line by line and storing them in a dictionary structure for subsequent use. The SDP message parsing includes parsing the SDP media description part if the SIP request message contains "Content-Type:application / sdp". With such settings, the SIP request message can be parsed efficiently and can support extensions (such as parsing other types of message bodies).

[0157] Under the preset dynamic expansion mechanism and the preset load balancing and clustering mechanism, the asynchronous message processing module 20 performs asynchronous response processing based on the SIP parsed message to obtain the SIP response message.

[0158] For example, the asynchronous message processing module 20 can perform asynchronous response processing on the SIP parsed message based on the preset dynamic expansion mechanism and the preset load balancing and clustering mechanism. This asynchronous response processing may include:

[0159] 1. Determine the response code. The SIP communication system can generate the corresponding response code according to the request type (such as 200 OK or 404 Not Found, etc.);

[0160] 2. Construct the response message. The response message generated by the SIP communication system needs to include fields such as the requested Call-ID, CSeq, etc. to ensure relevance.

[0161] According to the example embodiment, the asynchronous message distribution module 30 performs asynchronous distribution processing on the SIP response message based on the preset asynchronous sending method.

[0162] For example, the asynchronous message distribution module 30 can send the SIP response message corresponding to the TCP message type based on the preset asynchronous sending method such as "writer.write"; it can also send the SIP response message corresponding to the UDP message type based on the preset asynchronous sending method such as "transport.sendto".

[0163] Again, for example, the SIP communication system can also perform asynchronous message forwarding, including:

[0164] 1. Find the target address. The SIP communication system extracts the target user address from the To or Request-URI in the message header;

[0165] 2. Asynchronously connect to the target server. The SIP communication system uses "asyncio.open_connection" to create a connection;

[0166] 3. Forward the message and wait for the response. Asynchronously send the message to the target server and wait for the response from the target server and then return it to the original requestor.

[0167] Optionally, the asynchronous message distribution module 30 can set the maximum number of connections, which can prevent the service from crashing due to overload.

[0168] Exemplarily, the maximum number of connections can be custom-set according to user requirements.

[0169] Through the above embodiments, the present invention can support UDP and TCP transport layer protocols based on asynchronous I / O. It can be understood that in high-concurrency scenarios, the traditional blocking I / O model will have performance bottlenecks due to the high overhead of thread / process switching. By using asynchronous I / O, the present invention can manage tens of thousands of concurrent connections within a single thread, which can improve network communication efficiency.

[0170] Optionally, the asynchronous message processing module 20 can also parse and respond to SIP request messages based on a high-concurrency scenario optimization mechanism.

[0171] The high-concurrency scenario optimization mechanism can at least include one of event loop optimization, connection pool management, and traffic control. The high-concurrency scenario optimization mechanism has also been described in detail above and will not be elaborated here.

[0172] Through the above embodiments, the present invention asynchronously receives SIP request messages from clients based on a non-blocking I / O model, parses and responds to SIP request messages based on a preset dynamic extension mechanism and a preset load balancing and clustering mechanism to obtain SIP response messages, and can asynchronously distribute and process SIP response messages based on a preset asynchronous sending method.

[0173] The present invention has the characteristics of high-performance optimization. For example, based on the asynchronous message processing ability of the non-blocking I / O model, the present invention can avoid the overhead of thread / process context switching, improve system throughput, support tens of thousands of concurrent connections, and meet the requirements of high-concurrency scenarios. The reception, parsing, response, and forwarding of SIP request messages in the present invention can all be completed through asynchronous event processing, which can reduce resource occupancy and improve response speed. Based on the preset dynamic extension mechanism, the present invention can quickly add functions through plugins, and different functional modules are independent of each other, which can reduce the code coupling degree. The present invention is also based on a preset load balancing and clustering mechanism for distributed deployment.

[0174] The present invention has the characteristics of high flexibility and scalability. For example, through the state sharing mechanism based on the Redis cluster, the present invention can be horizontally extended in a multi-node environment. And through the Kafka message queue, asynchronous message distribution can be achieved, further enhancing the scalability of the system. And the present invention can also support multiple transport protocols such as UDP and TCP at the same time, and can adapt to a variety of application scenarios.

[0175] The present invention features high reliability. For example, through the Redis cluster, the present invention can achieve the sharing of SIP user registration information and session status, ensuring consistency among multiple nodes. And the data persistence mechanism (Redis persistence and Kafka logs) reduces the risk of accidental data loss. The present invention can also use Nginx / HAProxy for load balancing to ensure that a single point of failure does not affect the overall operation of the system. And the multi-replica mechanism of Kafka guarantees the high availability of message processing. In addition, the plug-in architecture can support TLS encrypted transmission and custom authentication mechanisms, which can enhance communication security.

[0176] The present invention also features low development and operation and maintenance costs. For example, the present invention can use the Python language, whose code is concise and easy to read, with high development efficiency, reducing the engineering complexity. And it can leverage high-performance libraries in the Python ecosystem to avoid developing underlying logic from scratch. The present invention can also support containerized deployment and can be quickly deployed to various environments (such as local, cloud). And the distributed deployment mechanism reduces the single-machine resource bottleneck and improves hardware utilization. And the plug-in design and modular structure facilitate system maintenance and function expansion.

[0177] The present invention also features high application value. For example, the present invention can support scenarios such as high-concurrency voice calls, video conferences, instant messaging, etc. And it can be used as a lightweight SIP server, suitable for the communication needs of small and medium-sized enterprises. It can also utilize the distributed architecture design and can be used as a core component of a large communication platform, supporting cross-region deployment. And it can also be compatible with mainstream SIP clients and relay services (such as Zoiper, Asterisk, Kamailio, etc.).

[0178] According to another aspect of the present invention, there is also provided an electronic device. The electronic device includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors can implement the SIP communication method as described above.

[0179] According to another aspect of the present invention, there is also provided a non-volatile computer-readable storage medium. A computer program is stored on the storage medium, and when the computer program is executed by a processor, it can implement the SIP communication method as described above.

[0180] According to another aspect of the present invention, the present invention also provides a computer program product. The computer program product includes: a computer program stored on a computer-readable storage medium; the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the SIP communication method as described above.

[0181] Finally, it should be noted that the above are only preferred embodiments of the present invention and are not used to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions of the foregoing embodiments or perform equivalent replacements for some of the technical features. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A SIP communication method based on asynchronous message processing, characterized in that: include: Asynchronously receive the client's SIP request message based on the non-blocking I / O model; Parsing and responding to the SIP request message based on a preset dynamic expansion mechanism and a preset load balancing and clustering mechanism to obtain a SIP response message; The SIP response message is asynchronously distributed based on a preset asynchronous sending mode.

2. The SIP communication method according to claim 1, characterized in that: In the case where the SIP request message includes a TCP message type, the asynchronously receiving the SIP request message from the client based on the non-blocking I / O model includes: Start the target asynchronous TCP server; Based on the coroutine of the target asynchronous TCP server, the SIP request message is asynchronously read through a first asynchronous reading mode.

3. The SIP communication method according to claim 1, characterized in that: In the case where the SIP request message includes a UDP message type, the asynchronously receiving the SIP request message from the client based on the non-blocking I / O model includes: Start UDP listening; Based on the UDP monitoring, the SIP request message is asynchronously read through a second asynchronous reading mode.

4. The SIP communication method according to claim 1, characterized in that: The preset dynamic extension mechanism includes at least one of a core SIP engine, a plug-in manager, a plug-in module and an event-driven architecture.

5. The SIP communication method according to claim 1, characterized in that: The preset load balancing and clustering mechanism includes at least one of a load balancer, a SIP processing node, a Redis cluster and a Kafka message queue.

6. The SIP communication method according to claim 1, characterized in that: The parsing and responding to the SIP request message based on the preset dynamic expansion mechanism and the preset load balancing and clustering mechanism includes: Performing request line parsing, header parsing and SDP message parsing on the SIP request message to obtain a SIP parsed message; Under the preset dynamic expansion mechanism and the preset load balancing and clustering mechanism, asynchronous response processing is performed based on the SIP parsing message to obtain the SIP response message.

7. The SIP communication method according to claim 1, characterized in that: The SIP communication method may further include: Parsing and responding to the SIP request message based on a high-concurrency scenario optimization mechanism to obtain the SIP response message; Among them, the high concurrency scenario optimization mechanism includes at least one of event loop optimization, connection pool management and flow control.

8. A SIP communication system based on asynchronous message processing, characterized in that: The SIP communication system is used to execute the SIP communication method according to any one of claims 1 to 7, and the SIP communication system includes: Asynchronous message receiving module, asynchronously receiving the client's SIP request message based on the non-blocking I / O model; An asynchronous message processing module, which parses and responds to the SIP request message based on a preset dynamic expansion mechanism and a preset load balancing and clustering mechanism to obtain a SIP response message; The asynchronous message distribution module performs asynchronous distribution processing on the SIP response message based on a preset asynchronous sending mode.

9. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the SIP communication method according to any one of claims 1 to 7.

10. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the SIP communication method according to any one of claims 1 to 7 is implemented.