CN109151056B - Method and system for pushing messages based on Canal - Google Patents

Method and system for pushing messages based on Canal Download PDF

Info

Publication number
CN109151056B
CN109151056B CN201811122508.3A CN201811122508A CN109151056B CN 109151056 B CN109151056 B CN 109151056B CN 201811122508 A CN201811122508 A CN 201811122508A CN 109151056 B CN109151056 B CN 109151056B
Authority
CN
China
Prior art keywords
message
push server
user information
web application
qmq
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.)
Active
Application number
CN201811122508.3A
Other languages
Chinese (zh)
Other versions
CN109151056A (en
Inventor
谢炀炀
刘诚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ctrip Computer Technology Shanghai Co Ltd
Original Assignee
Ctrip Computer Technology Shanghai Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Ctrip Computer Technology Shanghai Co Ltd filed Critical Ctrip Computer Technology Shanghai Co Ltd
Priority to CN201811122508.3A priority Critical patent/CN109151056B/en
Publication of CN109151056A publication Critical patent/CN109151056A/en
Application granted granted Critical
Publication of CN109151056B publication Critical patent/CN109151056B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses a method and a system for pushing messages based on Canal, wherein the method comprises the following steps: when a login instruction of the Web application is received, establishing connection between the Web application and a push server; the login instruction comprises user information; acquiring user information and an IP (Internet protocol) of a push server, and correspondingly storing the user information and the IP in a Redis cache; when monitoring that the task information in the message database changes, the local component sends the changed task information to the push server; and the push server acquires corresponding user information from the Redis cache and pushes the information according to the user information. The invention starts message pushing based on the change of the data of the message database, reduces the load on the server and the database, improves the message pushing efficiency and reduces unnecessary message pushing.

Description

Method and system for pushing messages based on Canal
Technical Field
The invention belongs to the technical field of message pushing, and particularly relates to a method and a system for pushing messages based on Canal.
Background
In order to facilitate the hotel reservation department staff to record events related to the operation order and to coordinate the establishment of overseas business, a staff event processing platform is required. In consideration of the performance of the system and the load of the database, the employee event processing platform adopts a push mode to pull out a push service. In the existing push service, under the requirement that a program of a client needs real-time synchronization, the push service is often implemented in an Ajax (Asynchronous JavaScript And XML, Asynchronous JavaScript (a scripting language) And XML (extensible markup language), a web page development technology for creating interactive web page applications) polling mode, the polling mode causes pressure on a server And a database, unnecessary message push can be sent sometimes, more resources are consumed, And efficiency is low.
Disclosure of Invention
The invention provides a method and a system for pushing messages based on Canal (an incremental log component based on binary logs) in order to overcome the defects that in the prior art, the message pushing adopts a polling mode, the pressure on a server and a database is large, the resource consumption is high, and the efficiency is low.
The invention solves the technical problems through the following technical scheme:
a method for pushing messages based on Canal comprises the following steps:
when a login instruction of Web (network) application is received, establishing connection between the Web application and a push server; the login instruction comprises user information;
acquiring user information and an Internet Protocol (IP) address of a push server, and correspondingly storing the user information and the IP in a Redis (database) cache;
when monitoring that the task information in the message database changes, the local component sends the changed task information to the push server;
and the push server acquires corresponding user information from the Redis cache and pushes the information according to the user information.
Preferably, when monitoring that the task information in the message database changes, the Canal component sends the changed task information to the push server, including:
the Canal component sends QMQ (a message queue) messages to the SOA (service oriented architecture) component, QMQ messages include varying task information;
and after receiving the QMQ message, the SOA component acquires the IP of the push server from the Redis cache and sends QMQ message to the push server according to the IP.
Preferably, the step of the push server obtaining the corresponding user information from the Redis cache and pushing the message according to the user information includes:
the push server pushes QMQ messages to the Web application through a WebSocket (a network communication protocol) protocol;
the Web application displays QMQ the message.
Preferably, the Web application is connected to the push server via a WebSocket protocol.
Preferably, the method for pushing messages based on Canal further comprises the following steps:
and when an exit instruction of the Web application is received, deleting the user information and the IP from the Redis cache.
The invention also provides a message pushing system based on the Canal, which comprises the following components: the system comprises a cancer component, a connection establishing module, an IP obtaining module, a push server, a Redis cache and a message database;
the connection establishing module is used for establishing the connection between the Web application and the push server when a login instruction of the Web application is received; the login instruction comprises user information;
the IP obtaining module is used for obtaining the user information and the IP of the push server and correspondingly storing the user information and the IP in a Redis cache;
the local component is used for sending the changed task information to the push server when monitoring the change of the task information in the message database;
and the push server is used for acquiring the corresponding user information from the Redis cache and pushing the information according to the user information.
Preferably, the Canal-based message pushing system further comprises an SOA component;
the Canal component is also used for sending QMQ messages to the SOA component, wherein the QMQ messages comprise changed task information;
and the SOA component is used for acquiring the IP of the push server from the Redis cache after receiving QMQ messages, and is used for sending QMQ messages to the push server according to the IP.
Preferably, the push server is further configured to push QMQ messages to the Web application through the WebSocket protocol;
the Web application is used to display QMQ the message.
Preferably, the Web application is connected to the push server via a WebSocket protocol.
Preferably, the Canal-based message pushing system further comprises a deleting module, and the deleting module is configured to delete the user information and the IP from the Redis cache when receiving an exit instruction of the Web application.
The positive progress effects of the invention are as follows: the invention starts message pushing based on the change of the data of the message database, reduces the load on the server and the database, improves the message pushing efficiency and reduces unnecessary message pushing.
Drawings
Fig. 1 is a flowchart of a Canal-based message pushing method according to embodiment 1 of the present invention.
Fig. 2 is a schematic structural diagram of a Canal-based message push system according to embodiment 2 of the present invention.
Detailed Description
The invention is further illustrated by the following examples, which are not intended to limit the scope of the invention.
Example 1
The present embodiment provides a message pushing method based on Canal, and referring to fig. 1, the pushing method includes the following steps:
step S101, when a login instruction of the Web application is received, connection between the Web application and a push server is established; the login instruction comprises user information;
step S102, obtaining user information and an IP (Internet protocol) of a push server, and correspondingly storing the user information and the IP in a Redis cache;
s103, when monitoring that the task information in the message database changes, the cancer component sends the changed task information to a push server;
and step S104, the push server acquires corresponding user information from the Redis cache, and pushes the information according to the user information.
And step S105, deleting the user information and the IP from the Redis cache when receiving the exit instruction of the Web application.
In specific implementation, after a user starts the Web application, user information is input in a login interface, and a login instruction is generated by triggering a control so as to establish connection between the Web application and a push server. In this embodiment, the Web application is connected to the push server via the WebSocket protocol. The number of the push servers is multiple, and the Web application is connected with one of the push servers.
And then, acquiring the user information and the IP of the push server, and correspondingly storing the user information and the IP in a Redis cache.
In this embodiment, the message database is implemented by a MySQL (a relational database management system) database. MySQL stores data needed by business, the data comprises task information, the data is stored in a form of tables, and each table can be configured to determine whether to be monitored by a Canal component. The Canal component listens to the data tables, and when any data table containing task information changes, the Canal component sends QMQ a message to the SOA component, and QMQ the message contains the changed task information.
And after receiving the QMQ message, the SOA component acquires the IP of the push server from the Redis cache, and sends QMQ message to the push server according to the IP based on HTTP (hyper text transfer protocol).
Then, the push server acquires the corresponding user information from the Redis cache, and pushes the QMQ message to the Web application corresponding to the user information, namely the Web application started by the user, through the WebSocket protocol. The Web application displays QMQ the message that the user can receive. The specific content and form of the message are related to the service type, and those skilled in the art can set the specific content and form of the message according to the service type.
If the same user starts 2 Web applications and is respectively connected to 2 push servers, according to the steps, the user receives messages on the started 2 Web applications. And if the user closes the Web application, the Web application sends an exit instruction, the user information and the IP are deleted from the Redis cache, and the Web application does not receive the message push.
Example 2
The embodiment provides a message pushing system based on a Canal, and referring to fig. 2, the pushing system includes a Canal component, a connection establishing module, an IP obtaining module, a pushing server, a Redis cache, and a message database; the connection establishing module is used for establishing the connection between the Web application and the push server when a login instruction of the Web application is received; the login instruction comprises user information; the IP obtaining module is used for obtaining the user information and the IP of the push server and correspondingly storing the user information and the IP in a Redis cache; the local component is used for sending the changed task information to the push server when monitoring the change of the task information in the message database; and the push server is used for acquiring the corresponding user information from the Redis cache and pushing the information according to the user information.
Referring to fig. 2, the push system further includes an SOA component and a deletion module. The Canal component is also used for sending QMQ messages to the SOA component, wherein the QMQ messages comprise changed task information; and the SOA component is used for acquiring the IP of the push server from the Redis cache after receiving QMQ messages, and is used for sending QMQ messages to the push server according to the IP. And the deleting module is used for deleting the user information and the IP from the Redis cache when receiving an exit instruction of the Web application.
The flow of message pushing performed by the Canal-based message pushing system of this embodiment is as follows:
after a user starts the Web application, the Web application outputs a login instruction, and the connection establishment module receives the login instruction and establishes the connection between the Web application and the push server. In this embodiment, the connection establishing module establishes the Web application and the push server through a WebSocket protocol. The number of the push servers is multiple, and the Web application is connected with one of the push servers.
Then, the IP obtaining module obtains the user information and the IP of the push server, and correspondingly stores the user information and the IP in a Redis cache.
In this embodiment, the message database is implemented by a MySQL database. MySQL stores data needed by business, the data comprises task information, the data is stored in a form of tables, and each table can be configured to determine whether to be monitored by a Canal component. The Canal component listens to the data tables, and when any data table containing task information changes, the Canal component sends QMQ a message to the SOA component, and QMQ the message contains the changed task information.
And after receiving the QMQ message, the SOA component acquires the IP of the push server from the Redis cache, and sends QMQ message to the push server according to the IP based on the HTTP protocol.
Then, the push server acquires the corresponding user information from the Redis cache, and pushes the QMQ message to the Web application corresponding to the user information, namely the Web application started by the user, through the WebSocket protocol. The Web application displays QMQ the message that the user can receive.
If the same user starts 2 Web applications, the connection establishing module will connect the 2 Web applications to the 2 push servers respectively (or may connect the 2 Web applications to the same push server), and according to the above steps, the user will receive messages on the started 2 Web applications. If the user closes the Web application, the Web application sends an exit instruction, the deletion module receives the exit instruction and deletes the user information and the IP from the Redis cache, and then the Web application does not receive the message push.
While specific embodiments of the invention have been described above, it will be appreciated by those skilled in the art that these are by way of example only, and that the scope of the invention is defined by the appended claims. Various changes and modifications to these embodiments may be made by those skilled in the art without departing from the spirit and scope of the invention, and these changes and modifications are within the scope of the invention.

Claims (6)

1. A method for pushing messages based on Canal is characterized by comprising the following steps:
when a login instruction of a Web application is received, establishing connection between the Web application and a push server; the login instruction comprises user information;
acquiring the user information and the IP of the push server, and correspondingly storing the user information and the IP in a Redis cache;
when monitoring that the task information in the message database changes, the local component sends the changed task information to the push server;
the push server acquires corresponding user information from the Redis cache, and pushes messages according to the user information;
when monitoring that the task information in the message database changes, the Canal component sends the changed task information to the push server, and the method comprises the following steps:
the Canal component sending QMQ a message to the SOA component, the QMQ message including changed task information;
after receiving the QMQ message, the SOA component acquires the IP of the push server from the Redis cache, and sends the QMQ message to the push server according to the IP;
the step that the push server obtains the corresponding user information from the Redis cache and pushes the message according to the user information comprises the following steps:
the pushing server pushes the QMQ message to the Web application through a WebSocket protocol;
the Web application displays QMQ the message.
2. The Canal-based message pushing method of claim 1, wherein the Web application connects to the push server through a WebSocket protocol.
3. The Canal-based message pushing method of claim 1, wherein the Canal-based message pushing method further comprises the steps of:
and when an exit instruction of the Web application is received, deleting the user information and the IP from the Redis cache.
4. A Canal-based message push system, comprising: the system comprises a cancer component, a connection establishing module, an IP obtaining module, a push server, a Redis cache and a message database;
the connection establishing module is used for establishing the connection between the Web application and the push server when a login instruction of the Web application is received; the login instruction comprises user information;
the IP obtaining module is used for obtaining the user information and the IP of the push server and correspondingly storing the user information and the IP in the Redis cache;
the local component is used for sending the changed task information to the push server when monitoring the change of the task information in the message database;
the push server is used for acquiring corresponding user information from the Redis cache and pushing messages according to the user information;
the Canal-based message pushing system also comprises an SOA component;
the Canal component is further configured to send QMQ messages to the SOA component, the QMQ messages including varying task information;
the SOA component is used for acquiring the IP of the push server from the Redis cache after receiving the QMQ message, and is used for sending the QMQ message to the push server according to the IP;
the push server is further used for pushing the QMQ message to the Web application through a WebSocket protocol;
the Web application is used to display the QMQ message.
5. The Canal-based message pushing system of claim 4, wherein the Web application connects to the push server via a WebSocket protocol.
6. The Canal-based message pushing system of claim 4, wherein the message pushing system further comprises a deletion module configured to delete the user information and the IP from the Redis cache upon receiving an exit instruction of a Web application.
CN201811122508.3A 2018-09-26 2018-09-26 Method and system for pushing messages based on Canal Active CN109151056B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811122508.3A CN109151056B (en) 2018-09-26 2018-09-26 Method and system for pushing messages based on Canal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811122508.3A CN109151056B (en) 2018-09-26 2018-09-26 Method and system for pushing messages based on Canal

Publications (2)

Publication Number Publication Date
CN109151056A CN109151056A (en) 2019-01-04
CN109151056B true CN109151056B (en) 2021-11-19

Family

ID=64812450

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811122508.3A Active CN109151056B (en) 2018-09-26 2018-09-26 Method and system for pushing messages based on Canal

Country Status (1)

Country Link
CN (1) CN109151056B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111970315A (en) * 2019-05-20 2020-11-20 北京车和家信息技术有限公司 Method, device and system for pushing message
CN110995566A (en) * 2019-10-30 2020-04-10 深圳震有科技股份有限公司 Message data pushing method, system and device
CN113238808A (en) * 2020-01-22 2021-08-10 北京沃东天骏信息技术有限公司 Message pushing method and device
CN112738182A (en) * 2020-12-24 2021-04-30 海南车智易通信息技术有限公司 Data pushing system, data pushing method and computing equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103780681A (en) * 2014-01-06 2014-05-07 南京莱斯信息技术股份有限公司 High real-time Web application system and data real-time pushing method thereof
CN105282227A (en) * 2015-09-06 2016-01-27 浪潮软件股份有限公司 High-efficiency high-stability page real-time data refreshing method
CN106209966A (en) * 2016-06-15 2016-12-07 中国科学院信息工程研究所 Management and control end updates the method for equipment state, the treating method and apparatus of service end
CN106569899A (en) * 2016-11-03 2017-04-19 努比亚技术有限公司 Ajax communication system and method
CN108076098A (en) * 2016-11-16 2018-05-25 北京京东尚科信息技术有限公司 A kind of method for processing business and system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060206586A1 (en) * 2005-03-09 2006-09-14 Yibei Ling Method, apparatus and system for a location-based uniform resource locator
EP1853044B1 (en) * 2006-05-02 2009-01-14 Research In Motion Limited Push framework for delivery of dynamic mobile content
US8539566B2 (en) * 2010-04-14 2013-09-17 Sybase, Inc. Resource monitoring using a JMX message bridge

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103780681A (en) * 2014-01-06 2014-05-07 南京莱斯信息技术股份有限公司 High real-time Web application system and data real-time pushing method thereof
CN105282227A (en) * 2015-09-06 2016-01-27 浪潮软件股份有限公司 High-efficiency high-stability page real-time data refreshing method
CN106209966A (en) * 2016-06-15 2016-12-07 中国科学院信息工程研究所 Management and control end updates the method for equipment state, the treating method and apparatus of service end
CN106569899A (en) * 2016-11-03 2017-04-19 努比亚技术有限公司 Ajax communication system and method
CN108076098A (en) * 2016-11-16 2018-05-25 北京京东尚科信息技术有限公司 A kind of method for processing business and system

Also Published As

Publication number Publication date
CN109151056A (en) 2019-01-04

Similar Documents

Publication Publication Date Title
CN109151056B (en) Method and system for pushing messages based on Canal
CN102255935B (en) Cloud service consuming method, cloud service intermediary and cloud system
CN109547511B (en) WEB message real-time pushing method, server, client and system
CN107766509B (en) Method and device for static backup of webpage
US20110055329A1 (en) Dynamic data sharing in a collaborative environment
CN103177095A (en) Embedded browser and implement method thereof
CN107438084B (en) Multi-client data synchronization method and device
CN104426985B (en) Show the method, apparatus and system of webpage
US10102239B2 (en) Application event bridge
CN104980289A (en) Message pushing method, device and system
CN103312751A (en) Instant messaging method based on browser
CN113794909A (en) Video streaming system, method, server, device, and storage medium
CN110309231A (en) A kind of method of data synchronization and system across computer room
CN111988386A (en) Cloud management platform real-time message pushing method and device and computer readable medium
CN111815292A (en) Business approval method and device and computer readable storage medium
CN103716230A (en) Message sending method, device and server
CN110798495B (en) Method and server for end-to-end message push in cluster architecture mode
CN106464728A (en) Method of handling notification channel disconnection
WO2016197851A1 (en) Method and apparatus for managing notification information
CN115951923B (en) Subscription event management method, display system, device and storage medium
CN103685326A (en) WEB concurrent data transmission method and WEB application system
CN112181937B (en) Method and device for transferring data
US10079739B2 (en) Computer-implemented method for handling log file
US9613150B2 (en) Remote viewing of documents via the web in real-time
CN114844957B (en) Link message conversion method, device, equipment, storage medium and program product

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
GR01 Patent grant
GR01 Patent grant