Instant messaging method, system, device, processor and electronic device
By establishing connection relationships and message queues between clients and server clusters in the resource center and message center, the problems of cross-node communication and multi-role participation in the instant communication system are solved, and efficient instant messaging expansion and multi-role support are achieved.
Patent Information
- Application Number
- CN202210934342.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-04
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2042-08-04
AI Technical Summary
Due to the use of WebSocket protocol, the instant communication system has content isolation between nodes, which cannot achieve cross-node communication, and cannot support large-scale instant communication scenarios and application scenarios with multi-role participation.
By establishing a connection relationship between the client and the server cluster in the resource center and creating a message queue based on connection identity in the message center, message push and broadcast between the client and the server is realized, and instant communication scenarios with cross-node communication and multi-role participation are supported.
It realizes cross-node communication, supports instant messaging expansion, and can handle large-scale instant messaging scenarios and multi-role application scenarios, avoiding message delay and loss.
Smart Images

Figure CN115297154B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology and other related technical fields, and specifically, to an instant messaging method, system, device, processor and electronic device. Background Art
[0002] Instant messaging is a service that connects a terminal to an instant messaging network. In related technologies, on the one hand, instant messaging is often implemented using the WebSocket protocol. Since the WebSocket protocol is a stateful long connection protocol, there is memory isolation between multiple nodes and cross-node communication cannot be achieved. This results in the server being unable to expand horizontally and unable to support large-scale instant messaging scenarios.
[0003] On the other hand, the message sending of instant messaging applications depends on the application's memory and only supports synchronous sending. When the message is large or there is concurrency, it is easy to cause the input interface or output interface to be blocked, which in turn causes message delay or even message loss.
[0004] On the other hand, instant messaging applications only support point-to-point message transmission between servers and clients. There is no unified connection resource pool between clients and servers. The connection between a single client and server cannot perceive the existence of other connections, resulting in the inability to realize application scenarios such as broadcasting, group messaging, and group chat.
[0005] In addition, instant messaging applications only support two roles: server and client, and cannot support instant messaging scenarios involving multiple roles, such as customers, customer service, technical support, project managers, and other multiple roles.
[0006] In related technologies, since instant messaging often uses the WebSocket protocol, there is content isolation between nodes, resulting in the problem that cross-node communication is not supported. No effective solution has been proposed yet. Summary of the invention
[0007] The main purpose of the present application is to provide an instant messaging method, system, device, processor and electronic device to solve the problem in the related art that since instant messaging often uses the WebSocket protocol, there is content isolation between nodes, resulting in non-support for cross-node communication.
[0008] In order to achieve the above-mentioned purpose, according to one aspect of the present application, an instant messaging method is provided. The method includes: receiving a connection request sent by at least one client, and establishing a connection relationship between the client sending the connection request and a server in a server cluster in a resource center; obtaining a connection identifier of each connection relationship to obtain multiple connection identifiers; creating a message queue for each connection relationship in a message center based on the connection identifier, wherein the message queue is used to receive a message sent by a client having a connection relationship with a server in the server cluster to a current client; and pushing the message in each message queue to the client indicated by the corresponding connection relationship.
[0009] Optionally, before pushing the messages in each message queue to the client indicated by the corresponding connection relationship, the method also includes: receiving a target message broadcast by at least one first client through the message center, and determining at least one second client to receive the target message; determining a target connection relationship between the second client and the server; and sending the target message to the message queue indicated by the target connection relationship.
[0010] Optionally, establishing connection relationships between clients sending connection requests and servers in a server cluster in a resource center includes: obtaining the number of clients connected to each server in the server cluster to obtain multiple numbers; determining whether each number is less than a number threshold; obtaining servers whose number is less than the number threshold to obtain target servers; and establishing a connection relationship between the client sending a connection request and any target server.
[0011] Optionally, after establishing the connection relationship between the client sending the connection request and the server in the server cluster in the resource center, the method also includes: obtaining the information of each client and determining the URL of the server that has a connection relationship with each client; registering the information of each client and the URL of the server corresponding to the client in the resource center to obtain registration information, and generating a connection identifier between the client and the server based on the registration information.
[0012] Optionally, the message queue is a ring queue, and a storage space of a preset capacity is provided in the ring queue.
[0013] Optionally, after the resource center establishes connection relationships between the client sending the connection request and the servers in the server cluster, the method also includes: determining whether each connection relationship is disconnected; if there is a disconnected connection relationship, deleting the connection identifier and message queue of the disconnected connection relationship in the message center.
[0014] Optionally, before receiving a connection request sent by at least one client, the method also includes: establishing a lifecycle interface for different types of clients in a resource center, the lifecycle interface being used to perform preset operations on clients of corresponding types, the preset operations including at least one of the following: establishing a connection relationship between the client and the server and a message queue for the connection relationship, receiving messages through the message queue for the connection relationship, and deleting the message queue for the connection relationship when the connection relationship is disconnected.
[0015] According to another aspect of the present application, an instant messaging system is provided. The system includes: a server cluster including multiple servers; a resource center for establishing a connection relationship between each client and a server in the server cluster; a message center for creating a message queue for each connection relationship, and for receiving messages broadcast by each client, pushing the messages to the message queue corresponding to the client to be received, and pushing the messages in each message queue to the corresponding client.
[0016] In order to achieve the above-mentioned purpose, according to another aspect of the present application, an instant messaging device is provided. The device includes: a receiving unit, which is used to receive a connection request sent by at least one client, and establish a connection relationship between the client sending the connection request and the server in the server cluster in the resource center; an acquisition unit, which is used to acquire a connection identifier of each connection relationship and obtain multiple connection identifiers; a creation unit, which is used to create a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive a message sent by a client having a connection relationship with a server in the server cluster to the current client; and a push unit, which is used to push the message in each message queue to the client indicated by the corresponding connection relationship.
[0017] Through this application, the following steps are adopted: receiving a connection request sent by at least one client, and establishing a connection relationship between the client sending the connection request and the server in the server cluster in the resource center; obtaining a connection identifier for each connection relationship, and obtaining multiple connection identifiers; creating a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive messages sent by a client having a connection relationship with a server in the server cluster to the current client; pushing the messages in each message queue to the client indicated by the corresponding connection relationship, solving the problem in the related technology that the WebSocket protocol is often used in instant communication, and there is content isolation between nodes, resulting in non-support for cross-node communication. By distributing the servers, using the same resource center to schedule the connection between the client and the server, the message queues corresponding to each client are uniformly placed in the message center for processing, thereby achieving the effect of realizing cross-node communication and supporting instant messaging expansion. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 is a flow chart of an instant messaging method provided according to an embodiment of the present application;
[0020] Figure 2 is a schematic diagram of a data structure of a connection relationship provided according to an embodiment of the present application;
[0021] Figure 3 is a schematic diagram of the structure of an instant messaging system provided according to an embodiment of the present application;
[0022] Figure 4 is a schematic diagram of the structure of an optional instant messaging system provided according to an embodiment of the present application;
[0023] Figure 5 is a schematic diagram of an instant messaging device provided according to an embodiment of the present application;
[0024] Figure 6 is a schematic diagram of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0026] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0029] The present invention is described below in conjunction with preferred implementation steps. Figure 1 is a flow chart of an instant messaging method provided according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0030] Step S101: receiving a connection request sent by at least one client, and establishing connection relationships between the client sending the connection request and servers in a server cluster in a resource center.
[0031] Specifically, the client can be a user who uses the instant messaging application, such as a merchant customer, merchant customer service, etc. The resource center is a resource scheduling and deployment center for the instant messaging application, responsible for the creation, operation, and destruction of the background service endpoints of the instant messaging application. The connection request can open the interface of the instant messaging application for the user, and the instant messaging application automatically generates a connection request for the user's client. After receiving the connection request, the resource center establishes a connection relationship between the server in the server cluster and the client.
[0032] It should be noted that the resource center is established based on the distributed cache. When the connection relationship is established, the instant messaging application registers the connection index and the IP address of the corresponding node of the server where it is located in the resource center in the form of a key-value pair.
[0033] Step S102: Acquire a connection identifier of each connection relationship to obtain a plurality of connection identifiers.
[0034] Specifically, the connection identifier may be a unique identifier used to confirm the client to which the connection relationship belongs.
[0035] It should be noted that after each client is connected to the server, the client is located at a service endpoint of the server node. Each server has multiple service endpoints, and each server has a unique node IP address. The resource center stores all service endpoint information in the server cluster. Each service endpoint corresponds to a unique connection identifier. Service endpoints can establish single-send, group-send, group chat and other message modes through connection identifiers.
[0036] Step S103: creating a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive a message sent by a client having a connection relationship with a server in the server cluster to the current client.
[0037] Specifically, the message center can be a communication message transfer station for instant messaging applications. It is responsible for receiving messages from the sender and forwarding the messages to the receiver quickly and accurately, supporting multiple message modes such as single sending and group sending. In the message center, a corresponding message queue is created for each connection relationship to receive messages. When the message queue corresponding to the current client receives a message, the received message comes from other clients connected to the server.
[0038] For example, client A needs to send a message to client B and client C. Client A broadcasts the message to the message queues corresponding to client B and client C in the message center.
[0039] Step S104: Push the messages in each message queue to the client indicated by the corresponding connection relationship.
[0040] Specifically, when a new message is received in the message queue, the instant messaging application automatically monitors from the message center and pushes the message to the client corresponding to the message queue.
[0041] The instant communication method provided by the embodiment of the present application receives a connection request sent by at least one client, and establishes a connection relationship between the client sending the connection request and the server in the server cluster in the resource center; obtains the connection identifier of each connection relationship, and obtains multiple connection identifiers; creates a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive messages sent by the client having a connection relationship with the server in the server cluster to the current client; pushes the messages in each message queue to the client indicated by the corresponding connection relationship, which solves the problem in the related art that the WebSocket protocol is often used in instant communication, and there is content isolation between nodes, resulting in non-support for cross-node communication. By distributing the servers and utilizing the connection between the same scheduling client and server in the resource center, the message queues corresponding to each client are uniformly placed in the message center for processing, thereby achieving the effect of realizing cross-node communication and supporting instant communication expansion.
[0042] The message queue receives information by listening in the message center. Optionally, in the instant messaging method provided in the embodiment of the present application, before pushing the message in each message queue to the client indicated by the corresponding connection relationship, the method also includes: receiving a target message broadcast by at least one first client through the message center, and determining at least one second client to receive the target message; determining the target connection relationship between the second client and the server; and sending the target message to the message queue indicated by the target connection relationship.
[0043] Specifically, the first client may be a client that sends messages in an instant messaging application, and the second client may be a client that receives messages in an instant messaging application. One-to-one chat and group chat functions may be implemented through the message center. Therefore, there may be multiple first clients and second clients, and the relationship between the first client and the second client may be one-to-one, one-to-many, many-to-one or many-to-many. The message center determines the second client that receives the message through a connection identifier, and the message queue corresponding to the first client broadcasts the target message to the second client in the message center. The message queue corresponding to the second client can monitor the target message broadcast by the first client based on the connection identifier. After receiving the target message, the message queue corresponding to the second client pushes the target message to the second client through the target connection relationship. The message center processes the reception and transmission of messages, so that the instant messaging application can implement functions such as cross-node communication and group chat.
[0044] The server that establishes a connection with the client needs to have a free connection location. Optionally, in the instant messaging method provided in the embodiment of the present application, the connection relationship between the client that sends the connection request and the servers in the server cluster is established in the resource center respectively, including: obtaining the number of clients connected to each server in the server cluster, and obtaining multiple numbers; determining whether each number is less than a number threshold; obtaining servers whose number is less than the number threshold, and obtaining a target server; and establishing a connection relationship between the client that sends the connection request and any one of the target servers.
[0045] Specifically, the maximum number of clients that can connect to each server is the server load, and the number threshold is the load threshold. When a client applies to establish a connection with a server, the resource center will select servers whose server loads do not reach the load threshold from the server cluster to establish a connection with the client. By connecting the client to servers whose number is less than the number threshold, server overload and failure can be avoided.
[0046] After the client establishes a connection with the server, it is necessary to register with the resource center. Optionally, in the instant messaging method provided in the embodiment of the present application, after the connection relationship between the client that sends the connection request and the server in the server cluster is established in the resource center, the method also includes: obtaining information of each client and determining the URL of the server that has a connection relationship with each client; registering the information of each client and the URL of the server corresponding to the client in the resource center to obtain registration information, and generating a connection identifier between the client and the server based on the registration information.
[0047] Specifically, the information can be the identity information of the client, such as client A, client B or customer service C. The registration information includes the service endpoint information and the identity information of the client. The service endpoint information is the location information of the endpoint occupied by the client on the server. The resource center stores all the service endpoint information in the cluster, and each service endpoint has a connection identifier as a unique identity identifier. By registering the connection relationship between the client and the server in the resource center, the client can realize the communication function in the instant messaging application.
[0048] For example, Figure 2 is a schematic diagram of a data structure of a connection relationship provided in an embodiment of the present application, such as Figure 2 As shown, each connection relationship is stored in the resource center as a data structure in the form of a key-value pair. The connection ID is the connection identifier, the node IP is the URL of the server in the connection relationship, the message queue ID is the identifier of the message queue, the creation time is the creation time of the connection relationship, the last heartbeat time refers to the time when the two connected parties of the connection relationship are disconnected, and the last message time is the reception time of the last message in the message queue corresponding to the connection relationship.
[0049] In order to realize fast transmission of messages, the message queue uses a ring queue. Optionally, in the instant messaging method provided in the embodiment of the present application, the message queue is a ring queue, and a storage space of a preset capacity is set in the ring queue.
[0050] It should be noted that the message queue in this embodiment implements a circular queue through an array. The circular queue uses a digital identifier to mark the next available element in the message queue. When storing data in the message queue, it is only necessary to find the available element position in the circular queue through the digital identifier. In a circular queue, the queue elements that have been consumed, that is, the elements that have been read, will not be destroyed immediately. If the reading result of an element in the circular queue fails, the failed element segment in the queue can be found through the failed element position and the current available element position, and these elements can be consumed again. The consumed elements are kept until they are replaced by new elements. Developers can set the size of the circular queue according to their own business characteristics.
[0051] Since the circular queue is implemented based on an array, memory can be pre-allocated to the message queue to keep the messages in the message queue permanently valid, which means that garbage collection is almost never triggered. There is no need to create an object for each addition of data, and to destroy the object when it is deleted, as in a linked list. Therefore, storage and reading time can be saved, and the efficiency of instant messaging can be improved.
[0052] Assume that the length of the circular queue is bufferSize, and set two pointers for the circular queue: head points to the next read position, and tail points to the next write position. The last unit of the circular queue does not store data. If head == tail, then the storage space of the circular queue is free. If head == tail + 1 (mod bufferSize), then the storage space of the circular queue is full.
[0053] In an optional implementation, when multiple messages are sent to a message queue at the same time, in order to avoid message loss, a lock-free concurrency method can also be used to receive and read messages. The basic principle of lock-free concurrency is that when reading messages in a circular queue, only the value of head is modified, and when writing messages to a circular queue, only the value of tail is modified. During a write operation, the value of tail is modified after the content is written to the queue; while during a read operation, the value of tail is read and assigned to copyTail, and the assignment operation is an atomic operation. Therefore, after reading copyTail, there must be data to be read from head to copyTail, and there will be no situation where the read operation is performed without data being written. Similarly, the value of head will be modified only after the read operation is completed; and before the write operation, the value of head will be read to determine whether there is space to write data. Therefore, at this time, there must be space to write data between tail and head-1, and there will be no situation where the data at a position is overwritten by a write operation before it is read.
[0054] After the client is disconnected from the server, the message queue and connection identifier corresponding to the client are deleted in the message center and the resource center. Optionally, in the instant messaging method provided in the embodiment of the present application, after the connection relationship between the client sending the connection request and the servers in the server cluster is established in the resource center respectively, the method also includes: determining whether each connection relationship is disconnected; if there is a disconnected connection relationship, deleting the connection identifier and message queue of the disconnected connection relationship in the message center.
[0055] Specifically, it is determined whether the connection relationship is disconnected by determining whether the user of the client leaves the interface of the instant messaging application. When the connection is disconnected, that is, when the connection is destroyed, the instant messaging application is responsible for canceling the registration information in the resource center and deleting the message queue and connection identifier created in the message center. By regularly deleting the disconnected message queue and connection identifier, the problem of insufficient storage space in the resource center can be avoided.
[0056] The instant messaging application also supports custom client types. Optionally, in the instant messaging method provided in the embodiment of the present application, before receiving a connection request sent by at least one client, the method also includes: establishing a life cycle interface for different types of clients in the resource center, the life cycle interface is used to perform preset operations on clients of the corresponding type, and the preset operations include at least one of the following: establishing a connection relationship between the client and the server and a message queue of the connection relationship, receiving messages through the message queue of the connection relationship, and deleting the message queue of the connection relationship when the connection relationship is disconnected.
[0057] Specifically, a role factory is established in the backend of the instant messaging application, and lifecycle interfaces of different types of clients are established through the role factory. The role factory is a parent interface for developers. Developers can set up multiple roles, that is, client types, through the lifecycle interface extension. The lifecycle interface includes: endpoint creation, message receipt, and endpoint destruction. Developers can implement business logic according to role needs. By setting up the role factory, the instant messaging application can provide services for multiple business scenarios.
[0058] In actual development, different business scenarios may involve different instant messaging role requirements. For example, online customer service scenarios involve two roles: customer and customer service; in enterprise information interaction scenarios and social scenarios, the roles will become more complex and diverse.
[0059] For the online customer service scenario, which involves two roles, customer and customer service, the business logic set for the customer is as follows: after creating the endpoint for the client corresponding to the customer, the developer will set the preset operation for this type of endpoint, such as triggering a welcome message when the customer opens the online customer service message box, setting the corresponding reply information for the customer's common questions, etc. When the customer receives the message, the instant messaging application is controlled to push the message content to the client for display. When the customer closes the online customer service message box, the service endpoint in the resource center is destroyed, and the customer service end is notified that the specified customer has gone offline.
[0060] The business logic for customer service settings is as follows: After creating an endpoint for the client corresponding to the customer service, the developer will set another preset operation for this type of endpoint. For example, when the customer service is online, the customer service will be pushed to the customer service waiting for access. When the customer service receives a message, the instant messaging application is controlled to push the message content to the client for display, and the source customer information of the message is marked. When the customer service goes offline, the service endpoint in the resource center is destroyed, and the client that is interacting with it is notified that the specified customer service is offline.
[0061] The present application also provides an instant messaging system. Figure 3 Schematic diagram of the structure of the instant messaging system provided according to the embodiment of the present application. Figure 3 As shown, the system includes:
[0062] The server cluster 301 includes multiple servers.
[0063] Specifically, the server cluster 301 includes all servers of the instant messaging application program, and each server establishes a connection relationship with a corresponding client to provide instant messaging services for the client.
[0064] The resource center 302 is used to establish a connection relationship between each client and the servers in the server cluster 301 .
[0065] Specifically, the resource center 302 is responsible for managing the creation, operation, and destruction of the background service endpoints of the instant messaging application. The resource center 302 is implemented using distributed cache technology and supports cross-node data aggregation; it opens an operation and maintenance interface and supports querying the real-time operation status of the service endpoint by node IP and endpoint ID. The resource center 302 is established based on distributed cache. When the connection relationship is established, the instant messaging application registers the connection index and the IP address of the corresponding node of the server where it is located to the resource center 302 in the form of a key-value pair.
[0066] The message center 303 is used to create a message queue for each connection relationship, receive messages broadcast by each client, push messages to the message queue corresponding to the client to be received, and push messages in each message queue to the corresponding client.
[0067] Specifically, the message center 303 is an instant messaging message transfer station. It is responsible for receiving messages from the sender and forwarding the messages to the receiver quickly and accurately, supporting multiple message modes such as single sending and group sending; it is based on a high-performance ring queue and has the characteristics of low power consumption and low latency. In the message center 303, a corresponding message queue is created for each connection relationship to receive messages.
[0068] Figure 4 is a schematic diagram of the structure of an optional instant messaging system provided according to an embodiment of the present application. Figure 4 As shown, client 1 needs to send hello to client 2, client 3 and client 4. Resource center 302 schedules the server with IP 100.1 in server cluster 301 to establish a connection relationship with client 1, and sends hello to the message queues corresponding to client 2, client 3 and client 4 in message center 303. Client 2 establishes a connection relationship with the server with IP 100.1 and creates queue 2 in message center 303. Client 3 establishes a connection relationship with the server with IP 100.2 and creates queue 3 in message center 303. Client 4 establishes a connection relationship with the server with IP 100.3 and creates queue 4 in message center 303. Endpoint 1 is the server location with IP 100.1 of client 1, endpoint 2 is the server location with IP 100.1 of client 2, endpoint 3 is the server location with IP 100.2 of client 3, and endpoint 4 is the server location with IP 100.3 of client 4. Queue 2, queue 3 and queue 4 listen to hello in message center 303 and push hello to the corresponding clients.
[0069] According to the instant messaging system provided by the embodiment of the present application, each client establishes a connection relationship with the corresponding server, and creates a message queue for each connection relationship, and the message queue broadcasts or receives messages from other message queues in the message center 303. Cross-node communication is realized, server horizontal expansion is supported, and multiple application scenarios such as broadcasting, group messaging and group chat are supported.
[0070] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0071] The embodiment of the present application also provides an instant messaging device. It should be noted that the instant messaging device of the embodiment of the present application can be used to execute the instant messaging method provided by the embodiment of the present application. The instant messaging device provided by the embodiment of the present application is introduced below.
[0072] Figure 5 Schematic diagram of an instant messaging device provided according to an embodiment of the present application. Figure 5 As shown, the device comprises:
[0073] The receiving unit 50 is used to receive a connection request sent by at least one client, and establish a connection relationship between the client sending the connection request and the server in the server cluster in the resource center;
[0074] An acquiring unit 51 is used to acquire a connection identifier of each connection relationship to obtain multiple connection identifiers;
[0075] A creating unit 52, configured to create a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive a message sent by a client having a connection relationship with a server in the server cluster to the current client;
[0076] The push unit 53 is used to push the messages in each message queue to the client indicated by the corresponding connection relationship.
[0077] The instant messaging device provided in the embodiment of the present application receives a connection request sent by at least one client through a receiving unit 50, and establishes a connection relationship between the client sending the connection request and the server in the server cluster in the resource center; an obtaining unit 51 obtains a connection identifier of each connection relationship to obtain multiple connection identifiers; a creating unit 52 creates a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive messages sent by a client having a connection relationship with a server in the server cluster to the current client; a pushing unit 53 pushes the messages in each message queue to the client indicated by the corresponding connection relationship, thereby solving the problem in the related art that cross-node communication is not supported due to content isolation between nodes due to the common application of the WebSocket protocol in instant messaging. By distributing the servers and utilizing the same scheduling of the connection between the client and the server in the resource center, the message queues corresponding to the clients are uniformly placed in the message center for processing, thereby achieving the effect of realizing cross-node communication and supporting instant messaging expansion.
[0078] Optionally, in the instant messaging device provided in the embodiment of the present application, the device also includes: an information receiving unit, used to receive a target message broadcast by at least one first client through a message center, and determine at least one second client that receives the target message; a determination unit, used to determine a target connection relationship between the second client and the server; and a sending unit, used to send the target message to a message queue indicated by the target connection relationship.
[0079] Optionally, in the instant messaging device provided in the embodiment of the present application, the receiving unit 50 includes: a first acquisition module, used to acquire the number of clients connected to each server in the server cluster, and obtain multiple numbers; a judgment module, used to judge whether each number is less than a number threshold; a second acquisition module, used to acquire servers whose number is less than the number threshold, and obtain a target server; an establishment module, used to establish a connection relationship between a client sending a connection request and any target server.
[0080] Optionally, in the instant messaging device provided in the embodiment of the present application, the device also includes: an information acquisition unit, used to acquire information of each client and determine the URL of a server that has a connection relationship with each client; a registration unit, used to register the information of each client and the URL of the server corresponding to the client in the resource center respectively, obtain registration information, and generate a connection identifier between the client and the server based on the registration information.
[0081] Optionally, in the instant messaging device provided in the embodiment of the present application, the message queue is a ring queue, and a storage space of a preset capacity is provided in the ring queue.
[0082] Optionally, in the instant messaging device provided in the embodiment of the present application, the device also includes: a judgment unit, used to judge whether each connection relationship is disconnected; and a deletion unit, used to delete the connection identifier and message queue of the disconnected connection relationship in the message center when a disconnected connection relationship exists.
[0083] Optionally, in the instant messaging device provided in the embodiment of the present application, the device also includes: an interface establishment unit, used to establish a life cycle interface for different types of clients in a resource center, the life cycle interface is used to perform preset operations on clients of corresponding types, and the preset operations include at least one of the following: establishing a connection relationship between the client and the server and a message queue of the connection relationship, receiving messages through the message queue of the connection relationship, and deleting the message queue of the connection relationship when the connection relationship is disconnected.
[0084] The instant messaging device includes a processor and a memory. The receiving unit 50, the acquiring unit 51, the creating unit 52 and the pushing unit 53 are all stored in the memory as program units. The processor executes the program units stored in the memory to implement corresponding functions.
[0085] The processor contains a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set, and cross-node communication can be achieved by adjusting kernel parameters, supporting instant messaging expansion.
[0086] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0087] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, an instant messaging method is implemented.
[0088] An embodiment of the present invention provides a processor, which is used to run a program, wherein the program executes an instant communication method when it is run.
[0089] like Figure 6 As shown, an embodiment of the present invention provides an electronic device, wherein the device 601 includes a processor, a memory, and a program stored in the memory and executable on the processor, and the processor implements an instant messaging method when executing the program. The device in this article may be a server, a PC, a PAD, a mobile phone, etc.
[0090] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that initializes the following method steps: an instant communication method.
[0091] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0092] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0093] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0094] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0095] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0096] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0097] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0098] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0099] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0100] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. An instant messaging method, characterized in that: include: receiving a connection request sent by at least one client, and establishing, in a resource center, connection relationships between the client sending the connection request and servers in the server cluster; Obtaining a connection identifier for each of the connection relationships to obtain a plurality of connection identifiers; Creating a message queue for each connection relationship in the message center based on the connection identifier, wherein the message queue is used to receive a message sent by a client having a connection relationship with a server in the server cluster to the current client; Pushing the messages in each of the message queues to the client indicated by the corresponding connection relationship; Before pushing the messages in each of the message queues to the client indicated by the corresponding connection relationship, the method further includes: receiving, through the message center, a target message broadcast by at least one first client, and determining at least one second client to receive the target message; determining a target connection relationship between the second client and the server; and sending the target message to the message queue indicated by the target connection relationship; Among them, before receiving a connection request sent by at least one client, the method also includes: establishing a lifecycle interface for different types of clients in the resource center, and the lifecycle interface is used to perform preset operations on clients of corresponding types, and the preset operations include at least one of the following: establishing a connection relationship between the client and the server and a message queue for the connection relationship, receiving messages through the message queue of the connection relationship, and deleting the message queue of the connection relationship when the connection relationship is disconnected.
2. The method according to claim 1, characterized in that Establishing the connection relationship between the client sending the connection request and the server in the server cluster in the resource center includes: Obtaining the number of clients connected to each of the servers in the server cluster to obtain multiple numbers; determining whether each of the quantities is less than a quantity threshold; Acquire servers whose number is less than the number threshold, and obtain the target server; A connection relationship is established between the client sending the connection request and any one of the target servers.
3. The method according to claim 1, characterized in that After the resource center respectively establishes a connection relationship between the client sending the connection request and the server in the server cluster, the method further includes: Acquire information of each of the clients, and determine the URL of a server that is connected to each of the clients; The information of each client and the website address of the server corresponding to the client are registered in the resource center to obtain registration information, and a connection identifier between the client and the server is generated according to the registration information.
4. The method according to claim 1, characterized in that: The message queue is a ring queue, and a storage space of a preset capacity is provided in the ring queue.
5. The method according to claim 1, characterized in that After the resource center respectively establishes a connection relationship between the client sending the connection request and the server in the server cluster, the method further includes: Determining whether each of the connection relationships is disconnected; In the case where there is a disconnected connection relationship, the connection identifier and the message queue of the disconnected connection relationship are deleted in the message center.
6. An instant messaging system, characterized in that: include: A server cluster, including multiple servers; A resource center is used to establish a connection relationship between each client and a server in the server cluster, wherein life cycle interfaces of different types of clients are established in the resource center, and the life cycle interfaces are used to perform preset operations on clients of corresponding types, and the preset operations include at least one of the following: establishing a connection relationship between the client and the server and a message queue of the connection relationship, receiving a message through the message queue of the connection relationship, and deleting the message queue of the connection relationship when the connection relationship is disconnected; A message center is used to create a message queue for each of the connection relationships, and is also used to receive messages broadcast by each of the clients, push the messages to the message queues corresponding to the clients to be received, and push the messages in each of the message queues to the corresponding clients, wherein before pushing the messages in each of the message queues to the corresponding clients, the message center receives a target message broadcast by at least one first client, and determines at least one second client to receive the target message; determines a target connection relationship between the second client and the server; and sends the target message to the message queue indicated by the target connection relationship.
7. An instant messaging device, characterized in that: include: A receiving unit, configured to receive a connection request sent by at least one client, and to establish a connection relationship between the client sending the connection request and a server in the server cluster in the resource center; An acquiring unit, configured to acquire a connection identifier of each of the connection relationships, and obtain a plurality of connection identifiers; A creating unit, configured to create a message queue for each connection relationship in a message center based on the connection identifier, wherein the message queue is configured to receive a message sent by a client having a connection relationship with a server in the server cluster to a current client; A push unit, used to push the messages in each of the message queues to the client indicated by the corresponding connection relationship; An information receiving unit, used to receive a target message broadcasted by at least one first client through the message center, and determine at least one second client to receive the target message; a determining unit, used to determine a target connection relationship between the second client and the server; a sending unit, used to send the target message to a message queue indicated by the target connection relationship; An interface establishment unit is used to establish life cycle interfaces of different types of clients in the resource center, and the life cycle interfaces are used to perform preset operations on clients of corresponding types, and the preset operations include at least one of the following: establishing a connection relationship between the client and the server and a message queue of the connection relationship, receiving messages through the message queue of the connection relationship, and deleting the message queue of the connection relationship when the connection relationship is disconnected.
8. A processor, characterized in that: The processor is used to run a program, wherein the program executes the instant messaging method according to any one of claims 1 to 5 when running.
9. An electronic device, characterized in that: It includes one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the instant messaging method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Chat room message distribution method, chat room message distribution system and electronic equipment
CN112436997A