CN115412520A - Method for storing, reading and writing interaction of Instant Messaging (IM) chat data - Google Patents
Method for storing, reading and writing interaction of Instant Messaging (IM) chat data Download PDFInfo
- Publication number
- CN115412520A CN115412520A CN202211075243.2A CN202211075243A CN115412520A CN 115412520 A CN115412520 A CN 115412520A CN 202211075243 A CN202211075243 A CN 202211075243A CN 115412520 A CN115412520 A CN 115412520A
- Authority
- CN
- China
- Prior art keywords
- message
- user
- session
- chat
- hbase
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 14
- 230000003993 interaction Effects 0.000 title claims abstract description 11
- 238000004891 communication Methods 0.000 claims description 9
- 238000005192 partition Methods 0.000 claims description 6
- 238000013500 data storage Methods 0.000 claims description 4
- 230000000977 initiatory effect Effects 0.000 claims 1
- 238000005516 engineering process Methods 0.000 abstract description 2
- 230000001360 synchronised effect Effects 0.000 abstract description 2
- 238000013461 design Methods 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012163 sequencing technique Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/04—Real-time or near real-time messaging, e.g. instant messaging [IM]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1097—Protocols in which an application is distributed across nodes in the network for distributed storage of data in networks, e.g. transport arrangements for network file system [NFS], storage area networks [SAN] or network attached storage [NAS]
Abstract
The invention discloses a method for storing, reading and writing interaction of Instant Messaging (IM) chat data, which comprises the following steps: JAVA programming technology, netty builds an im server, hbase stores chat information, redis data is written more in the validity period, MQ broadcasts to search users needing to be pushed in real time, mySQL stores user information, and chat list information (session list) is obtained. The Hbase stores chat information, redis synchronous unread messages and unread messages are temporarily cached, and message writing expansion is realized; the pushed message is broadcasted to all IM servers through MQ, a user does not need to be specially recorded to have a special channel on a certain IM system, and the pushed message is processed asynchronously; mySQL only stores user information and a session list, and the storage data volume of MySQL is reduced.
Description
Technical Field
The invention relates to the technical field of instant messaging, in particular to a method for storing, reading and writing interaction of Instant Messaging (IM) chat data.
Background
Instant Messaging (Instant Messaging) is the most popular communication method on the Internet at present, and allows two or more people to communicate text messages, files, voice and video in real time by using a network. The most core part in the IM system is a message system, the most core function in the message system is message synchronization and storage, a server can automatically store messages sent and received by a chat window of the IM system, chat records are formed and stored in a relational database, with the continuous increase of users, the chat data also show a large amount of increase, the single query efficiency can be reduced, and a reasonable chat data design and storage medium is needed for the users to rapidly pull and check the chat records.
The basic principle is as follows:
1: a user client logs in an IM system;
2: inquiring a user list;
3: inquiring users needing chatting, entering a conversation, and inquiring chatting history information of the users;
4: sending a chat message;
5: the server stores the chat messages and pushes and consumes the chat messages to the client of the receiver:
1: and building an IM system by using Netty.
2: mySQL is used for storing chat information, chat list information and user information.
The method comprises the following steps:
1: a user client logs in an IM system to establish a unique communication channel of the user client;
2: inquiring a user list from MySQL, inquiring a user needing chatting, entering a conversation, and inquiring a chatting history message of the user;
3: the user sends the message, the IM system receives the message, searches the IM system where the user is located, transfers the request to the corresponding IM system, and pushes the message to the receiving party.
4: the chat information is stored in MySQL, so that the query of historical messages and unread messages is facilitated.
Data structure:
historical message MySQL: session id message self-increment id message type content creation time;
unread message MySQL: session id | message id | user id | whether read |;
session list MySQL: session id user id.
With the development of the internet, various instant messaging software is also developed in an endlessly manner aiming at the fact that instant messaging in the traditional industry and the internet industry is more important; the instant messaging IM system also provides more and more abundant communication functions, but the chat data storage of the IM system at present mostly uses a relational database for storage, and the query speed of historical messages is slowed along with the increase of data volume.
In summary, the present invention provides a method for storing, reading, and writing interaction of instant messaging IM chat data.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a method for storing, reading and writing interaction of Instant Messaging (IM) chatting data, which realizes the general storage design of chatting records and the rapid reading of historical messages and unread messages.
In order to achieve the purpose, the invention is realized by the following technical scheme: a method for storing, reading and writing interaction of Instant Messaging (IM) chat data comprises the following steps:
1: and the user logs in the IM system and establishes a unique communication channel of the user. And pull its own session list from MySQL.
2: and the user selects a user needing to establish the chat, enters the chat session and pulls the unread message from the Redis.
3: user initiated chat messages
4: after the message reaches the server, the root session id calculates RowKey, the message needing to be pushed is broadcasted to all IM servers through MQ, if the server has the user-specific communication channel to directly push the message and store the contact message in Hbase, if no specific channel exists, the user is not online, at the moment, the message needs to keep an unread message to set a period of validity in Redis, and the contact message is synchronously stored in Hbase.
The step 4 adopts the following data structure:
hbase history message: custom RowKey message type content creation time sender session
Redis unread message: zset { Key: user id | valueJson = { message type | content | creation time } | score: rowKey }
Session list MySQL: session id user id.
The step 4 adopts a RowKey structure:
hbase stores IM information, and RowKey is designed;
conversation% 20 | conversation id | reverse order message id;
the purpose of the session modulus value is data partition (region) storage, and the data read-write pressure can be shared by the pre-partition;
determining a unique session by using the session id, wherein all messages in a group have the same session id;
and determining the unique message and pulling the latest message sequence by the message id in the reverse order, wherein the reverse order ensures that the value of the id of the newer message is smaller, the IM software always displays the latest message in the group first, and the IM software loads the previous message after sliding the interface upwards.
The invention has the following beneficial effects:
1. MySQL only stores user information and a session list, the query of historical information is transferred from MySQL to Hbase, the query pressure of MySQL is reduced, and Redis bears write extension in the message validity period.
2. Hbase data which is fully utilized in historical message design is natural and ordered, and the characteristics of distributed and telescopic big data storage and high rowKey query performance are achieved based on rowKeyASCIl sequence arrangement.
3. Unified rowKey design is matched with rowKeyASCIl sequencing of Hbase, and query only needs to be carried out according to rowKey.
Drawings
The invention is described in detail below with reference to the drawings and the detailed description;
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
In order to make the technical means, the creation characteristics, the achievement purposes and the effects of the invention easy to understand, the invention is further explained by combining the specific embodiments.
Referring to fig. 1, the following technical solutions are adopted in the present embodiment: a method for storing, reading and writing interaction of Instant Messaging (IM) chat data comprises the following steps:
1: and the user logs in the IM system and establishes a unique communication channel of the user. And pull its own session list from MySQL.
2: and the user selects a user needing to establish the chat, enters the chat session and pulls the unread message from the Redis.
3: user initiated chat messages
4: after the message reaches the server, the root session id calculates RowKey, the message needing to be pushed is broadcasted to all IM servers through MQ, if the server has the user-specific communication channel to directly push the message and store the contact message in Hbase, if no specific channel exists, the user is not online, at the moment, the message needs to keep an unread message to set a period of validity in Redis, and the contact message is synchronously stored in Hbase.
Data structure:
hbase history message: custom RowKey message type content creation time sender session
Redis unread message: zset { Key: user id | valueJson = { message type | content | creation time } | score: rowKey }
Session list MySQL: session id user id.
RowKey structure:
hbase stores IM messages, and RowKey is designed;
conversation% 20 | conversation id | reverse order message id;
the purpose of the session modulus value is data partition (region) storage, and the data read-write pressure can be shared by the pre-partition;
determining a unique session by using the session id, wherein all messages in a group have the same session id;
and determining the unique message and pulling the latest message sequence by the message id in the reverse order, wherein the reverse order ensures that the value of the id of the newer message is smaller, the IM software always displays the latest message in the group first, and the IM software loads the previous message after sliding the interface upwards.
The specific embodiment adopts the following steps: JAVA programming technology, netty builds an im server, hbase stores chat information, redis data is written more in the validity period, MQ broadcasts to search users needing to be pushed in real time, mySQL stores user information, and chat list information (session list) is obtained.
In the specific embodiment, hbase stores chat information, redis synchronous unread messages and unread messages are temporarily cached, so that message write expansion is realized; the pushed message is broadcasted to all IM servers through MQ, a user does not need to be specially recorded to have a special channel on a certain IM system, and the pushed message is processed asynchronously; mySQL only stores user information and a session list, and the data storage amount of MySQL is reduced.
Example 1:
query examples:
inquiring the session message: 107101127
scan "message",{STARTROW => '107101127' ,ENDROW => '107101127~' , FORMATTER => 'JSONString'}。
The foregoing shows and describes the general principles and broad features of the present invention and advantages thereof. It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, which are described in the specification and illustrated only to illustrate the principle of the present invention, but that various changes and modifications may be made therein without departing from the spirit and scope of the present invention, which fall within the scope of the invention as claimed. The scope of the invention is defined by the appended claims and equivalents thereof.
Claims (3)
1. A method for storing, reading and writing interaction of Instant Messaging (IM) chat data is characterized by comprising the following steps:
(1) The user logs in an IM system, establishes a unique communication channel of the user and pulls a session list of the user from MySQL;
(2) The user selects a user needing to establish a chat, enters a chat session, and pulls an unread message from Redis;
(3) Initiating a chat message by the user;
(4) After the message reaches the server, the root session id calculates RowKey, the message needing to be pushed is broadcasted to all IM servers through MQ, if the server has the user-specific communication channel to directly push the message and store the contact message in Hbase, if no specific channel exists, the user is not online, at the moment, the message needs to keep an unread message to set a period of validity in Redis, and the contact message is synchronously stored in Hbase.
2. The method for storing read-write interaction of Instant Messaging (IM) chat data according to claim 1, wherein the step 4 adopts the following data structure:
hbase history message: custom RowKey message type content creation time sender session
Redis unread message: zset { Key: user id | valueJson = { message type | Content | creation time } | score: rowKey }
Session list MySQL: session id user id.
3. The method for IM chat data storage read-write interaction in instant messaging according to claim 1, wherein step 4 employs a RowKey structure:
hbase stores IM messages, and RowKey is designed;
conversation% 20 | conversation id | reverse order message id;
the purpose of the session modulus value is data partition (region) storage, and the data read-write pressure can be shared by the pre-partition;
determining a unique session by using the session id, wherein all messages in a group have the same session id;
and determining the unique message and pulling the latest message sequence by the message id in the reverse order, wherein the reverse order ensures that the value of the id of the newer message is smaller, the IM software always displays the latest message in the group first, and the IM software loads the previous message after sliding the interface upwards.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211075243.2A CN115412520A (en) | 2022-09-04 | 2022-09-04 | Method for storing, reading and writing interaction of Instant Messaging (IM) chat data |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211075243.2A CN115412520A (en) | 2022-09-04 | 2022-09-04 | Method for storing, reading and writing interaction of Instant Messaging (IM) chat data |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115412520A true CN115412520A (en) | 2022-11-29 |
Family
ID=84164278
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211075243.2A Pending CN115412520A (en) | 2022-09-04 | 2022-09-04 | Method for storing, reading and writing interaction of Instant Messaging (IM) chat data |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115412520A (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20140164524A1 (en) * | 2012-12-06 | 2014-06-12 | International Business Machines Corporation | Searchable peer-to-peer system through instant messaging based topic indexes |
CN108289055A (en) * | 2018-01-05 | 2018-07-17 | 创盛视联数码科技(北京)有限公司 | A kind of distributed live chat system and method based on Redis subscription services |
CN109815026A (en) * | 2018-12-18 | 2019-05-28 | 国电南京自动化股份有限公司 | Electric power time series database based on distributed component |
CN110198351A (en) * | 2019-05-29 | 2019-09-03 | 深圳前海微众银行股份有限公司 | Storage method, device, server-side and the readable storage medium storing program for executing of offline message |
CN112333080A (en) * | 2020-10-27 | 2021-02-05 | 合肥市智享亿云信息科技有限公司 | Instant communication off-line message pushing method |
-
2022
- 2022-09-04 CN CN202211075243.2A patent/CN115412520A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20140164524A1 (en) * | 2012-12-06 | 2014-06-12 | International Business Machines Corporation | Searchable peer-to-peer system through instant messaging based topic indexes |
CN108289055A (en) * | 2018-01-05 | 2018-07-17 | 创盛视联数码科技(北京)有限公司 | A kind of distributed live chat system and method based on Redis subscription services |
CN109815026A (en) * | 2018-12-18 | 2019-05-28 | 国电南京自动化股份有限公司 | Electric power time series database based on distributed component |
CN110198351A (en) * | 2019-05-29 | 2019-09-03 | 深圳前海微众银行股份有限公司 | Storage method, device, server-side and the readable storage medium storing program for executing of offline message |
CN112333080A (en) * | 2020-10-27 | 2021-02-05 | 合肥市智享亿云信息科技有限公司 | Instant communication off-line message pushing method |
Non-Patent Citations (1)
Title |
---|
冯晓普: "《HBase存储的研究与应用》", 《中国优秀硕士学位论文全文数据库》 * |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104700836B (en) | A kind of audio recognition method and system | |
US20080281927A1 (en) | Summarization tool and method for a dialogue sequence | |
US20110029616A1 (en) | Unified auto-reply to an email coming from unified messaging service | |
WO2012048601A1 (en) | Method for displaying message and message display apparatus | |
US20080096532A1 (en) | Emotional state integrated messaging | |
CN101360071A (en) | Method and system for multimedia resource sharing based on instant chat | |
US8583743B1 (en) | System and method for message gateway consolidation | |
EP1435715A2 (en) | Atomic message division | |
US20120221649A1 (en) | Peer-to-peer collaboration of publishers in a publish-subscription environment | |
EP2050259B1 (en) | Method and system for generating and presenting conversation threads having email, voicemail and chat messages | |
US20230237243A1 (en) | Methods, Systems, and Apparatus for Email to Persistent Messaging | |
US9565266B2 (en) | Broker facilitated peer-to-peer publisher collaboration in a publish-subscription environment | |
CN101291342A (en) | Data synchronizing method and system in distributed system | |
WO2012171404A1 (en) | Method, device and system for sharing microblog message | |
CN113886494A (en) | Message storage method, device, equipment and computer readable medium for instant messaging | |
CN111641700A (en) | Method for realizing management and retrieval of metadata based on Ceph object storage | |
CN101661485A (en) | Method and equipment for supporting query of contact information | |
CN115412520A (en) | Method for storing, reading and writing interaction of Instant Messaging (IM) chat data | |
CN109921983A (en) | A kind of multilingual chat mobile application | |
CN101127990A (en) | A method for searching mobile phone SMS | |
CN101588542A (en) | Method and terminal for processing messages | |
CN101197844B (en) | File storage method based on subscription issuing system | |
CN111369302A (en) | Method, system and computer readable storage medium for generating points in real time | |
CN107370717A (en) | A kind of cross-platform audio frequency transmission method | |
CN107040455B (en) | Instant message communication method and system based on redis |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |