CN104468841A - Method and device for transmitting information in batches - Google Patents
Method and device for transmitting information in batches Download PDFInfo
- Publication number
- CN104468841A CN104468841A CN201410850953.7A CN201410850953A CN104468841A CN 104468841 A CN104468841 A CN 104468841A CN 201410850953 A CN201410850953 A CN 201410850953A CN 104468841 A CN104468841 A CN 104468841A
- Authority
- CN
- China
- Prior art keywords
- message
- sent
- metamessage
- server data
- meta information
- 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
Classifications
-
- 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
-
- 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/06—Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种批量发送消息的方法和装置,应用于分布式消息系统,所述方法包括:读取待发送的已经封装的请求包;解析所述请求包,以获取元信息以及消息;判断所述元信息是否与之前的请求包的元信息相同;以及根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。利用所述方法和装置,可以针对元信息相同的消息进行批量处理,一起发送到相应的服务器数据目录,减少了网络延迟,大幅提升了发送性能。
The invention discloses a method and device for sending messages in batches, which are applied to a distributed message system. The method includes: reading a packaged request packet to be sent; parsing the request packet to obtain meta information and messages; Judging whether the meta information is the same as the meta information of the previous request packet; and according to the judging result, processing the meta information and corresponding messages and sending them to the corresponding server data directory. By using the method and device, messages with the same meta-information can be processed in batches and sent together to a corresponding server data directory, thereby reducing network delay and greatly improving sending performance.
Description
技术领域technical field
本发明涉及计算机技术领域,尤其涉及一种批量发送消息的方法和装置。The present invention relates to the field of computer technology, in particular to a method and device for sending messages in batches.
背景技术Background technique
分布式消息系统是采用分布式处理进行消息发布和订阅的系统,典型的分布式消息系统包括kafka,RabbitMQ,ActiveMQ,QBus等等。A distributed message system is a system that uses distributed processing to publish and subscribe messages. Typical distributed message systems include kafka, RabbitMQ, ActiveMQ, QBus, and so on.
Qbus是一种以kafka为原型的分布式消息系统,其主要由发布方(Producer)、订阅方(Consumer)、存储方(Broker)、协调方(Zookeeper)、代理方(Agent)等单元组成。其中Agent的主要作用是将日志文件实时推送到存储方。Qbus is a distributed message system based on kafka, which is mainly composed of publisher (Producer), subscriber (Consumer), storage (Broker), coordinator (Zookeeper), agent (Agent) and other units. The main function of the Agent is to push the log files to the storage side in real time.
QBus系统目前使用消息单条发送策略,为了保证数据可靠性,数据发送需要等待确收(ACK),网络延迟成为了性能的瓶颈,其中,需要逐一读取请求包后发送到对应的服务器数据目录,多次经过网络造成性能较差,无法满足大量用户调用发送接口的需求,容易造成数据发送积压,引发积压报警,增加运维成本。另外,大量未发送消息导致本地文件无法删除,本地磁盘空间占用率高。The QBus system currently uses a single message sending strategy. In order to ensure data reliability, data sending needs to wait for acknowledgment (ACK), and network delay has become a performance bottleneck. Among them, it is necessary to read the request packets one by one and send them to the corresponding server data directory. Repeatedly passing through the network results in poor performance and cannot meet the needs of a large number of users to call the sending interface. It is easy to cause a backlog of data sending, trigger backlog alarms, and increase operation and maintenance costs. In addition, a large number of unsent messages makes local files unable to be deleted, and the local disk space usage rate is high.
发明内容Contents of the invention
鉴于上述问题,提出了本发明实施例的批量发送消息的方法和装置,以便克服上述问题或者至少部分地解决上述问题。In view of the above problems, the method and device for sending messages in batches according to the embodiments of the present invention are proposed, so as to overcome the above problems or at least partly solve the above problems.
依据本发明的第一方面,提供了一种批量发送消息的方法,应用于分布式消息系统,包括:读取待发送的已经封装的请求包;解析所述请求包,以获取元信息以及消息;判断所述元信息是否与之前的请求包的元信息相同;以及根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。According to the first aspect of the present invention, a method for sending messages in batches is provided, which is applied to a distributed message system, including: reading an encapsulated request packet to be sent; parsing the request packet to obtain meta information and message ; Judging whether the meta information is the same as the meta information of the previous request packet; and according to the judgment result, processing the meta information and the corresponding message and sending them to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的方法中,所述根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录的步骤包括:若判断结果为相同,则将对应的消息缓存到缓存文件中;若判断结果为不同,则将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,并将所述缓存文件清空,将所述不同的元信息所对应的消息缓存到缓存文件中。Optionally, in the method for sending messages in batches according to the embodiment of the present invention, the step of processing the meta information and the corresponding message and sending them to the corresponding server data directory according to the judgment result includes: if the judgment result is If they are the same, the corresponding message is cached in the cache file; if the judgment result is different, the cache file and the corresponding meta information are repackaged into a request packet, and sent to the corresponding server data directory, and the cache The file is cleared, and messages corresponding to the different meta information are cached in the cache file.
可选地,在根据本发明的实施例的批量发送消息的方法中,在所述读取待发送的已经封装的请求包的步骤之前,所述方法还包括:将单个消息与元信息封装为请求包。Optionally, in the method for sending messages in batches according to an embodiment of the present invention, before the step of reading the encapsulated request packet to be sent, the method further includes: encapsulating a single message and meta information into request package.
可选地,在根据本发明的实施例的批量发送消息的方法中,在所述根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录的步骤中,调用异步发送接口将经过处理的元信息以及对应的消息发送到相应的服务器数据目录。Optionally, in the method for sending messages in batches according to the embodiment of the present invention, in the step of processing the meta information and the corresponding messages and sending them to the corresponding server data directory according to the judgment result, call asynchronous sending The interface sends the processed meta-information and corresponding messages to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的方法中,在所述根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录的步骤之后,所述方法还包括:接收服务器返回的确收信息,并将所发送的元信息以及对应的消息删除。Optionally, in the method for sending messages in batches according to an embodiment of the present invention, after the step of processing the meta-information and the corresponding message according to the judgment result and sending it to the corresponding server data directory, the method It also includes: receiving the acknowledgment information returned by the server, and deleting the sent meta-information and the corresponding message.
可选地,在根据本发明的实施例的批量发送消息的方法中,在所述解析所述请求包以获取元信息以及消息的步骤之后,所述方法还包括:判断所述元信息所对应的消息的最大发送超时时间是否低于预先定义的阈值;以及若判断结果为是,则将所述请求包发送到相应的服务器数据目录。Optionally, in the method for sending messages in batches according to an embodiment of the present invention, after the step of parsing the request packet to obtain meta information and messages, the method further includes: judging that the meta information corresponds to Whether the maximum sending timeout time of the message is lower than the predefined threshold; and if the judging result is yes, the request packet is sent to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的方法中,在所述将对应的消息缓存到缓存文件中的步骤之后,所述方法还包括:判断所缓存的消息大小是否超出预先定义的缓存大小;以及若判断结果为是,则将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。Optionally, in the method for sending messages in batches according to an embodiment of the present invention, after the step of caching the corresponding messages into the cache file, the method further includes: judging whether the cached message size exceeds the preset The defined cache size; and if the judgment result is yes, repackage the cached message and meta information into a request packet and send it to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的方法中,在所述将对应的消息缓存到缓存文件中的步骤之后,所述方法还包括:判断是否已经超过所缓存的消息的发送超时时间;以及若判断结果为是,则将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。Optionally, in the method for sending messages in batches according to an embodiment of the present invention, after the step of caching the corresponding messages into the cache file, the method further includes: judging whether the cached message has exceeded sending timeout time; and if the judging result is yes, repackaging the cached message and meta information into a request packet and sending it to the corresponding server data directory.
依据本发明的第二方面,提供了一种批量发送消息的装置,应用于分布式消息系统,包括:读取模块,用于读取待发送的已经封装的请求包;解析模块,用于解析所述请求包,以获取元信息以及消息;第一判断模块,用于判断所述元信息是否与之前的请求包的元信息相同;以及处理和发送模块,用于根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。According to the second aspect of the present invention, there is provided a device for sending messages in batches, which is applied to a distributed message system, including: a reading module, used to read the encapsulated request packet to be sent; a parsing module, used for parsing The request packet is used to obtain meta information and messages; the first judging module is used to judge whether the meta information is the same as the meta information of the previous request packet; and the processing and sending module is used to check the meta information according to the judging result And the corresponding message is processed and sent to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的装置中,处理和发送模块:在判断结果为相同的情况下,将对应的消息缓存到缓存文件中;在判断结果为不同的情况下,将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,并将所述缓存文件清空,将所述不同的元信息所对应的消息缓存到缓存文件中。Optionally, in the device for sending messages in batches according to an embodiment of the present invention, the processing and sending modules: if the judgment result is the same, cache the corresponding message in the cache file; if the judgment result is different Next, repackage the cache file and the corresponding meta information into a request packet, send it to the corresponding server data directory, clear the cache file, and cache the messages corresponding to the different meta information to the cache file middle.
可选地,在根据本发明的实施例的批量发送消息的装置中,还包括封装模块,用于将单个消息与元信息封装为请求包。Optionally, in the apparatus for sending messages in batches according to the embodiment of the present invention, an encapsulation module is further included, configured to encapsulate a single message and meta information into a request packet.
可选地,在根据本发明的实施例的批量发送消息的装置中,所述处理和发送模块调用异步发送接口将经过处理的元信息以及对应的消息发送到相应的服务器数据目录。Optionally, in the device for sending messages in batches according to the embodiment of the present invention, the processing and sending module calls an asynchronous sending interface to send the processed meta information and corresponding messages to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的装置中,还包括确收和删除模块,用于接收服务器返回的确收信息,并将所发送的元信息以及对应的消息删除。Optionally, the device for sending messages in batches according to the embodiment of the present invention further includes a confirmation and deletion module, configured to receive the confirmation information returned by the server, and delete the sent meta information and corresponding messages.
可选地,在根据本发明的实施例的批量发送消息的装置中,还包括第二判断模块,用于在所述解析模块解析所述请求包以获取元信息以及消息之后,判断所述元信息所对应的消息的最大发送超时时间是否低于预先定义的阈值,并且在判断结果为是的情况下,所述处理和发送模块将所述请求包发送到相应的服务器数据目录。Optionally, in the device for sending messages in batches according to an embodiment of the present invention, a second judging module is also included, configured to judge the meta information after the parsing module parses the request packet to obtain meta information and messages. Whether the maximum sending timeout of the message corresponding to the information is lower than the predefined threshold, and if the judgment result is yes, the processing and sending module sends the request packet to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的装置中,还包括第三判断模块,用于在所述处理和发送模块将对应的消息缓存到缓存文件中之后,判断所缓存的消息大小是否超出预先定义的缓存大小,并且在判断结果为是的情况下,所述处理和发送模块将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。Optionally, in the device for sending messages in batches according to the embodiment of the present invention, a third judging module is also included, configured to judge the cached message after the processing and sending module caches the corresponding message in the cache file. Whether the size of the message exceeds the predefined cache size, and if the judgment result is yes, the processing and sending module repackages the cached message and meta information into a request packet and sends it to the corresponding server data directory.
可选地,在根据本发明的实施例的批量发送消息的装置中,还包括第四判断模块,用于在所述处理和发送模块将对应的消息缓存到缓存文件中之后,判断是否已经超过所缓存的消息的发送超时时间,并且在判断结果为是的情况下,所述处理和发送模块将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。Optionally, in the apparatus for sending messages in batches according to an embodiment of the present invention, a fourth judging module is also included, which is used to judge whether the The timeout period for sending the cached message, and if the judgment result is yes, the processing and sending module repackages the cached message and meta information into a request packet and sends it to the corresponding server data directory.
本发明提供了上述批量发送消息的方法和装置,根据本发明的实施例,可以读取待发送的已经封装的请求包,解析所述请求包以获取元信息以及消息,判断所述元信息是否与之前的请求包的元信息相同,并根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。由此,可以针对元信息相同的消息进行批量处理,一起发送到相应的服务器数据目录,减少了网络延迟,大幅提升了发送性能。另外,根据本发明的各可选实施例,由于采取了单个缓存文件的方式,在消息未发送成功时容易执行回滚操作;在接收到服务器返回的确收信息后删除元信息及消息,降低了对本地磁盘的占用;还能够针对消息发送超时时间以及所缓存的消息大小的情况,进行不同的有针对性的处理,确保了发送实时性以及发送成功率。The present invention provides the above method and device for sending messages in batches. According to the embodiment of the present invention, the encapsulated request packet to be sent can be read, the request packet can be parsed to obtain meta-information and messages, and it can be judged whether the meta-information It is the same as the meta information of the previous request packet, and according to the judgment result, the meta information and the corresponding message are processed and sent to the corresponding server data directory. As a result, messages with the same meta information can be processed in batches and sent to the corresponding server data directory together, reducing network delay and greatly improving sending performance. In addition, according to various optional embodiments of the present invention, due to the adoption of a single cache file, it is easy to perform a rollback operation when the message is not sent successfully; delete the meta information and the message after receiving the confirmation information returned by the server, reducing the It occupies the local disk; it can also perform different targeted processing according to the timeout period of message sending and the size of the cached message, so as to ensure the real-time sending and sending success rate.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention, it can be implemented according to the contents of the description, and in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable , the specific embodiments of the present invention are enumerated below.
附图说明Description of drawings
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiment. The drawings are only for the purpose of illustrating a preferred embodiment and are not to be considered as limiting the invention. Also throughout the drawings, the same reference numerals are used to designate the same parts. In the attached picture:
图1是根据本发明的实施例的批量发送消息方法的流程示意图;以及1 is a schematic flow diagram of a method for sending messages in batches according to an embodiment of the present invention; and
图2是根据本发明的实施例的批量发送消息的装置以及服务器的结构示意图。Fig. 2 is a schematic structural diagram of a device for sending messages in batches and a server according to an embodiment of the present invention.
具体实施方式Detailed ways
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided for more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
根据本发明的第一方面,提供了一种批量发送消息的方法100,应用于分布式消息系统。According to the first aspect of the present invention, a method 100 for sending messages in batches is provided, which is applied to a distributed message system.
在本发明的实施例中,分布式消息系统可以是采用分布式处理进行消息发布和订阅的系统,例如包括kafka,RabbitMQ,ActiveMQ,QBus等等。在下文中,将以QBus系统为例,对于本发明的原理进行详细地描述,以帮助读者更好地理解本发明的原理。但本领域技术人员应当理解,本发明的范围并不限于QBus系统,而是可以适用于任何分布式消息系统。In the embodiment of the present invention, the distributed message system may be a system that adopts distributed processing to publish and subscribe messages, for example including kafka, RabbitMQ, ActiveMQ, QBus and so on. In the following, the principle of the present invention will be described in detail by taking the QBus system as an example, so as to help readers better understand the principle of the present invention. However, those skilled in the art should understand that the scope of the present invention is not limited to the QBus system, but can be applied to any distributed message system.
QBus系统主要由发布方(Producer)、订阅方(Consumer)、存储方(Broker)、协调方(Zookeeper)、代理方(Agent)等单元组成。其中代理方的主要作用是将日志文件实时推送到存储方,因此代理方的消息发送机制至关重要。下面将主要以代理方的消息发送为例来例示本发明的原理,同样,本发明的范围不限于此,而是可以应用于分布式消息系统(例如,QBus系统)的各个单元。The QBus system is mainly composed of publishers (Producer), subscribers (Consumer), storage (Broker), coordinator (Zookeeper), agent (Agent) and other units. The main role of the agent is to push log files to the storage in real time, so the message sending mechanism of the agent is very important. The principle of the present invention will be exemplified below by mainly taking the message sending of the agent side as an example. Similarly, the scope of the present invention is not limited thereto, but can be applied to each unit of a distributed message system (eg, QBus system).
图1示出了根据本发明的实施例的批量发送消息方法100的流程图。如图1所示,方法100始于步骤S110,其中,读取待发送的已经封装的请求包。FIG. 1 shows a flowchart of a method 100 for sending messages in batches according to an embodiment of the present invention. As shown in FIG. 1 , the method 100 starts at step S110, wherein the encapsulated request packet to be sent is read.
可选地,根据本发明的实施例,在所述读取待发送的已经封装的请求包的步骤S110之前,所述方法还可以包括以下步骤:将单个消息与元信息(即,meta信息)封装为请求包。根据本发明的实施例,可以调用SDK(软件开发套件)将单个消息与元信息封装成请求包,并记录在本地文件中,以准备发送到服务器。Optionally, according to an embodiment of the present invention, before the step S110 of reading the encapsulated request packet to be sent, the method may further include the following step: combining a single message with meta information (that is, meta information) Encapsulated as a request package. According to the embodiment of the present invention, the SDK (Software Development Kit) can be called to encapsulate a single message and meta information into a request package, and record it in a local file, ready to be sent to the server.
而在步骤S110中,可以读取(例如,从本地文件中)该待发送的已经封装的请求包。之后,在步骤S120中,解析所述请求包,以获取元信息以及消息。例如,可以将已经封装的请求包解封装,并从中获取元信息以及消息。In step S110, the encapsulated request packet to be sent may be read (for example, from a local file). Afterwards, in step S120, the request packet is parsed to obtain meta information and messages. For example, the encapsulated request packet can be decapsulated, and meta information and messages can be obtained from it.
在步骤S120之后,执行步骤S130,其中,判断所述元信息是否与之前的请求包的元信息相同。根据本发明的实施例,存在多种不同的元信息。将与元信息一起封装在请求包中的消息称为与元信息对应的消息,相同的元信息对应的消息类型相同或相似,不同的元信息对应的消息类型不同或不相似。根据本发明的实施例,可以将该类型相同或相似的消息一起批量发送,而类型不同或不相似的消息需要分别发送。After step S120, step S130 is executed, wherein it is judged whether the meta information is the same as the meta information of the previous request packet. According to an embodiment of the present invention, there are various kinds of meta information. The message encapsulated in the request packet together with the meta information is called the message corresponding to the meta information, the message types corresponding to the same meta information are the same or similar, and the message types corresponding to different meta information are different or dissimilar. According to the embodiment of the present invention, messages of the same or similar type can be sent together in batches, while messages of different or dissimilar types need to be sent separately.
接下来,执行步骤S140,其中,根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。Next, step S140 is executed, wherein, according to the judgment result, the meta information and the corresponding message are processed and sent to the corresponding server data directory.
根据本发明的实施例,所述步骤S140可以包括:若判断结果为相同,则将对应的消息缓存到缓存文件中;若判断结果为不同,则将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,并将所述缓存文件清空,将所述不同的元信息所对应的消息缓存到缓存文件中。According to an embodiment of the present invention, the step S140 may include: if the judgment result is the same, then cache the corresponding message into the cache file; if the judgment result is different, then repackage the cache file and the corresponding meta information The request package is sent to the corresponding server data directory, and the cache file is cleared, and the messages corresponding to the different meta information are cached in the cache file.
在上述步骤S140中,如果判断结果相同,即元信息与之前的请求包的元信息相同,则可以将该元信息对应的消息缓存到缓存文件(例如,Batcher.buf文件)中,以准备之前的请求包中的消息一起批量发送到相应的服务器数据目录。In the above step S140, if the judgment result is the same, that is, the meta information is the same as the meta information of the previous request packet, the message corresponding to the meta information can be cached in the cache file (for example, the Batcher. The messages in the request package are sent in batches to the corresponding server data directory.
而如果判断结果不同,即元信息与之前的请求包的元信息不同,需要分别进行发送,则可以将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录。即,将之前缓存在缓存文件中的所有相同类型的消息与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,该服务器数据目录与该元信息相对应。在发送完成后,可以将所述缓存文件清空,并对所述不同的元信息所对应的消息进行缓存处理,将其缓存到缓存文件中。接下来,继续读取下一个请求包,并进行解析以获取其中的元信息以及消息,并判断这一元信息是否与现在缓存的消息对应的元信息相同,并进行上述处理。接着,对于下面的请求包重复上述过程。And if the judgment result is different, that is, the meta information is different from that of the previous request packet and needs to be sent separately, then the cache file and the corresponding meta information can be repackaged into a request packet and sent to the corresponding server data directory . That is, all messages of the same type previously cached in the cache file and corresponding meta information are repackaged into a request packet, and sent to a corresponding server data directory corresponding to the meta information. After the sending is completed, the cache file may be cleared, and the messages corresponding to the different meta information are cached and stored in the cache file. Next, continue to read the next request packet, and parse it to obtain the meta information and message in it, and judge whether this meta information is the same as the meta information corresponding to the currently cached message, and perform the above processing. Next, repeat the above process for the following request packets.
根据本发明的实施例,在所述步骤S140中,可以调用异步发送接口(例如,SDK异步发送接口)将经过处理的元信息以及对应的消息发送到相应的服务器数据目录。According to an embodiment of the present invention, in the step S140, an asynchronous sending interface (for example, an SDK asynchronous sending interface) may be called to send the processed meta information and corresponding messages to the corresponding server data directory.
可选地,根据本发明的实施例,在所述步骤S140之后,所述方法100可以包括以下步骤:接收服务器返回的确收信息,并将所发送的元信息以及对应的消息删除。由此,可以将已经完成发送的元信息以及消息删除,减少对于本地磁盘空间的占用。Optionally, according to an embodiment of the present invention, after the step S140, the method 100 may include the following steps: receiving the acknowledgment information returned by the server, and deleting the sent meta information and the corresponding message. In this way, the meta information and messages that have been sent can be deleted, reducing the occupation of local disk space.
可选地,根据本发明的一种实施例,在所述步骤S120之后,所述方法还可以包括以下可选步骤:判断所述元信息所对应的消息的最大发送超时时间是否低于预先定义的阈值;若判断结果为是,则将所述请求包发送到相应的服务器数据目录。在上述实施例中,判断本次读取和解析的请求包中的元信息所对应的消息的最大发送时间是否低于预先定义的阈值,即,判断这种元信息对应的消息是否具有较高的发送实时性的要求,对于这种元信息(及消息),为了不影响发送实时性,不进行批量发送,而是直接进行单独地发送。上述预先定义的阈值可以根据实际需要来进行选择,为了确保较高的发送实时性,可以选择较小的阈值;而为了确保较高的发送性能,则可以选择较大的阈值。Optionally, according to an embodiment of the present invention, after the step S120, the method may further include the following optional step: judging whether the maximum sending timeout time of the message corresponding to the meta information is lower than the predefined threshold; if the judgment result is yes, then send the request packet to the corresponding server data directory. In the above embodiment, it is judged whether the maximum sending time of the message corresponding to the meta information in the request packet read and parsed this time is lower than the predefined threshold, that is, it is judged whether the message corresponding to the meta information has a higher In order not to affect the real-time transmission of such meta-information (and messages) according to the requirement of real-time transmission, batch transmission is not performed, but individual transmission is directly performed. The above-mentioned predefined threshold can be selected according to actual needs. In order to ensure high real-time transmission, a smaller threshold can be selected; and in order to ensure high transmission performance, a larger threshold can be selected.
可选地,根据本发明的一种实施例,在所述步骤S140中,执行了所述将对应的消息缓存到缓存文件中的步骤之后,所述方法还可以包括以下可选步骤:判断所缓存的消息大小是否超出预先定义的缓存大小;若判断结果为是,则将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。在上述实施例中,可以保证批量发送的请求包的大小不至于过大而影响发送,其中,判断已经缓存的消息的大小是否超出了预先定义的缓存大小,如果已经超出,则不再缓存后续的相同的元信息对应的消息,而是直接进行重新封装和发送。Optionally, according to an embodiment of the present invention, in the step S140, after the step of caching the corresponding message into the cache file is performed, the method may further include the following optional step: judging the Whether the cached message size exceeds the predefined cache size; if the judgment result is yes, repackage the cached message and meta information into a request packet and send it to the corresponding server data directory. In the above-mentioned embodiment, it can be ensured that the size of the request packets sent in batches will not be too large to affect the sending. Among them, it is judged whether the size of the cached message exceeds the predefined cache size. If it has exceeded, the subsequent The message corresponding to the same meta-information, but directly repackaged and sent.
可选地,根据本发明的一种实施例,在所述步骤S140中,执行了所述将对应的消息缓存到缓存文件中的步骤之后,所述方法还可以包括以下可选步骤:判断是否已经超过所缓存的消息的发送超时时间;以及若判断结果为是,则将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。在上述实施例中,可以保证较高的发送实时性,即,保证已经缓存的消息不至于发送超时,一旦判断已经超过所缓存的消息的发送超时时间,就不再缓存后续的相同的元信息对应的消息,而是直接进行重新封装和发送。Optionally, according to an embodiment of the present invention, in step S140, after performing the step of caching the corresponding message into the cache file, the method may further include the following optional step: judging whether The timeout period for sending the cached message has exceeded; and if the judgment result is yes, repackage the cached message and meta information into a request packet, and send it to the corresponding server data directory. In the above embodiment, high real-time transmission can be guaranteed, that is, it is guaranteed that the cached message will not be sent overtime, and once it is judged that the transmission timeout of the cached message has exceeded, the subsequent same meta information will not be cached The corresponding message is directly repackaged and sent.
根据本发明的第二方面,与上述方法100相对应,还提供了一种批量发送消息的装置200,应用于分布式消息系统。According to the second aspect of the present invention, corresponding to the method 100 above, an apparatus 200 for sending messages in batches is also provided, which is applied to a distributed message system.
在本发明的实施例中,分布式消息系统可以是采用分布式处理进行消息发布和订阅的系统,例如包括kafka,RabbitMQ,ActiveMQ,QBus等等。在下文中,将以QBus系统为例,对于本发明的原理进行详细地描述,以帮助读者更好地理解本发明的原理。但本领域技术人员应当理解,本发明的范围并不限于QBus系统,而是可以适用于任何分布式消息系统。In the embodiment of the present invention, the distributed message system may be a system that adopts distributed processing to publish and subscribe messages, for example including kafka, RabbitMQ, ActiveMQ, QBus and so on. In the following, the principle of the present invention will be described in detail by taking the QBus system as an example, so as to help readers better understand the principle of the present invention. However, those skilled in the art should understand that the scope of the present invention is not limited to the QBus system, but can be applied to any distributed message system.
QBus系统主要由发布方(Producer)、订阅方(Consumer)、存储方(Broker)、协调方(Zookeeper)、代理方(Agent)等单元组成。其中代理方的主要作用是将日志文件实时推送到存储方,因此代理方的消息发送机制至关重要。下面将主要以代理方的消息发送为例来例示本发明的原理,同样,本发明的范围不限于此,而是可以应用于分布式消息系统(例如,QBus系统)的各个单元。The QBus system is mainly composed of publishers (Producer), subscribers (Consumer), storage (Broker), coordinator (Zookeeper), agent (Agent) and other units. The main role of the agent is to push log files to the storage in real time, so the message sending mechanism of the agent is very important. The principle of the present invention will be exemplified below by mainly taking the message sending of the agent side as an example. Similarly, the scope of the present invention is not limited thereto, but can be applied to each unit of a distributed message system (eg, QBus system).
图2示出了根据本发明的实施例的批量发送消息的装置200和服务器300的结构示意图。如图2所示,装置200主要包括读取模块210、解析模块220、第一判断模块230、处理和发送模块240。其中,所述读取模块210用于读取待发送的已经封装的请求包;所述解析模块220,用于解析所述请求包,以获取元信息以及消息;所述第一判断模块230,用于判断所述元信息是否与之前的请求包的元信息相同;所述处理和发送模块240,用于根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。Fig. 2 shows a schematic structural diagram of an apparatus 200 for sending messages in batches and a server 300 according to an embodiment of the present invention. As shown in FIG. 2 , the device 200 mainly includes a reading module 210 , an analyzing module 220 , a first judging module 230 , and a processing and sending module 240 . Wherein, the reading module 210 is used to read the encapsulated request packet to be sent; the parsing module 220 is used to parse the request packet to obtain meta information and messages; the first judging module 230, It is used to judge whether the meta information is the same as that of the previous request packet; the processing and sending module 240 is used to process the meta information and corresponding messages according to the judgment result and send them to the corresponding server data directory.
首先,所述读取模块210读取待发送的已经封装的请求包。First, the reading module 210 reads the encapsulated request packet to be sent.
可选地,根据本发明的实施例,所述装置200还可以包括可选模块:封装模块(在图2中未示出),在所述读取模块210读取待发送的已经封装的请求包之前,所述封装模块可以将单个消息与元信息(即,meta信息)封装为请求包。根据本发明的实施例,所述封装模块可以调用SDK(软件开发套件)将单个消息与元信息封装成请求包,并记录在本地文件中,以准备发送到服务器。Optionally, according to an embodiment of the present invention, the apparatus 200 may also include an optional module: an encapsulation module (not shown in FIG. 2 ), where the read module 210 reads the encapsulated request to be sent Before the packet, the encapsulation module may encapsulate a single message and meta information (ie, meta information) into a request packet. According to an embodiment of the present invention, the encapsulation module may call SDK (Software Development Kit) to encapsulate a single message and meta-information into a request package, and record it in a local file, ready to be sent to the server.
所述读取模块210可以读取(例如,从本地文件中)该待发送的已经封装的请求包。之后,所述解析模块220可以解析所述请求包,以获取元信息以及消息。例如,所述解析模块220可以将已经封装的请求包解封装,并从中获取元信息以及消息。The reading module 210 can read (for example, from a local file) the encapsulated request packet to be sent. Afterwards, the parsing module 220 can parse the request packet to obtain meta information and messages. For example, the parsing module 220 may decapsulate the encapsulated request packet, and obtain meta information and messages therefrom.
随后,所述第一判断模块230可以判断所述元信息是否与之前的请求包的元信息相同。根据本发明的实施例,存在多种不同的元信息。将与元信息一起封装在请求包中的消息称为与元信息对应的消息,相同的元信息对应的消息类型相同或相似,不同的元信息对应的消息类型不同或不相似。根据本发明的实施例,可以将该类型相同或相似的消息一起批量发送,而类型不同或不相似的消息需要分别发送。Subsequently, the first judging module 230 can judge whether the meta information is the same as the meta information of the previous request packet. According to an embodiment of the present invention, there are various kinds of meta information. The message encapsulated in the request packet together with the meta information is called the message corresponding to the meta information, the message types corresponding to the same meta information are the same or similar, and the message types corresponding to different meta information are different or dissimilar. According to the embodiment of the present invention, messages of the same or similar type can be sent together in batches, while messages of different or dissimilar types need to be sent separately.
接下来,所述处理和发送模块240可以根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。Next, the processing and sending module 240 may process the meta information and corresponding messages according to the judgment result and send them to the corresponding server data directory.
根据本发明的实施例,若判断结果为相同,则所述处理和发送模块240将对应的消息缓存到缓存文件中;若判断结果为不同,则所述处理和发送模块240将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,并将所述缓存文件清空,将所述不同的元信息所对应的消息缓存到缓存文件中。According to an embodiment of the present invention, if the judgment result is the same, the processing and sending module 240 caches the corresponding message in the cache file; if the judgment result is different, the processing and sending module 240 caches the cache file The corresponding meta information is repackaged into a request packet, and sent to the corresponding server data directory, and the cache file is cleared, and the messages corresponding to the different meta information are cached in the cache file.
如果判断结果相同,即元信息与之前的请求包的元信息相同,则所述处理和发送模块240可以将该元信息对应的消息缓存到缓存文件(例如,Batcher.buf文件)中,以准备之前的请求包中的消息一起批量发送到相应的服务器数据目录。If the judgment result is the same, that is, the meta information is the same as the meta information of the previous request packet, then the processing and sending module 240 can cache the message corresponding to the meta information into a cache file (for example, Batcher.buf file) to prepare The messages in the previous request package are sent to the corresponding server data directory in batches together.
而如果判断结果不同,即元信息与之前的请求包的元信息不同,需要分别进行发送,则所述处理和发送模块240可以将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录。即,所述处理和发送模块240将之前缓存在缓存文件中的所有相同类型的消息与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,该服务器数据目录与该元信息相对应。在发送完成后,所述处理和发送模块240可以将所述缓存文件清空,并对所述不同的元信息所对应的消息进行缓存处理,将其缓存到缓存文件中。接下来,所述读取模块210继续读取下一个请求包,并由所述解析模块220进行解析以获取其中的元信息以及消息,并由所述第一判断模块230判断这一元信息是否与现在缓存的消息对应的元信息相同,并由所述处理和发送模块240进行上述处理。接着,对于下面的请求包重复上述操作。And if the judgment result is different, that is, the meta information is different from that of the previous request packet and needs to be sent separately, then the processing and sending module 240 can repackage the cache file and the corresponding meta information into a request packet, and sent to the appropriate server data directory. That is, the processing and sending module 240 repackages all messages of the same type and corresponding meta-information previously cached in the cache file into a request packet, and sends it to a corresponding server data directory, and the server data directory and the meta-information Corresponding. After the sending is completed, the processing and sending module 240 may clear the cache file, and perform cache processing on the messages corresponding to the different meta information, and cache them in the cache file. Next, the reading module 210 continues to read the next request packet, and the parsing module 220 parses it to obtain the meta information and message therein, and the first judging module 230 judges whether this meta information is consistent with The meta information corresponding to the cached messages is the same, and the processing and sending module 240 performs the above processing. Next, repeat the above operations for the following request packets.
根据本发明的实施例,所述处理和发送模块240可以调用异步发送接口(例如,SDK异步发送接口)将经过处理的元信息以及对应的消息发送到相应的服务器数据目录。According to an embodiment of the present invention, the processing and sending module 240 may call an asynchronous sending interface (eg, SDK asynchronous sending interface) to send the processed meta information and corresponding messages to the corresponding server data directory.
可选地,根据本发明的实施例,所述装置200还可以包括可选模块:确收和删除模块(未在图2中示出),用于在所述处理和发送模块240根据判断结果对元信息以及对应的消息进行处理并发送到相应的服务器数据目录之后,接收服务器返回的确收信息,并将所发送的元信息以及对应的消息删除。由此,可以将已经完成发送的元信息以及消息删除,减少对于本地磁盘空间的占用。Optionally, according to an embodiment of the present invention, the apparatus 200 may also include an optional module: an acknowledgment and deletion module (not shown in FIG. After the meta information and corresponding messages are processed and sent to the corresponding server data directory, the confirmation information returned by the server is received, and the sent meta information and corresponding messages are deleted. In this way, the meta information and messages that have been sent can be deleted, reducing the occupation of local disk space.
可选地,根据本发明的一种实施例,所述装置200还可以包括可选模块:第二判断模块(未在图2中示出),用于在所述解析模块220解析所述请求包以获取元信息以及消息之后,判断所述元信息所对应的消息的最大发送超时时间是否低于预先定义的阈值;若判断结果为是,则所述第二判断模块将所述请求包发送到相应的服务器数据目录。在上述实施例中,所述第二判断模块判断本次读取和解析的请求包中的元信息所对应的消息的最大发送时间是否低于预先定义的阈值,即,所述第二判断模块判断这种元信息对应的消息是否具有较高的发送实时性的要求,对于这种元信息(及消息),为了不影响发送实时性,不进行批量发送,而是直接进行单独地发送。上述预先定义的阈值可以根据实际需要来进行选择,为了确保较高的发送实时性,可以选择较小的阈值;而为了确保较高的发送性能,则可以选择较大的阈值。Optionally, according to an embodiment of the present invention, the apparatus 200 may also include an optional module: a second judging module (not shown in FIG. 2 ), configured to parse the request in the parsing module 220 After obtaining the meta information and the message, judge whether the maximum sending timeout time of the message corresponding to the meta information is lower than the predefined threshold; if the judgment result is yes, then the second judging module sends the request packet to the appropriate server data directory. In the above embodiment, the second judging module judges whether the maximum sending time of the message corresponding to the meta information in the request packet read and parsed this time is lower than a predefined threshold, that is, the second judging module It is judged whether the message corresponding to this kind of meta-information has a higher requirement of real-time sending. For this kind of meta-information (and message), in order not to affect the real-time sending, it is not sent in batches, but directly sent individually. The above-mentioned predefined threshold can be selected according to actual needs. In order to ensure high real-time transmission, a smaller threshold can be selected; and in order to ensure high transmission performance, a larger threshold can be selected.
可选地,根据本发明的一种实施例,所述装置200还可以包括可选模块:第三判断模块(未在图2中示出),用于在所述处理和发送模块240将对应的消息缓存到缓存文件中之后,判断所缓存的消息大小是否超出预先定义的缓存大小;若判断结果为是,则所述第三判断模块将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。在上述实施例中,可以保证批量发送的请求包的大小不至于过大而影响发送,其中,判断已经缓存的消息的大小是否超出了预先定义的缓存大小,如果已经超出,则不再缓存后续的相同的元信息对应的消息,而是直接进行重新封装和发送。Optionally, according to an embodiment of the present invention, the apparatus 200 may also include an optional module: a third judging module (not shown in FIG. 2 ), configured to convert the corresponding After the message is cached in the cache file, it is judged whether the size of the cached message exceeds the predefined cache size; if the judgment result is yes, then the third judging module repackages the cached message and meta information into a request packet, And sent to the corresponding server data directory. In the above-mentioned embodiment, it can be ensured that the size of the request packets sent in batches will not be too large to affect the sending. Among them, it is judged whether the size of the cached message exceeds the predefined cache size. If it has exceeded, the subsequent The message corresponding to the same meta-information, but directly repackaged and sent.
可选地,根据本发明的一种实施例,所述装置200还可以包括可选模块:第四判断模块(未在图2中示出),用于在所述处理和发送模块240将对应的消息缓存到缓存文件中之后,判断是否已经超过所缓存的消息的发送超时时间;若判断结果为是,则所述第四判断模块将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。在上述实施例中,可以保证较高的发送实时性,即,保证已经缓存的消息不至于发送超时,一旦判断已经超过所缓存的消息的发送超时时间,就不再缓存后续的相同的元信息对应的消息,而是直接进行重新封装和发送。Optionally, according to an embodiment of the present invention, the apparatus 200 may also include an optional module: a fourth judging module (not shown in FIG. 2 ), configured to convert the corresponding After the message is cached in the cache file, it is judged whether the sending timeout of the cached message has been exceeded; if the judgment result is yes, then the fourth judging module repackages the cached message and meta information into a request packet, and sent to the appropriate server data directory. In the above embodiment, high real-time transmission can be guaranteed, that is, it is guaranteed that the cached message will not be sent overtime, and once it is judged that the transmission timeout of the cached message has exceeded, the subsequent same meta information will not be cached The corresponding message is directly repackaged and sent.
本发明提供了上述批量发送消息的方法和装置,根据本发明的实施例,可以读取待发送的已经封装的请求包,解析所述请求包以获取元信息以及消息,判断所述元信息是否与之前的请求包的元信息相同,并根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。由此,可以针对元信息相同的消息进行批量处理,一起发送到相应的服务器数据目录,减少了网络延迟,大幅提升了发送性能。另外,根据本发明的各可选实施例,由于采取了单个缓存文件的方式,在消息未发送成功时容易执行回滚操作;在接收到服务器返回的确收信息后删除元信息及消息,降低了对本地磁盘的占用;还能够针对消息发送超时时间以及所缓存的消息大小的情况,进行不同的有针对性的处理,确保了发送实时性以及发送成功率。The present invention provides the above method and device for sending messages in batches. According to the embodiment of the present invention, the encapsulated request packet to be sent can be read, the request packet can be parsed to obtain meta-information and messages, and it can be judged whether the meta-information It is the same as the meta information of the previous request packet, and according to the judgment result, the meta information and the corresponding message are processed and sent to the corresponding server data directory. As a result, messages with the same meta information can be processed in batches and sent to the corresponding server data directory together, reducing network delay and greatly improving sending performance. In addition, according to various optional embodiments of the present invention, due to the adoption of a single cache file, it is easy to perform a rollback operation when the message is not sent successfully; delete the meta information and the message after receiving the confirmation information returned by the server, reducing the It occupies the local disk; it can also perform different targeted processing according to the timeout period of message sending and the size of the cached message, so as to ensure the real-time sending and sending success rate.
在此提供的方法和装置不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类装置所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The methods and apparatus provided herein are not inherently related to any particular computer, virtual system, or other device. Various generic systems can also be used with the teachings based on this. The structure required to construct such an apparatus will be apparent from the foregoing description. Furthermore, the present invention is not specific to any particular programming language. It should be understood that various programming languages can be used to implement the content of the present invention described herein, and the above description of specific languages is for disclosing the best mode of the present invention.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure the understanding of this description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, in order to streamline this disclosure and to facilitate an understanding of one or more of the various inventive aspects, various features of the invention are sometimes grouped together in a single embodiment, figure, or its description. This method of disclosure, however, is not to be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the Detailed Description are hereby expressly incorporated into this Detailed Description, with each claim standing on its own as a separate embodiment of this invention.
本领域那些技术人员可以理解,可以对实施例中的装置中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个装置中。可以把实施例中的若干模块组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者模块中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的替代特征来代替。Those skilled in the art can understand that the modules in the device in the embodiment can be adaptively changed and arranged in one or more devices different from the embodiment. Several modules in an embodiment can be combined into one module or unit or assembly, and further they can be divided into a plurality of sub-modules or sub-units or sub-assemblies. All features disclosed in this specification (including accompanying claims, abstract and drawings) and any method or method so disclosed may be used in any combination, except that at least some of such features and/or procedures or modules are mutually exclusive. All processes or units of equipment are combined. Each feature disclosed in this specification (including accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
此外,本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。Furthermore, those skilled in the art will understand that although some embodiments described herein include some features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention. and form different embodiments. For example, in the claims, any one of the claimed embodiments can be used in any combination.
本发明的各个装置实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的装置中的一些或者全部模块的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various apparatus embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all functions of some or all modules in the device according to the embodiment of the present invention. The present invention can also be implemented as an apparatus program (for example, a computer program and a computer program product) for performing a part or all of the methods described herein. Such a program for realizing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet site, or provided on a carrier signal, or provided in any other form.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”或“包括”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" or "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means can be embodied by one and the same item of hardware. The use of the words first, second, and third, etc. does not indicate any order. These words can be interpreted as names.
本发明还公开了:The invention also discloses:
A1.一种批量发送消息的方法,应用于分布式消息系统,包括:A1. A method for sending messages in batches, applied to a distributed message system, including:
读取待发送的已经封装的请求包;Read the encapsulated request packet to be sent;
解析所述请求包,以获取元信息以及消息;Parsing the request packet to obtain meta information and messages;
判断所述元信息是否与之前的请求包的元信息相同;以及judging whether the meta information is the same as the meta information of the previous request packet; and
根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。According to the judgment result, the meta-information and the corresponding message are processed and sent to the corresponding server data directory.
A2.如权利要求A1所述的方法,其中所述根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录的步骤包括:A2. The method according to claim A1, wherein the step of processing the meta-information and the corresponding message and sending it to the corresponding server data directory according to the judgment result comprises:
若判断结果为相同,则将对应的消息缓存到缓存文件中;If the judgment result is the same, the corresponding message is cached in the cache file;
若判断结果为不同,则将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,并将所述缓存文件清空,将所述不同的元信息所对应的消息缓存到缓存文件中。If the judging result is different, repackage the cache file and the corresponding meta information into a request packet, send it to the corresponding server data directory, clear the cache file, and repackage the cache file corresponding to the different meta information Messages are cached into a cache file.
A3.如权利要求A1所述的方法,其中在所述读取待发送的已经封装的请求包的步骤之前,所述方法还包括:将单个消息与元信息封装为请求包。A3. The method according to claim A1, wherein before the step of reading the encapsulated request packet to be sent, the method further comprises: encapsulating a single message and meta information into a request packet.
A4.如权利要求A1至A3中的任一项所述的方法,其中在所述根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录的步骤中,调用异步发送接口将经过处理的元信息以及对应的消息发送到相应的服务器数据目录。A4. The method according to any one of claims A1 to A3, wherein in the step of processing the meta information and the corresponding message and sending it to the corresponding server data directory according to the judgment result, calling asynchronous sending The interface sends the processed meta-information and corresponding messages to the corresponding server data directory.
A5.如权利要求A1至A3中的任一项所述的方法,其中在所述根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录的步骤之后,所述方法还包括:A5. The method according to any one of claims A1 to A3, wherein after the step of processing the meta information and the corresponding message according to the judgment result and sending it to the corresponding server data directory, the method Also includes:
接收服务器返回的确收信息,并将所发送的元信息以及对应的消息删除。Receive the acknowledgment information returned by the server, and delete the sent meta information and the corresponding message.
A6.如权利要求A1至A3中的任一项所述的方法,其中在所述解析所述请求包以获取元信息以及消息的步骤之后,所述方法还包括:A6. The method according to any one of claims A1 to A3, wherein after the step of parsing the request packet to obtain meta information and messages, the method further comprises:
判断所述元信息所对应的消息的最大发送超时时间是否低于预先定义的阈值;以及judging whether the maximum sending timeout period of the message corresponding to the meta information is lower than a predefined threshold; and
若判断结果为是,则将所述请求包发送到相应的服务器数据目录。If the judgment result is yes, the request packet is sent to the corresponding server data directory.
A7.如权利要求A2所述的方法,其中在所述将对应的消息缓存到缓存文件中的步骤之后,所述方法还包括:A7. The method according to claim A2, wherein after the step of buffering the corresponding message into the cache file, the method further comprises:
判断所缓存的消息大小是否超出预先定义的缓存大小;以及determine whether the cached message size exceeds a predefined cache size; and
若判断结果为是,则将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。If the judgment result is yes, the cached message and meta-information are repackaged into a request packet, and sent to the corresponding server data directory.
A8.如权利要求A2所述的方法,其中在所述将对应的消息缓存到缓存文件中的步骤之后,所述方法还包括:A8. The method according to claim A2, wherein after the step of buffering the corresponding message into the cache file, the method further comprises:
判断是否已经超过所缓存的消息的发送超时时间;以及judging whether the sending timeout period of the buffered message has been exceeded; and
若判断结果为是,则将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。If the judgment result is yes, the cached message and meta-information are repackaged into a request packet, and sent to the corresponding server data directory.
B9.一种批量发送消息的装置,应用于分布式消息系统,包括:B9. A device for sending messages in batches, applied to a distributed message system, comprising:
读取模块,用于读取待发送的已经封装的请求包;The reading module is used to read the encapsulated request packet to be sent;
解析模块,用于解析所述请求包,以获取元信息以及消息;A parsing module, configured to parse the request packet to obtain meta information and messages;
第一判断模块,用于判断所述元信息是否与之前的请求包的元信息相同;以及A first judging module, configured to judge whether the meta information is the same as the meta information of the previous request packet; and
处理和发送模块,用于根据判断结果,对元信息以及对应的消息进行处理并发送到相应的服务器数据目录。The processing and sending module is used to process the meta information and corresponding messages according to the judgment result and send them to the corresponding server data directory.
B10.如权利要求B9所述的装置,其中处理和发送模块:B10. The apparatus of claim B9, wherein the processing and sending module:
在判断结果为相同的情况下,将对应的消息缓存到缓存文件中;If the judgment result is the same, cache the corresponding message into the cache file;
在判断结果为不同的情况下,将所述缓存文件与对应的元信息重新封装为请求包,并发送到相应的服务器数据目录,并将所述缓存文件清空,将所述不同的元信息所对应的消息缓存到缓存文件中。If the judgment result is different, repackage the cache file and the corresponding meta information into a request packet, send it to the corresponding server data directory, clear the cache file, and replace the different meta information The corresponding message is cached in the cache file.
B11.如权利要求B9所述的装置,还包括封装模块,用于将单个消息与元信息封装为请求包。B11. The device according to claim B9, further comprising an encapsulation module, configured to encapsulate a single message and meta-information into a request packet.
B12.如权利要求B9至B11中的任一项所述的装置,其中所述处理和发送模块调用异步发送接口将经过处理的元信息以及对应的消息发送到相应的服务器数据目录。B12. The device according to any one of claims B9 to B11, wherein the processing and sending module calls the asynchronous sending interface to send the processed meta information and corresponding messages to the corresponding server data directory.
B13.如权利要求B9至B11中的任一项所述的装置,还包括确收和删除模块,用于接收服务器返回的确收信息,并将所发送的元信息以及对应的消息删除。B13. The device according to any one of claims B9 to B11, further comprising an acknowledgment and deletion module, configured to receive the acknowledgment information returned by the server, and delete the sent meta information and the corresponding message.
B14.如权利要求B9至B11中的任一项所述的装置,还包括第二判断模块,用于在所述解析模块解析所述请求包以获取元信息以及消息之后,判断所述元信息所对应的消息的最大发送超时时间是否低于预先定义的阈值,并且B14. The device according to any one of claims B9 to B11, further comprising a second judging module for judging the meta information after the parsing module parses the request packet to obtain meta information and messages Whether the maximum sending timeout of the corresponding message is lower than the predefined threshold, and
在判断结果为是的情况下,所述处理和发送模块将所述请求包发送到相应的服务器数据目录。If the judgment result is yes, the processing and sending module sends the request packet to the corresponding server data directory.
B15.如权利要求B10所述的装置,还包括第三判断模块,用于在所述处理和发送模块将对应的消息缓存到缓存文件中之后,判断所缓存的消息大小是否超出预先定义的缓存大小,并且B15. The device according to claim B10, further comprising a third judging module, configured to judge whether the size of the cached message exceeds a predefined cache after the corresponding message is cached in the cache file by the processing and sending module size, and
在判断结果为是的情况下,所述处理和发送模块将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。If the judgment result is yes, the processing and sending module repackages the cached message and meta information into a request packet, and sends it to the corresponding server data directory.
B16.如权利要求B10所述的装置,还包括第四判断模块,用于在所述处理和发送模块将对应的消息缓存到缓存文件中之后,判断是否已经超过所缓存的消息的发送超时时间,并且B16. The device according to claim B10, further comprising a fourth judging module, for judging whether the sending timeout of the cached message has been exceeded after the corresponding message is cached in the cache file by the processing and sending module ,and
在判断结果为是的情况下,所述处理和发送模块将所缓存的消息与元信息重新封装为请求包,并发送到相应的服务器数据目录。If the judgment result is yes, the processing and sending module repackages the cached message and meta information into a request packet, and sends it to the corresponding server data directory.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410850953.7A CN104468841A (en) | 2014-12-30 | 2014-12-30 | Method and device for transmitting information in batches |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410850953.7A CN104468841A (en) | 2014-12-30 | 2014-12-30 | Method and device for transmitting information in batches |
Publications (1)
Publication Number | Publication Date |
---|---|
CN104468841A true CN104468841A (en) | 2015-03-25 |
Family
ID=52914192
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410850953.7A Pending CN104468841A (en) | 2014-12-30 | 2014-12-30 | Method and device for transmitting information in batches |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104468841A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105100271A (en) * | 2015-08-31 | 2015-11-25 | 南京势行软件开发有限公司 | System for publishing distributed flexible extension information and control method thereof |
CN113761433A (en) * | 2020-11-04 | 2021-12-07 | 北京沃东天骏信息技术有限公司 | Service processing method and device |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101815034A (en) * | 2010-03-26 | 2010-08-25 | 迈普通信技术股份有限公司 | Intertask message sending method and communication apparatus |
CN102739781A (en) * | 2012-06-13 | 2012-10-17 | 苏州阔地网络科技有限公司 | Batch scheduling method and system of messages |
CN102916880A (en) * | 2011-08-01 | 2013-02-06 | 中兴通讯股份有限公司 | Method and device for sending and receiving data packet in packet switched network |
-
2014
- 2014-12-30 CN CN201410850953.7A patent/CN104468841A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101815034A (en) * | 2010-03-26 | 2010-08-25 | 迈普通信技术股份有限公司 | Intertask message sending method and communication apparatus |
CN102916880A (en) * | 2011-08-01 | 2013-02-06 | 中兴通讯股份有限公司 | Method and device for sending and receiving data packet in packet switched network |
CN102739781A (en) * | 2012-06-13 | 2012-10-17 | 苏州阔地网络科技有限公司 | Batch scheduling method and system of messages |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105100271A (en) * | 2015-08-31 | 2015-11-25 | 南京势行软件开发有限公司 | System for publishing distributed flexible extension information and control method thereof |
CN113761433A (en) * | 2020-11-04 | 2021-12-07 | 北京沃东天骏信息技术有限公司 | Service processing method and device |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104468629B (en) | A kind of method and apparatus of Batch sending message | |
CN103647726B (en) | Message dispatching method and device thereof | |
CN103678091A (en) | Method and device for processing crash data of application software | |
CN104125547B (en) | Handle the method and short message processing device of short message | |
CN108536538A (en) | Processor core scheduling method and device, terminal and storage medium | |
KR102136945B1 (en) | Service implementation method, device and system based on FIX protocol | |
CN102916983B (en) | The guard system of access to netwoks behavior | |
CN102932375A (en) | Protection method and device for network access behavior | |
CN103634203B (en) | Message asynchronous transport method, device and system | |
CN104935655A (en) | Data display method and device | |
CN104038916B (en) | Method and system, the client of flow optimization are realized on the mobile terminal device | |
CN103491162B (en) | Information sharing method based on mobile Internet and system | |
US9456325B2 (en) | Transmission of a multimedia message doubled with the transmission of a text message | |
CN105657000A (en) | Message transmission method and device | |
WO2017032152A1 (en) | Method for writing data into storage device and storage device | |
US20120079048A1 (en) | Providing remote application access using entitlements | |
US8121129B2 (en) | Optimizing throughput of data in a communications network | |
CN106911735A (en) | Data capture method and device | |
CN103685060A (en) | Data packet sending method and data packet sending device | |
CN106803841A (en) | The read method of message queue data, device and distributed data-storage system | |
WO2014072739A1 (en) | Video distribution | |
CN103942277A (en) | Method and device for downloading file in browsers and browsers | |
CN104468841A (en) | Method and device for transmitting information in batches | |
CN104346460B (en) | Carry out the method, apparatus and browser client of file download | |
WO2025016034A1 (en) | Data transmission method and apparatus, transmission device, terminal device, computer-readbale storage medium, and computer program product |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20150325 |