


技术领域technical field
本发明属于互联网技术领域,尤其涉及一种业务处理方法以及装置、电子设备、介质。The present invention belongs to the field of Internet technologies, and in particular relates to a business processing method and apparatus, electronic equipment and medium.
背景技术Background technique
目前,随着游戏业务中日益丰富的活动内容,后端业务系统的逻辑逐渐复杂。例如,游戏业务中跨服活动的增加,往往会触发大量的跨服业务,对后端业务系统的远程调用和异步并发等业务功能造成较大压力。At present, with the increasingly rich activity content in the game business, the logic of the back-end business system is gradually complicated. For example, the increase of cross-server activities in the game business often triggers a large number of cross-server services, which puts a lot of pressure on business functions such as remote calls and asynchronous concurrency of the back-end business system.
相关技术中,一般的游戏后端框架的远程调用监听回调方案难以在后端业务系统中实现由远程调用请求发起的串联或并联业务逻辑,而如果引入当下主流的Promise/Future到上述游戏框架中,则会因为Promise/Future框架与线程调度、协程调度的深度耦合而破坏游戏框架的线程模型,带来异常风险。另外,现有Promise/Future方案除了会侵入线程模型外,还由于没考虑所依赖的λ函数的缺陷而对线上热更造成麻烦,影响项目的维护与稳定。In the related art, the remote call monitoring callback scheme of the general game back-end framework is difficult to realize the serial or parallel business logic initiated by the remote call request in the back-end business system, and if the current mainstream Promise/Future is introduced into the above game framework , it will destroy the threading model of the game framework due to the deep coupling of the Promise/Future framework with thread scheduling and coroutine scheduling, bringing abnormal risks. In addition, the existing Promise/Future solution not only invades the thread model, but also causes more trouble for online heating because it does not consider the defects of the dependent λ function, which affects the maintenance and stability of the project.
发明内容SUMMARY OF THE INVENTION
本发明提供了一种业务处理方法以及装置、电子设备、介质,以实现与线程协程解耦的业务处理流程,便于在后端业务系统中添加业务处理逻辑,提升后端业务系统的灵活性。The present invention provides a business processing method, device, electronic equipment, and medium, so as to realize the business processing flow decoupled from the thread coroutine, facilitate adding business processing logic in the back-end business system, and improve the flexibility of the back-end business system .
第一方面,本发明提供了一种业务处理方法,该方法包括:In a first aspect, the present invention provides a service processing method, the method comprising:
响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求,每个远程调用请求中包含与相应服务端对应的待处理数据;In response to the remote processing task triggered by the local business, send remote invocation requests to multiple servers executing the remote processing tasks, and each remote invocation request contains data to be processed corresponding to the corresponding server;
生成多个远程调用请求对应的多个Promise代理对象,并组合多个Promise代理对象以得到目标Promise对象;Generate multiple Promise proxy objects corresponding to multiple remote call requests, and combine multiple Promise proxy objects to obtain the target Promise object;
在目标Promise对象上设置监听器;Set a listener on the target Promise object;
通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,并将接收到的数据处理结果传入目标Promise对象;Receive data processing results obtained by multiple servers based on the data to be processed through multiple Promise proxy objects, and transfer the received data processing results to the target Promise object;
通过目标Promise对象将组合后的数据处理结果传递给监听器,以使得本地业务通过监听器获取到组合后的数据处理结果。The combined data processing result is passed to the listener through the target Promise object, so that the local business can obtain the combined data processing result through the listener.
在一可能的设计中,方法还包括:通过Promise代理对象中包含的回调函数接收异步处理任务的执行状态。In a possible design, the method further includes: receiving the execution status of the asynchronous processing task through the callback function contained in the Promise proxy object.
在一可能的设计中,回调函数接口为λ函数。通过Promise代理对象中包含的回调函数接收异步处理任务的执行状态,包括:通过调用setSuccesss方法或setFailure方法传入λ函数,以接收用于指示异步处理任务执行状态的回调参数。In a possible design, the callback function interface is a lambda function. Receive the execution status of the asynchronous processing task through the callback function contained in the Promise proxy object, including: passing in the λ function by calling the setSuccesss method or the setFailure method to receive the callback parameter indicating the execution status of the asynchronous processing task.
在一可能的设计中,方法还包括:对于调用第一回调方法的异步处理任务,若多个服务端中任一服务器返回的执行状态为成功,则确定异步处理任务完成;对于调用第二回调方法的异步处理任务,若多个服务端中所有服务器返回的执行状态均为成功,则确定异步处理任务完成。In a possible design, the method further includes: for the asynchronous processing task that calls the first callback method, if the execution status returned by any one of the multiple servers is successful, it is determined that the asynchronous processing task is completed; The asynchronous processing task of the method, if the execution status returned by all servers in multiple servers is successful, it is determined that the asynchronous processing task is completed.
在一可能的设计中,通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,包括:对于多个Promise代理对象中的每一Promise代理对象,通过每一Promise代理对象中包含的数据处理接口,调用预设的数据返回方法获取多个服务端的数据处理结果;其中,多个Promise代理对象包括面向同步流程的第一Promise代理对象和/或面向异步流程的第二Promise代理对象,数据处理结果包括多个服务端各自对应的返回值和/或异常值。In a possible design, the data processing results obtained by the multiple servers based on the data to be processed are respectively received through multiple Promise proxy objects, including: for each Promise proxy object in the multiple Promise proxy objects, through each Promise proxy object The data processing interface contained in the object calls the preset data return method to obtain the data processing results of multiple servers; wherein the multiple Promise proxy objects include a first Promise proxy object oriented to a synchronous process and/or a second Promise proxy object oriented to an asynchronous process Promise proxy object, the data processing result includes the corresponding return values and/or abnormal values of multiple servers.
在一可能的设计中,第一Promise代理对象对应的数据返回方法包括工厂方法,工厂方法用于从服务端获取Param数据类型的返回值和/或异常值。In a possible design, the data return method corresponding to the first Promise proxy object includes a factory method, and the factory method is used to obtain the return value and/or abnormal value of the Param data type from the server.
在一可能的设计中,响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求,包括:对异步处理任务中的多个待处理数据进行串行化处理,并将串行化处理后的多个待处理数据封装到远程调用请求中;向多个服务端分别发送远程调用请求。In a possible design, in response to a remote processing task triggered by a local service, sending remote invocation requests to multiple servers executing the remote processing task, including: serializing multiple data to be processed in the asynchronous processing task. process, and encapsulate multiple serialized data to be processed into remote call requests; send remote call requests to multiple servers respectively.
在一可能的设计中,组合后的数据处理结果包括串行化处理的多个数据处理结果。In one possible design, the combined data processing results include serialized processing of multiple data processing results.
该方法还包括:若串行化处理的多个数据处理结果中包括异常值,并且异常值处于Promise链末尾,则确定异常值是否被处理;输出未被处理的异常值以及对应的堆栈信息。The method further includes: if the multiple data processing results of the serialization process include an abnormal value and the abnormal value is at the end of the Promise chain, determining whether the abnormal value has been processed; and outputting the unprocessed abnormal value and the corresponding stack information.
在一可能的设计中,方法还包括:对于Promise代理对象包含的回调函数未处理过的变量参数,通过回调函数中设置的可选参数以及预设映射方式获取变量参数。In a possible design, the method further includes: for variable parameters not processed by the callback function contained in the Promise proxy object, obtaining the variable parameters through optional parameters set in the callback function and a preset mapping method.
在一可能的设计中,方法还包括:通过第一回调方法添加与Promise代理对象构成竞争关系的超时Promise对象;若Promise代理对象的返回时间早于超时Promise对象的返回时间,则向监听器传递Promise代理对象的返回值;若超时Promise对象的返回时间早于Promise代理对象的返回时间,则确定Promise代理对象竞争失败,并向监听器传递Promise代理对象存在超时异常。In a possible design, the method further includes: adding a timeout Promise object that forms a competitive relationship with the Promise proxy object through the first callback method; if the return time of the Promise proxy object is earlier than the return time of the timeout Promise object, then pass to the listener. The return value of the Promise proxy object; if the return time of the timeout Promise object is earlier than the return time of the Promise proxy object, it is determined that the Promise proxy object competition fails, and the Promise proxy object is passed to the listener with a timeout exception.
第二方面,本发明提供了一种业务处理装置,该装置包括:In a second aspect, the present invention provides a service processing device, the device comprising:
请求模块,用于响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求,每个远程调用请求中包含与相应服务端对应的待处理数据;a request module, configured to send remote invocation requests to a plurality of servers performing remote processing tasks in response to a remote processing task triggered by a local service, and each remote invocation request includes data to be processed corresponding to the corresponding server;
生成模块,用于生成多个远程调用请求对应的多个Promise代理对象,并组合多个Promise代理对象以得到目标Promise对象;The generation module is used to generate multiple Promise proxy objects corresponding to multiple remote call requests, and combine multiple Promise proxy objects to obtain the target Promise object;
设置模块,用于在目标Promise对象上设置监听器;The settings module is used to set the listener on the target Promise object;
传入模块,用于通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,并将接收到的数据处理结果传入目标Promise对象;The incoming module is used to receive data processing results obtained by multiple servers based on the data to be processed through multiple Promise proxy objects, and transfer the received data processing results to the target Promise object;
传递模块,用于通过目标Promise对象将组合后的数据处理结果传递给监听器,以使得本地业务通过监听器获取到组合后的数据处理结果。The delivery module is used to deliver the combined data processing result to the listener through the target Promise object, so that the local business can obtain the combined data processing result through the listener.
第三方面,本发明实施例提供一种电子设备,其中包括处理器和存储器,其中,所述存储器上存储有可执行代码,当所述可执行代码被所述处理器执行时,使所述处理器至少可以实现第一方面中的业务处理方法。In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory, wherein executable code is stored on the memory, and when the executable code is executed by the processor, the The processor can at least implement the service processing method in the first aspect.
本发明实施例又提供了一种系统,包括处理器和存储器,所述存储器中存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、至少一段程序、代码集或指令集由所述处理器加载并执行以实现上面描述的一种业务处理方法。An embodiment of the present invention further provides a system, including a processor and a memory, wherein the memory stores at least one instruction, at least one piece of program, code set or instruction set, the at least one instruction, at least one piece of program, code set or The instruction set is loaded and executed by the processor to implement a service processing method described above.
本发明实施例进一步提供了一种计算机可读介质,其上存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、至少一段程序、代码集或指令集由处理器加载并执行以实现上面描述的一种业务处理方法。Embodiments of the present invention further provide a computer-readable medium on which is stored at least one instruction, at least one piece of program, code set or instruction set, where the at least one instruction, at least one piece of program, code set or instruction set is stored by a processor Load and execute to implement one of the business processing methods described above.
本发明实施例中,采用Promise异步编程模式设计业务处理逻辑,具体地,响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求,每个远程调用请求中包含与相应服务端对应的待处理数据;生成多个远程调用请求对应的多个Promise代理对象,并组合多个Promise代理对象以得到目标Promise对象;在目标Promise对象上设置监听器;通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,并将接收到的数据处理结果传入Promise对象;通过目标Promise对象将组合后的数据处理结果传递给监听器,以使得本地业务通过监听器获取到组合后的数据处理结果。本发明实施例中,通过多个Promise代理对象接收对应服务端的数据处理结果,进而通过目标Promise对象组合数据处理结果以传递给监听器,便于监听器触发后续业务,实现了与线程/协程的微任务解耦。通过本发明实施例大大简化后端业务逻辑,避免新增业务处理逻辑对后端业务系统框架的侵入,便于在后端业务系统中添加各种业务处理逻辑,提升后端业务系统的灵活性。In the embodiment of the present invention, the business processing logic is designed using the Promise asynchronous programming mode. Specifically, in response to the remote processing task triggered by the local business, remote calling requests are respectively sent to multiple servers executing the remote processing tasks. Each remote calling request It contains the data to be processed corresponding to the corresponding server; generates multiple Promise proxy objects corresponding to multiple remote call requests, and combines multiple Promise proxy objects to obtain the target Promise object; set a listener on the target Promise object; Each Promise proxy object receives the data processing results obtained by multiple servers based on the data to be processed, and transfers the received data processing results to the Promise object; passes the combined data processing results to the listener through the target Promise object to This enables the local business to obtain the combined data processing result through the listener. In the embodiment of the present invention, the data processing results of the corresponding server are received through multiple Promise proxy objects, and then the data processing results are combined through the target Promise object to transmit to the listener, which is convenient for the listener to trigger subsequent services, and realizes the connection with threads/coroutines. Decoupling of microtasks. The embodiment of the present invention greatly simplifies the back-end business logic, avoids the intrusion of new business processing logic into the back-end business system framework, facilitates adding various business processing logics to the back-end business system, and improves the flexibility of the back-end business system.
附图说明Description of drawings
此处所说明的附图用来提供对本发明的进一步理解,构成本发明的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:The accompanying drawings described herein are used to provide further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the attached image:
图1为本发明一实施例提供的一种业务处理方法的流程示意图;FIG. 1 is a schematic flowchart of a service processing method according to an embodiment of the present invention;
图2为本发明一实施例提供的一种业务处理装置的结构示意图;FIG. 2 is a schematic structural diagram of a service processing apparatus according to an embodiment of the present invention;
图3为与本发明实施例提供的业务处理装置对应的电子设备的结构示意图。FIG. 3 is a schematic structural diagram of an electronic device corresponding to a service processing apparatus provided by an embodiment of the present invention.
具体实施方式Detailed ways
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments These are some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
除非另有定义,本文所使用的所有的技术和科学术语与属于本发明的技术领域的技术人员通常理解的含义相同。本文中在本发明的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本发明。Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terms used herein in the description of the present invention are for the purpose of describing specific embodiments only, and are not intended to limit the present invention.
目前,随着游戏业务中日益丰富的活动内容,后端业务系统的逻辑逐渐复杂。例如,游戏业务中跨服活动的增加,往往会触发大量的跨服业务,对后端业务系统的远程调用和异步并发等业务功能造成较大压力。相关技术中,一般的游戏后端框架的远程调用监听回调方案难以在后端业务系统中实现由远程调用请求发起的串联或并联业务逻辑,而如果引入当下主流的Promise/Future到上述游戏框架中,则会因为Promise/Future框架与线程调度、协程调度的深度耦合而破坏游戏框架的线程模型,带来异常风险。At present, with the increasingly rich activity content in the game business, the logic of the back-end business system is gradually complicated. For example, the increase of cross-server activities in the game business often triggers a large number of cross-server services, which puts a lot of pressure on business functions such as remote calls and asynchronous concurrency of the back-end business system. In the related art, the remote call monitoring callback scheme of the general game back-end framework is difficult to realize the serial or parallel business logic initiated by the remote call request in the back-end business system, and if the current mainstream Promise/Future is introduced into the above game framework , it will destroy the threading model of the game framework due to the deep coupling of the Promise/Future framework with thread scheduling and coroutine scheduling, bringing abnormal risks.
此外,相关技术中,现有Promise/Future方案除了会侵入线程模型外,Promise异步编程模式极度依赖λ函数。然而,λ函数捕获了λ函数外的变量时会改变这个匿名内部类的单方法的参数签名和私有字段,导致热更失败。例如,λ函数具有先天缺陷,即λ函数中的λ是一个匿名函数变量,该变量一般会作为方法参数。因此接入现有的Promise方案会对线上代码热更新造成麻烦,影响后续业务的维护以及运行稳定性。In addition, in the related art, the existing Promise/Future scheme not only invades the thread model, but also the Promise asynchronous programming mode is extremely dependent on the λ function. However, when the λ function captures the variables outside the λ function, it will change the parameter signature and private fields of the single method of this anonymous inner class, causing the hotfix to fail. For example, the λ function has a congenital defect, that is, the λ in the λ function is an anonymous function variable, which is generally used as a method parameter. Therefore, accessing the existing Promise solution will cause trouble for online code hot update, affecting the maintenance and operation stability of subsequent services.
本发明实施例提供的业务处理方案的核心思想是:采用Promise异步编程模式设计业务处理逻辑,从而在后端业务处理系统保持原有线程以及进度池调用的情况下,融入新增业务处理逻辑。具体地,响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求,每个远程调用请求中包含与相应服务端对应的待处理数据;生成多个远程调用请求对应的多个Promise代理对象,并组合多个Promise代理对象以得到目标Promise对象;在目标Promise对象上设置监听器;通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,并将接收到的数据处理结果传入Promise对象;通过目标Promise对象将组合后的数据处理结果传递给监听器,以使得本地业务通过监听器获取到组合后的数据处理结果。本方案中通过多个Promise代理对象接收对应服务端的数据处理结果,进而通过目标Promise对象组合数据处理结果以传递给监听器,便于监听器触发后续业务,实现了与线程/协程的微任务解耦。通过本方案大大简化后端业务逻辑,避免新增业务处理逻辑对后端业务系统框架的侵入,便于在后端业务系统中添加各种业务处理逻辑,提升后端业务系统的灵活性。The core idea of the business processing solution provided by the embodiments of the present invention is to design business processing logic by adopting the Promise asynchronous programming mode, so as to incorporate new business processing logic while the back-end business processing system maintains the original thread and progress pool calls. Specifically, in response to a remote processing task triggered by a local service, a remote invocation request is respectively sent to multiple servers performing the remote processing task, and each remote invocation request contains data to be processed corresponding to the corresponding server; Call multiple Promise proxy objects corresponding to the request, and combine multiple Promise proxy objects to obtain the target Promise object; set a listener on the target Promise object; receive the data obtained from multiple servers based on the data to be processed through multiple Promise proxy objects. Data processing results, and pass the received data processing results into the Promise object; pass the combined data processing results to the listener through the target Promise object, so that the local business can obtain the combined data processing results through the listener. In this solution, the data processing results of the corresponding server are received through multiple Promise proxy objects, and then the data processing results are combined through the target Promise object to pass to the listener, which is convenient for the listener to trigger subsequent services, and realizes the micro-task solution with threads/coroutines. coupled. This solution greatly simplifies the back-end business logic, avoids the intrusion of new business processing logic into the back-end business system framework, facilitates adding various business processing logics to the back-end business system, and improves the flexibility of the back-end business system.
在介绍了业务处理方案的核心思路之后,下面具体介绍本发明的各种非限制性实施例。After the core idea of the service processing solution is introduced, various non-limiting embodiments of the present invention are specifically described below.
本发明实施例中,提供了一种Promise组件,为上述核心思路中的业务处理方案提供实现基础。具体地,Promise组件包括接口层、核心层、应用层。In the embodiment of the present invention, a Promise component is provided, which provides an implementation basis for the business processing solution in the above-mentioned core idea. Specifically, the Promise component includes an interface layer, a core layer, and an application layer.
在接口层中包括以下模块:Promise模块、监听器模块(Promise.Listener)、映射模块(Promise.Mapper)、任务模块(PromiseTask)。接口层主要用于提供业务处理逻辑中所需调用的接口方法,例如,onSuccess、onFailure等以onXxx形式命名的方法,这些方法用于监听同步流程或异步流程的返回值。例如,addContext、addTimeout等以addXxx形式命名的方法,此类方法用于添加额外操作。例如,ofValue、ofError、ofAsync、ofParam等以ofXxx形式命名的方法,此类方法属于Promise构造工厂方法。例如,all、allSuccess、any、anySuccess等方法,此类方法主要用于并发组合以及竞争模型的构建。The interface layer includes the following modules: Promise module, listener module (Promise.Listener), mapping module (Promise.Mapper), task module (PromiseTask). The interface layer is mainly used to provide interface methods that need to be called in the business processing logic. For example, onSuccess, onFailure, and other methods named in the form of onXxx are used to monitor the return value of a synchronous process or an asynchronous process. For example, addContext, addTimeout, etc. methods named addXxx, such methods are used to add additional operations. For example, ofValue, ofError, ofAsync, ofParam and other methods named in the form ofXxx, such methods belong to Promise construction factory methods. For example, all, allSuccess, any, anySuccess and other methods are mainly used for concurrent composition and the construction of competition models.
需要注意的是,区别于相关技术,本发明中涉及的PromiseTask并不与微任务绑定,而是通过回调方式通知任务的执行情况,从而避免内嵌于后端业务处理系统的线程/协程调度中,这样通过接口层提供的模块以及接口方法可以实现与微任务的解耦。It should be noted that, different from related technologies, the PromiseTask involved in the present invention is not bound to the micro-task, but notifies the execution of the task through a callback method, thereby avoiding the thread/coroutine embedded in the back-end business processing system. In scheduling, the modules and interface methods provided by the interface layer can achieve decoupling from microtasks.
相关技术中,Promise框架通常只考虑异步流程,并且与微任务调度深度绑定,因而需要设置针对同步流程和异步流程的两套业务处理逻辑。而本发明中通过统一的Promise接口以及Promise代理对象,合并同步流程和异步流程的业务处理逻辑,从而大大简化后端业务处理逻辑的实现方式,提升业务处理逻辑的灵活性。具体实现方式下文实施例中介绍,此处在不展开。In related technologies, the Promise framework usually only considers asynchronous processes and is deeply bound to microtask scheduling, so it is necessary to set two sets of business processing logic for synchronous processes and asynchronous processes. In the present invention, the business processing logic of the synchronous process and the asynchronous process is combined through a unified Promise interface and a Promise proxy object, thereby greatly simplifying the implementation of the back-end business processing logic and improving the flexibility of the business processing logic. The specific implementation is introduced in the following embodiments, and will not be expanded here.
在核心层中包括以下模块:第一Promise代理对象(PromiseResult)、第二Promise代理对象(PromiseAsync)、消息模块(PromiseInfo)。核心层主要用于Promise的内部实现。其中,PromiseResult用于返回值与热更上下文的封装,PromiseAsync用于内部任务的等待、完成、异常状态、监听器的调度管理,PromiseInfo用于获取线程环境与RPC调用的追踪信息。The core layer includes the following modules: a first Promise proxy object (PromiseResult), a second Promise proxy object (PromiseAsync), and a message module (PromiseInfo). The core layer is mainly used for the internal implementation of Promises. Among them, PromiseResult is used for encapsulation of return value and hot update context, PromiseAsync is used for internal task waiting, completion, exception status, and scheduling management of listeners, and PromiseInfo is used to obtain thread environment and RPC call tracking information.
在应用层中包括以下模块:FuncPromise、PBool、Pint、PList、PLong、PMap、PString。应用层主要用于将Promise组件整合到后端业务处理系统的框架中实现具体应用场景。具体地,FuncPromise模块用于在后端业务处理系统的框架中实现远程调用以及Promise组件的异步任务集成,避免每次远程调用都需要重写并包装异步任务的实现过程。PBool、Pint、PList、PLong、PMap、PString等模块提供了一些Promise版本的常用或基本类型功能实现,用以简化相应类型的开发流程。比如,远程调用(Remote Procedure Call,RPC)过程中的参数传递以及返回值传递、异常捕获、异常包装以及其他Promise的功能实现。The following modules are included in the application layer: FuncPromise, PBool, Pint, PList, PLong, PMap, PString. The application layer is mainly used to integrate Promise components into the framework of the back-end business processing system to achieve specific application scenarios. Specifically, the FuncPromise module is used to implement remote calls and asynchronous task integration of Promise components in the framework of the back-end business processing system, avoiding the need to rewrite and wrap the implementation process of asynchronous tasks for each remote call. Modules such as PBool, Pint, PList, PLong, PMap, and PString provide some common or basic type function implementations of Promise versions to simplify the development process of corresponding types. For example, parameter transfer and return value transfer, exception capture, exception wrapping and other Promise functions in the Remote Procedure Call (RPC) process.
通过上述Promise组件有助于实现与线程/协程的微任务解耦,简化后端业务逻辑,避免新增业务处理逻辑对后端业务系统框架的侵入,便于在后端业务系统中添加各种业务处理逻辑,提升后端业务系统的灵活性。The above Promise components help to realize the decoupling of micro-tasks from threads/coroutines, simplify the back-end business logic, avoid the intrusion of new business processing logic into the back-end business system framework, and facilitate adding various types of back-end business systems to the back-end business system. The business processing logic improves the flexibility of the back-end business system.
下面结合以下实施例对业务处理方法的执行过程进行说明。The execution process of the service processing method will be described below with reference to the following embodiments.
图1为本发明实施例提供的一种业务处理方法的流程图。如图1所示,该业务处理方法包括如下步骤:FIG. 1 is a flowchart of a service processing method provided by an embodiment of the present invention. As shown in Figure 1, the service processing method includes the following steps:
101、响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求,每个远程调用请求中包含与相应服务端对应的待处理数据;101. In response to a remote processing task triggered by a local service, send remote invocation requests to multiple servers executing the remote processing tasks, and each remote invocation request includes data to be processed corresponding to the corresponding server;
102、生成多个远程调用请求对应的多个Promise代理对象,并组合多个Promise代理对象以得到目标Promise对象;102. Generate multiple Promise proxy objects corresponding to multiple remote call requests, and combine multiple Promise proxy objects to obtain the target Promise object;
103、在目标Promise对象上设置监听器;103. Set a listener on the target Promise object;
104、通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,并将接收到的数据处理结果传入目标Promise对象;104. Receive data processing results obtained by multiple servers based on the data to be processed through multiple Promise proxy objects, respectively, and transfer the received data processing results to the target Promise object;
105、通过目标Promise对象将组合后的数据处理结果传递给监听器,以使得本地业务通过监听器获取到组合后的数据处理结果。105. Pass the combined data processing result to the listener through the target Promise object, so that the local business obtains the combined data processing result through the listener.
上述业务处理方法采用Promise异步编程模式设计业务处理逻辑,从而在后端业务处理系统保持原有线程以及进度池调用的情况下,融入新增业务处理逻辑。这样,能够实现与线程/协程的微任务解耦,大大简化后端业务逻辑,避免新增业务处理逻辑对后端业务系统框架的侵入,便于在后端业务系统中添加各种业务处理逻辑,提升后端业务系统的灵活性。The above business processing method adopts the Promise asynchronous programming mode to design business processing logic, so that the new business processing logic is integrated while the back-end business processing system maintains the original thread and progress pool call. In this way, decoupling from threads/coroutines can be realized, which greatly simplifies the back-end business logic, avoids the intrusion of new business processing logic into the back-end business system framework, and facilitates adding various business processing logic to the back-end business system. , to improve the flexibility of the back-end business system.
本发明实施例提供的业务处理方法可以由一电子设备来执行,该电子设备可以是诸如智能手机、平板电脑、PC机、笔记本电脑等终端设备。具体地,可以由安装在终端设备中的客户端实现。当然,也可以是由服务器、服务器集群、云服务器、云服务平台等设备实现后将执行结果下发到客户端中。The service processing method provided by the embodiment of the present invention may be executed by an electronic device, and the electronic device may be a terminal device such as a smart phone, a tablet computer, a PC, a notebook computer, and the like. Specifically, it can be implemented by a client installed in a terminal device. Of course, it can also be implemented by a server, a server cluster, a cloud server, a cloud service platform, and other devices to deliver the execution result to the client.
为便于描述,下文结合具体示例说明图1示出的业务处理方法的具体执行过程:For the convenience of description, the specific execution process of the service processing method shown in FIG. 1 is described below with reference to specific examples:
首先,101中,响应于本地业务触发的远程处理任务,向执行远程处理任务的多个服务端分别发送远程调用请求。First, in 101, in response to a remote processing task triggered by a local service, a remote invocation request is respectively sent to a plurality of servers executing the remote processing task.
可以理解的是,所述远程处理任务可以是异步任务,多个服务端可以执行所述异步任务,每个远程调用请求中包含与相应服务端对应的待处理数据。此处待处理数据可以理解为需要调用远程处理的业务数据。可选地,待处理数据可以是串行化处理后的链式数据,以支持串行业务的链式调用,简化并行业务组合、竞争模型等业务逻辑。当然,远程处理任务也可以是同步任务,或者包含异步任务以及同步任务的混合任务,本发明并不限定。It can be understood that the remote processing task may be an asynchronous task, and multiple servers may execute the asynchronous task, and each remote call request includes to-be-processed data corresponding to the corresponding server. The data to be processed here can be understood as business data that needs to be called for remote processing. Optionally, the data to be processed may be serialized chained data to support chained invocation of serial services and simplify business logic such as parallel business combination and competition model. Of course, the remote processing task may also be a synchronous task, or a mixed task including an asynchronous task and a synchronous task, which is not limited in the present invention.
以所述远程处理任务为异步处理任务为例,上述步骤中,响应于本地业务触发的异步处理任务,向执行异步处理任务的多个服务端分别发送远程调用请求的一种可选实施方式:对异步处理任务中的多个待处理数据进行串行化处理,并将串行化处理后的多个待处理数据封装到远程调用请求中;向多个服务端分别发送远程调用请求。Taking the remote processing task as an asynchronous processing task as an example, in the above steps, in response to an asynchronous processing task triggered by a local service, an optional implementation manner of sending a remote calling request to multiple servers executing the asynchronous processing task: Serialize the multiple data to be processed in the asynchronous processing task, and encapsulate the multiple serialized data to be processed into the remote call request; send the remote call request to the multiple servers respectively.
以获取玩家是否在线的应用场景为例,本地业务如果需要获取玩家在线状态,可以将需要获取的玩家组建为目标玩家列表即humanIds,进而按照玩家所在服务器分为多组。每一组玩家数据即为与所在服务器对应的待处理数据。具体地,基于上述玩家分组发起异步处理任务中的远程调用,对异步处理任务中的多个待处理数据进行串行化处理,生成串行化请求参数即各个服务器对应的玩家列表(humanIds),通过远程调用请求将humanIds发送给对应服务器,完成对humanIds的远程处理。Taking the application scenario of obtaining whether a player is online as an example, if the local business needs to obtain the online status of the player, the player to be obtained can be formed into a target player list, namely humanIds, and then divided into multiple groups according to the server where the player is located. Each set of player data is the data to be processed corresponding to the server where it is located. Specifically, the remote call in the asynchronous processing task is initiated based on the above-mentioned player grouping, and the multiple data to be processed in the asynchronous processing task is serialized to generate the serialized request parameter, that is, the player list (humanIds) corresponding to each server, Send humanIds to the corresponding server through a remote call request to complete the remote processing of humanIds.
进而,102中,生成多个远程调用请求对应的多个Promise代理对象,并组合多个Promise代理对象以得到目标Promise对象。103中,在目标Promise对象上设置监听器。Further, in 102, multiple Promise proxy objects corresponding to the multiple remote call requests are generated, and the multiple Promise proxy objects are combined to obtain the target Promise object. In 103, a listener is set on the target Promise object.
仍以获取玩家是否在线的应用场景为例,本地业务发起每个远程调用方法都会构造并返回一个Promise代理对象,进而使用Promise.all方法组合这批Promise代理对象,得到pOnlineIds(即目标Promise对象)。进而,针对pOnlineIds的返回值设置监听器,用于直接监听各个远程调用对应的返回值,以便获取组合后的数据处理结果。Still taking the application scenario of obtaining whether the player is online or not as an example, each remote call method initiated by the local business will construct and return a Promise proxy object, and then use the Promise.all method to combine these Promise proxy objects to obtain pOnlineIds (that is, the target Promise object) . Furthermore, a listener is set for the return value of pOnlineIds, which is used to directly monitor the return value corresponding to each remote call, so as to obtain the combined data processing result.
进而,104中,通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果,并将接收到的数据处理结果传入目标Promise对象。105中,通过目标Promise对象将组合后的数据处理结果传递给监听器,以使得本地业务通过监听器获取到组合后的数据处理结果。Further, in 104, the data processing results obtained by the multiple servers based on the data to be processed are respectively received through the multiple Promise proxy objects, and the received data processing results are transferred to the target Promise object. In 105, the combined data processing result is passed to the listener through the target Promise object, so that the local service obtains the combined data processing result through the listener.
仍以获取玩家是否在线的应用场景为例,104中,远程调用的多个服务端接收串行化参数(即humanIds)之后,判断humanIds列表中哪些玩家在线。基于在线情况构造在线玩家id集合onlineIds(即数据处理结果),进而通过Promise.ofParam方法向Promise代理对象返回包含onlineIds的Promise对象,并将Promise对象串行化后传入本地业务的目标Promise对象中。具体地,各个远程调用服务端发送的数据执行结果由本地业务中的Promise代理对象接收,并传递给Promise.all。105中,当全部远程调用服务端均返回后,pOnlineIds将组合完毕的所有在线玩家集合传递给监听器。Still taking the application scenario of obtaining whether a player is online or not as an example, in
在本发明的一实施例中,提供了104中,通过多个Promise代理对象分别接收多个服务端基于待处理数据得到的数据处理结果的一种可选实施方式:对于多个Promise代理对象中的每一Promise代理对象,通过每一Promise代理对象中包含的数据处理接口,调用预设的数据返回方法获取多个服务端的数据处理结果。其中,多个Promise代理对象包括面向同步流程的第一Promise代理对象和/或面向异步流程的第二Promise代理对象。实际应用中,第一Promise代理对象可以记为PromiseResult,第二Promise代理对象可以记为PromiseAsync。多个服务端的数据处理结果包括但不限于多个服务端各自对应的返回值和/或异常值。In an embodiment of the present invention, an optional implementation manner of receiving data processing results obtained by multiple servers based on to-be-processed data through multiple Promise proxy objects is provided in 104: for the multiple Promise proxy objects in the Each Promise proxy object of , through the data processing interface contained in each Promise proxy object, calls the preset data return method to obtain the data processing results of multiple servers. The multiple Promise proxy objects include a first Promise proxy object oriented to a synchronous process and/or a second Promise proxy object oriented to an asynchronous process. In practical applications, the first Promise proxy object may be recorded as PromiseResult, and the second Promise proxy object may be recorded as PromiseAsync. The data processing results of the multiple servers include, but are not limited to, return values and/or abnormal values corresponding to the multiple servers.
具体而言,在一可选实施例中,构建面向同步流程的PromiseResult(即第一Promise代理对象),具体地,通过ofValue方法可以在PromiseResult中传入同步阻塞返回的返回值,或者通过ofError方法在PromiseResult中传入同步阻塞返回的异常。PromiseResult用于包装返回值或异常,并按照预先设置的Promise接口将返回值和异常通过以getXxx或onXxx命名的接口方法传递给相应业务处理端,并对返回值或异常添加对应的监听模块和处理模块。Specifically, in an optional embodiment, a PromiseResult (ie, the first Promise proxy object) oriented to the synchronous process is constructed. Specifically, the return value returned by synchronous blocking can be passed in the PromiseResult through the ofValue method, or the return value returned by the synchronous blocking can be passed through the ofError method. Pass in the exception returned by synchronous blocking in PromiseResult. PromiseResult is used to wrap the return value or exception, and pass the return value and exception to the corresponding business processing end through the interface method named getXxx or onXxx according to the preset Promise interface, and add the corresponding monitoring module and processing to the return value or exception module.
可选地,第一Promise代理对象对应的数据返回方法还包括工厂方法,该工厂方法用于从服务端获取Param数据类型的返回值和/或异常值。例如,ofParam工厂方法,该ofParam工厂方法能够提供Param的Promise版本包装类型(即Promise<Param>),通过这一方法能够更简便地整合后端业务系统中的远程调用的返回数据(如Param类型的返回值)。Optionally, the data return method corresponding to the first Promise proxy object further includes a factory method, where the factory method is used to obtain the return value and/or the abnormal value of the Param data type from the server. For example, ofParam factory method, the ofParam factory method can provide Param's Promise version wrapper type (ie Promise<Param>), this method can more easily integrate the return data of remote calls in the back-end business system (such as Param type) The return value).
另一可选实施例中,构建面向异步流程的PromiseAsync(即第二Promise代理对象),具体地,通过ofAsync方法传入一个PromiseTask到PromiseAsync中,将执行异步流程的异步任务包装成PromiseAsync。具体地,PromiseAsync中持有传入的PromiseTask,该PromiseTask用于获取回调(callback)参数,通过PromiseTask获取的回调参数能够设置PromiseAsync所处状态以及参数值。In another optional embodiment, an asynchronous process-oriented PromiseAsync (ie, a second Promise proxy object) is constructed. Specifically, a PromiseTask is passed into the PromiseAsync through the ofAsync method, and the asynchronous task executing the asynchronous process is packaged into a PromiseAsync. Specifically, the PromiseAsync holds the incoming PromiseTask, and the PromiseTask is used to obtain the callback parameter, and the callback parameter obtained through the PromiseTask can set the state of the PromiseAsync and the parameter value.
其中,PromiseTask是一个λ函数,用于接收回调参数,执行需求的业务逻辑,然后通过回调参数的setSuccesss方法或setFailure方法通知任务执行成功/失败。在本发明的一实施例中,对于面向异步流程的Promise代理对象,还可通过Promise代理对象中包含的回调函数接收异步处理任务的执行状态。本发明中PromiseTask通过回调参数来通知任务执行情况,因此本身不会创建线程或协程,也不负责微任务调度。具体地,假设Promise代理对象中包含的回调函数接口为λ函数。基于此,提供了上述步骤的一种可选实施方式,即:通过调用setSuccesss方法传入λ函数以接收用于指示异步处理任务执行状态的回调参数。或者,通过调用setFailure方法传入λ函数以接收用于指示异步处理任务执行状态的回调参数。Among them, PromiseTask is a λ function, which is used to receive callback parameters, execute the required business logic, and then notify the task execution success/failure through the setSuccesss method or setFailure method of the callback parameter. In an embodiment of the present invention, for an asynchronous process-oriented Promise proxy object, the execution status of the asynchronous processing task can also be received through a callback function included in the Promise proxy object. In the present invention, PromiseTask notifies task execution status through callback parameters, so it does not create threads or coroutines, nor is it responsible for microtask scheduling. Specifically, it is assumed that the callback function interface contained in the Promise proxy object is the λ function. Based on this, an optional implementation manner of the above steps is provided, that is, the λ function is passed in by calling the setSuccesss method to receive a callback parameter used to indicate the execution state of the asynchronous processing task. Alternatively, pass in the λ function by calling the setFailure method to receive a callback parameter indicating the execution status of the asynchronous processing task.
实际应用中,回调方法有多种。通过回调方法可以等待所有或部分任务的返回值,再基于返回值推进后续业务处理流程。具体地,对于调用第一回调方法的异步处理任务,该第一回调方法比如是以any命名的一系列方法,比如any方法、anySuccess方法,具体地,若多个服务端中任一服务器返回的执行状态为成功,则确定异步处理任务完成。可以理解的是,any方法对应竞争模型,也即接收一个Promise代理对象的返回值后即可确定对应的一组Promise代理对象执行完成。此情况下可忽略后续完成的Promise代理对象。In practical applications, there are many callback methods. Through the callback method, you can wait for the return value of all or some tasks, and then advance the subsequent business processing flow based on the return value. Specifically, for the asynchronous processing task that calls the first callback method, the first callback method is, for example, a series of methods named any, such as the any method and the anySuccess method. If the execution status is successful, it is determined that the asynchronous processing task is completed. It can be understood that the any method corresponds to the competition model, that is, after receiving the return value of a Promise proxy object, it can be determined that the execution of the corresponding set of Promise proxy objects is completed. In this case, subsequently completed Promise proxy objects can be ignored.
对于调用第二回调方法的异步处理任务,该第二回调方法比如是以All命名的一系列方法,如all方法、allSuccess方法,具体地,若多个服务端中所有服务器返回的执行状态均为成功,则确定异步处理任务完成。可以理解的是,all对应组合模型,也即接收一组Promise代理对象的返回监听任务,需要等待所有Promise代理对象的返回值传入后才能确定任务执行成功或失败。比如,记录所有Promise代理对象的传入数量,每成功或失败则进行一次标记,待所有任务计数完成后设置该组Promise代理对象成功或失败。For the asynchronous processing task that calls the second callback method, the second callback method is, for example, a series of methods named All, such as the all method and the allSuccess method. Specifically, if the execution status returned by all the servers in the multiple servers is If successful, it is determined that the asynchronous processing task is completed. It is understandable that all corresponds to the combination model, that is, receiving a return monitoring task of a set of Promise proxy objects, and it is necessary to wait for the return values of all Promise proxy objects to be passed in before determining whether the task execution succeeds or fails. For example, record the incoming number of all Promise proxy objects, mark each success or failure, and set the group of Promise proxy objects to succeed or fail after all tasks are counted.
由于网络环境、硬件故障、逻辑错误等原因,需要对业务超时情况,尤其是异步任务远程调用的超时情况进行监控。为此,在本发明的一实施例中,可选地,为每个进程创建一个专门的服务(Service)用于维护时钟队列,并向时钟队列中注册Promise的回调,以在指定时间通知任务完成情况,从而构造出一个延迟指定时间后返回的超时Promise对象(如TimeoutPromise)。Due to network environment, hardware failure, logic error and other reasons, it is necessary to monitor the business timeout, especially the timeout of remote calls of asynchronous tasks. To this end, in an embodiment of the present invention, optionally, a dedicated service (Service) is created for each process to maintain the clock queue, and the callback of Promise is registered in the clock queue to notify the task at a specified time Completion, thus constructing a timeout Promise object (such as TimeoutPromise) that is returned after a delay of the specified time.
可选地,还可通过第一回调方法添加与Promise代理对象构成竞争关系的超时Promise对象;若Promise代理对象的返回时间早于超时Promise对象的返回时间,则向监听器传递Promise代理对象的返回值;若超时Promise对象的返回时间早于Promise代理对象的返回时间,则确定Promise代理对象竞争失败,并向监听器传递Promise代理对象存在超时异常。Optionally, a timeout Promise object that forms a competitive relationship with the Promise proxy object can also be added through the first callback method; if the return time of the Promise proxy object is earlier than the return time of the timeout Promise object, the return of the Promise proxy object is passed to the listener. Value; if the return time of the timeout Promise object is earlier than the return time of the Promise proxy object, it is determined that the Promise proxy object competition fails, and a timeout exception exists in the Promise proxy object passed to the listener.
具体来说,就是通过前文实施例介绍的any方法(即第一回调方法),针对需要添加超时处理的Promise代理对象,构造对应的超时Promise对象。如果Promise代理对象抢先返回,则该Promise代理对象返回竞争成功,将Promise代理对象的返回值传递给链后的监听器或处理模块。如果超时Promise对象抢先返回,则该Promise代理对象返回竞争失败,此情况下会传递超时异常给链后的监听器。Specifically, through the any method (ie, the first callback method) described in the foregoing embodiment, a corresponding timeout Promise object is constructed for the Promise proxy object to which timeout processing needs to be added. If the Promise proxy object returns first, the Promise proxy object returns the competition successfully, and the return value of the Promise proxy object is passed to the listener or processing module after the chain. If the timeout Promise object returns first, the Promise proxy object returns a competition failure, and in this case, a timeout exception will be passed to the listener behind the chain.
除此之外,在PromiseAsync包装异步任务,用以管理异步任务的返回值以及为调度相关业务添加监听器。此处与同步流程相似,PromiseAsync中也可按照预先设置的Promise接口将返回值和异常通过以getXxx或onXxx命名的接口方法传递给相应业务处理端,并对返回值或异常添加对应的监听模块和处理模块。In addition, the asynchronous task is wrapped in PromiseAsync to manage the return value of the asynchronous task and add listeners for scheduling related services. Similar to the synchronization process here, PromiseAsync can also pass the return value and exception to the corresponding business processing end through the interface method named getXxx or onXxx according to the preset Promise interface, and add the corresponding monitoring module and exception to the return value or exception. processing module.
除了同步流以及异步流程之外,本发明中还可实现由两者结合起来得到的复合流程。在复合流程中,通过PromiseResult和PromiseAsync分别实现对应流程,并采用统一的Promise接口完成数据交互。具体流程以及数据交互形式与前文实施例类似,此处不另赘述。In addition to the synchronous flow and the asynchronous flow, the present invention can also implement a composite flow obtained by combining the two. In the composite process, the corresponding process is realized through PromiseResult and PromiseAsync respectively, and the unified Promise interface is used to complete the data interaction. The specific process and the data interaction form are similar to those in the foregoing embodiment, and are not described herein again.
本发明实施例中,Promise接口提供了用于获取执行情况的监听方法以及处理方法。PromiseResult和PromiseAsync均实现Promise接口,业务处理逻辑可通过该Promise接口调用。其中,Promise接口的监听方法包括但不限于Listener、SuccessListener、FailureListener。Listener是一般监听模式(包含对成功以及失败两种情况的监听),而SuccessListener和FailureListener可以理解为Listener在不同情况下的分支模式。也即SuccessListener表示对成功情况的监听模式,FailureListener表示对失败情况的监听模式,这两种模式分别用于触发任务成功和失败(如出现异常)情况下的处理流程。In this embodiment of the present invention, the Promise interface provides a monitoring method and a processing method for obtaining the execution status. Both PromiseResult and PromiseAsync implement the Promise interface, and business processing logic can be invoked through the Promise interface. The monitoring methods of the Promise interface include but are not limited to Listener, SuccessListener, and FailureListener. Listener is a general listening mode (including monitoring of success and failure), while SuccessListener and FailureListener can be understood as branch modes of Listener in different situations. That is, SuccessListener represents the monitoring mode for success, and FailureListener represents the monitoring mode for failure. These two modes are used to trigger the processing flow in case of task success and failure (such as exception).
Promise接口的处理方法包括但不限于Mapper、SuccessMapper、FailureMapper、FlatMapper、SuccessFlatMapper、FailureFlatMapper。这些方法会在被监听的Promise代理对象上注册监听器,从而等待Promise代理对象成功或失败时回调执行对应的监听器。其中,Success前缀的方法表示对任务成功时返回值的监听或处理,Failure前缀的方法表示对任务失败时异常的监听或处理,flat前缀的方法表示展平处理后返回的结果。比如,若Promise代理对象中未设置flat前缀的处理器,无法处理Promise代理对象中包装的Promise代理对象,即类似Promise<Promise<T>>这一类的嵌套结构。而通过flat前缀的处理器可以对此类嵌套结构进行展开,也即将Promise代理对象内部的值展开后传给新的Promise,得到Promise<T>的展平结构,从而将返回的Promise的值展开传递给链的下一业务处理环节中。The processing methods of the Promise interface include but are not limited to Mapper, SuccessMapper, FailureMapper, FlatMapper, SuccessFlatMapper, and FailureFlatMapper. These methods will register listeners on the monitored Promise proxy object, so that when the Promise proxy object succeeds or fails, the callback executes the corresponding listener. Among them, the method with the prefix Success indicates the monitoring or processing of the return value when the task succeeds, the method with the prefix Failure indicates the monitoring or processing of the exception when the task fails, and the method with the flat prefix indicates the result returned after flattening. For example, if a processor with no flat prefix is set in the Promise proxy object, it cannot process the Promise proxy object wrapped in the Promise proxy object, that is, a nested structure like Promise<Promise<T>>. The processor with the flat prefix can expand such nested structures, that is, expand the value inside the Promise proxy object and pass it to the new Promise to obtain the flattened structure of Promise<T>, so as to return the value of the Promise The expansion is passed to the next business processing link in the chain.
针对相关技术中的热更问题,在本发明的一实施例中,对于Promise代理对象包含的回调函数未处理过的变量参数,通过回调函数中设置的可选参数以及预设映射方式获取变量参数。具体来说,在本发明实施例中,Promise组件所要使用的ofXxx工厂方法以及onXxx监听方法等都需要传入λ函数,均需要添加额外的变量参数,如Object类型的变量。由于Java中λ的缺陷,线上热更新时不能使用当前λ函数中未曾捕获过的变量参数,因此,本发明实施例中可以通过预设映射方式如k-v形式传入变量参数,并在λ函数内部通过λ函数的ctx参数取得传入的变量参数,以避免热更新限制。In view of the hot update problem in the related art, in an embodiment of the present invention, for the variable parameters that are not processed by the callback function contained in the Promise proxy object, the variable parameters are obtained through the optional parameters set in the callback function and the preset mapping method. . Specifically, in the embodiment of the present invention, the ofXxx factory method and the onXxx monitoring method to be used by the Promise component all need to pass in the λ function, and additional variable parameters, such as variables of type Object, need to be added. Due to the defect of λ in Java, the variable parameters that have not been captured in the current λ function cannot be used during online hot update. Therefore, in the embodiment of the present invention, the variable parameters can be passed in through a preset mapping method such as k-v form, and the λ function Internally, the incoming variable parameters are obtained through the ctx parameter of the λ function to avoid hot update restrictions.
相关技术中,Promise会捕获这些异常包装为任务失败状态向链后传递,如果没对任务失败的情况添加相应的监听器(如FailureListener、Mapper),异常信息容易被隐藏吞没,不利于及时处理业务中的异常。In related technologies, Promise will capture these exceptions and package them as task failure status and transmit them to the back of the chain. If no corresponding listeners (such as FailureListener and Mapper) are added to the task failure, the exception information is easily hidden and engulfed, which is not conducive to timely processing of business. exception in .
为此,本发明的一实施例中,还提供了一种异常逃逸机制。实际应用中,可能很多场景下难以处理异步流程中产生的未预期异常,因而,针对未添加监听处理的失败任务,需要追加异常逃逸的检测机制。具体来说,假设组合后的数据处理结果包括串行化处理的多个数据处理结果。基于此,若串行化处理的多个数据处理结果中包括异常值,并且异常值处于Promise链末尾,则确定异常值是否被处理;输出未被处理的异常值以及对应的堆栈信息。To this end, in an embodiment of the present invention, an exception escape mechanism is also provided. In practical applications, it may be difficult to handle unexpected exceptions generated in asynchronous processes in many scenarios. Therefore, for failed tasks without added monitoring processing, an exception escape detection mechanism needs to be added. Specifically, it is assumed that the combined data processing result includes a plurality of serialized processing results. Based on this, if the multiple data processing results of the serialization process include an abnormal value, and the abnormal value is at the end of the Promise chain, it is determined whether the abnormal value is processed; the unprocessed abnormal value and the corresponding stack information are output.
简单来说,每个Promise代理对象的异常在传入监听器或处理器时都会设置已处理标记,未被标记说明则该Promise代理对象没有相应的监听器或处理器。如果一个异常已经传递到Promise链的末端仍未被处理,将引发异常逃逸的错误,此情况下需要打印出逃逸的异常信息与堆栈。Simply put, the exception of each Promise proxy object will be set with a processed flag when it is passed to a listener or handler. If it is not marked, the Promise proxy object does not have a corresponding listener or handler. If an exception has been passed to the end of the Promise chain and has not been handled, an exception escape error will be raised, in which case the escaped exception information and stack should be printed.
通过图1示出的业务处理方法,能够实现与线程/协程的微任务解耦,大大简化后端业务逻辑,避免新增业务处理逻辑对后端业务系统框架的侵入,便于在后端业务系统中添加各种业务处理逻辑,提升后端业务系统的灵活性。Through the business processing method shown in Figure 1, the micro-task decoupling from threads/coroutines can be realized, which greatly simplifies the back-end business logic, avoids the intrusion of new business processing logic into the back-end business system framework, and facilitates the back-end business Various business processing logics are added to the system to improve the flexibility of the back-end business system.
以下将详细描述本发明的一个或多个实施例的业务处理装置。本领域技术人员可以理解,这些业务处理装置均可使用市售的硬件组件通过本方案所教导的步骤进行配置来构成。The service processing apparatus of one or more embodiments of the present invention will be described in detail below. Those skilled in the art can understand that these service processing apparatuses can be configured by using commercially available hardware components through the steps taught in this solution.
图2为本发明实施例提供的一种业务处理装置的结构示意图。该装置应用于各种显示界面,如图2所示,该业务处理装置包括:FIG. 2 is a schematic structural diagram of a service processing apparatus according to an embodiment of the present invention. The device is applied to various display interfaces. As shown in Figure 2, the service processing device includes:
请求模块11,用于响应于本地业务触发的远程处理任务,向执行所述远程处理任务的多个服务端分别发送远程调用请求,每个远程调用请求中包含与相应服务端对应的待处理数据;The
生成模块12,用于生成所述多个远程调用请求对应的多个Promise代理对象,并组合所述多个Promise代理对象以得到目标Promise对象;A
设置模块13,用于在所述目标Promise对象上设置监听器;Setting
传入模块14,用于通过所述多个Promise代理对象分别接收所述多个服务端基于所述待处理数据得到的数据处理结果,并将接收到的数据处理结果传入所述目标Promise对象;The
传递模块15,用于通过所述目标Promise对象将组合后的数据处理结果传递给所述监听器,以使得所述本地业务通过所述监听器获取到所述组合后的数据处理结果。The
可选地,还包括回调模块,用于通过Promise代理对象中包含的回调函数接收所述异步处理任务的执行状态。Optionally, a callback module is also included, configured to receive the execution status of the asynchronous processing task through the callback function contained in the Promise proxy object.
可选地,所述回调函数接口为λ函数。所述回调模块具体用于:通过调用setSuccesss方法或setFailure方法传入所述λ函数,以接收用于指示所述异步处理任务执行状态的回调参数。Optionally, the callback function interface is a λ function. The callback module is specifically configured to: pass in the λ function by calling the setSuccesss method or the setFailure method, so as to receive a callback parameter for indicating the execution state of the asynchronous processing task.
可选地,回调模块还用于:对于调用第一回调方法的所述异步处理任务,若所述多个服务端中任一服务器返回的执行状态为成功,则确定所述异步处理任务完成。对于调用第二回调方法的所述异步处理任务,若所述多个服务端中所有服务器返回的执行状态均为成功,则确定所述异步处理任务完成。Optionally, the callback module is further configured to: for the asynchronous processing task that calls the first callback method, if the execution status returned by any one of the multiple servers is successful, determine that the asynchronous processing task is completed. For the asynchronous processing task that calls the second callback method, if the execution status returned by all the servers in the multiple servers is successful, it is determined that the asynchronous processing task is completed.
可选地,所述传入模块14通过所述多个Promise代理对象分别接收所述多个服务端基于所述待处理数据得到的数据处理结果的过程中,具体用于:对于所述多个Promise代理对象中的每一Promise代理对象,通过所述每一Promise代理对象中包含的数据处理接口,调用预设的数据返回方法获取所述多个服务端的数据处理结果。Optionally, in the process of respectively receiving the data processing results obtained by the multiple servers based on the data to be processed through the multiple Promise proxy objects, the
其中,所述多个Promise代理对象包括面向同步流程的第一Promise代理对象和/或面向异步流程的第二Promise代理对象,所述数据处理结果包括所述多个服务端各自对应的返回值和/或异常值。Wherein, the multiple Promise proxy objects include a first Promise proxy object oriented to a synchronous process and/or a second Promise proxy object oriented to an asynchronous process, and the data processing result includes the corresponding return values of the multiple servers and / or outliers.
可选地,所述第一Promise代理对象对应的数据返回方法包括工厂方法,所述工厂方法用于从服务端获取Param数据类型的返回值和/或异常值。Optionally, the data return method corresponding to the first Promise proxy object includes a factory method, and the factory method is used to obtain the return value and/or the abnormal value of the Param data type from the server.
可选地,所述请求模块11具体用于:对所述远程处理任务中的多个待处理数据进行串行化处理,并将串行化处理后的所述多个待处理数据封装到所述远程调用请求中;向所述多个服务端分别发送所述远程调用请求。Optionally, the
可选地,所述组合后的数据处理结果包括串行化处理的多个数据处理结果。Optionally, the combined data processing result includes multiple serialized data processing results.
所述装置还包括异常逃逸模块,用于若所述串行化处理的多个数据处理结果中包括异常值,并且所述异常值处于Promise链末尾,则确定所述异常值是否被处理;输出未被处理的所述异常值以及对应的堆栈信息。The device further includes an exception escape module, configured to determine whether the abnormal value is processed if the multiple data processing results of the serialization process include an abnormal value, and the abnormal value is at the end of the Promise chain; outputting The unhandled exception value and the corresponding stack information.
可选地,所述装置还包括热更模块,用于对于Promise代理对象包含的回调函数未处理过的变量参数,通过所述回调函数中设置的可选参数以及预设映射方式获取所述变量参数。Optionally, the device further includes a hot-replacement module, which is used to obtain the variable parameters that have not been processed by the callback function contained in the Promise proxy object through optional parameters set in the callback function and a preset mapping method. parameter.
可选地,所述装置还包括超时竞争模块,用于通过第一回调方法添加与Promise代理对象构成竞争关系的超时Promise对象;若所述Promise代理对象的返回时间早于所述超时Promise对象的返回时间,则向所述监听器传递所述Promise代理对象的返回值;若所述超时Promise对象的返回时间早于所述Promise代理对象的返回时间,则确定所述Promise代理对象竞争失败,并向所述监听器传递所述Promise代理对象存在超时异常。Optionally, the device further includes a timeout competition module for adding a timeout Promise object that forms a competitive relationship with the Promise proxy object through the first callback method; if the return time of the Promise proxy object is earlier than the timeout of the timeout Promise object. If the return time of the Promise proxy object is earlier than the return time of the Promise proxy object, it is determined that the Promise proxy object has failed to compete, and There is a timeout exception in passing the Promise proxy object to the listener.
图2所示业务处理装置可以执行前述各实施例中提供的方法,本实施例未详细描述的部分,可参考前述实施例的相关说明,在此不再赘述。The service processing apparatus shown in FIG. 2 may execute the methods provided in the foregoing embodiments. For parts not described in detail in this embodiment, reference may be made to the relevant descriptions of the foregoing embodiments, and details are not described herein again.
在一个可能的设计中,上述图2所示的业务处理装置的结构可实现为一电子设备。In a possible design, the structure of the service processing apparatus shown in FIG. 2 can be implemented as an electronic device.
如图3所示,该电子设备可以包括:处理器21、存储器22。其中,所述存储器22上存储有可执行代码,当所述可执行代码被所述处理器21执行时,至少使所述处理器21可以实现如前述实施例中提供的业务处理方法。其中,该电子设备的结构中还可以包括通信接口23,用于与其他设备或通信网络通信。As shown in FIG. 3 , the electronic device may include: a
另外,本发明实施例提供了一种非暂时性机器可读存储介质,所述非暂时性机器可读存储介质上存储有可执行代码,当所述可执行代码被无线路由器的处理器执行时,使所述处理器执行前述各实施例中提供的业务处理方法。In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, where executable codes are stored on the non-transitory machine-readable storage medium, and when the executable codes are executed by a processor of a wireless router , causing the processor to execute the service processing methods provided in the foregoing embodiments.
根据需要,本发明各实施例的系统、方法和装置可以实现为纯粹的软件(例如用Java来编写的软件程序),也可以根据需要实现为纯粹的硬件(例如专用ASIC芯片或FPGA芯片),还可以实现为结合了软件和硬件的系统(例如存储有固定代码的固件系统或者带有通用存储器和处理器的系统)。As required, the systems, methods and apparatuses of the embodiments of the present invention can be implemented as pure software (for example, a software program written in Java), or can be implemented as pure hardware (for example, a dedicated ASIC chip or FPGA chip) as required, It can also be implemented as a system that combines software and hardware (eg, a firmware system with fixed code stored or a system with a general-purpose memory and processor).
本发明的另一个方面是一种计算机可读介质,其上存储有计算机可读指令,所述指令被执行时可实施本发明各实施例的方法。Another aspect of the present invention is a computer-readable medium having computer-readable instructions stored thereon that, when executed, implement the methods of various embodiments of the present invention.
以上已经描述了本发明的各实施例,上述说明是示例性的,并非穷尽性的,并且也不限于所公开的各实施例。在不偏离所说明的各实施例的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。要求保护的主题的范围仅由所附的权利要求进行限定。Various embodiments of the present invention have been described above, and the foregoing descriptions are exemplary, not exhaustive, and not limiting of the disclosed embodiments. Numerous modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The scope of the claimed subject matter is limited only by the appended claims.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111672809.5ACN114553928B (en) | 2021-12-31 | 2021-12-31 | A business processing method and device, electronic equipment, and medium |
| CN202410341219.1ACN118433234A (en) | 2021-12-31 | 2021-12-31 | Service processing method and device, electronic equipment and medium |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111672809.5ACN114553928B (en) | 2021-12-31 | 2021-12-31 | A business processing method and device, electronic equipment, and medium |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410341219.1ADivisionCN118433234A (en) | 2021-12-31 | 2021-12-31 | Service processing method and device, electronic equipment and medium |
| Publication Number | Publication Date |
|---|---|
| CN114553928Atrue CN114553928A (en) | 2022-05-27 |
| CN114553928B CN114553928B (en) | 2024-04-16 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202111672809.5AActiveCN114553928B (en) | 2021-12-31 | 2021-12-31 | A business processing method and device, electronic equipment, and medium |
| CN202410341219.1APendingCN118433234A (en) | 2021-12-31 | 2021-12-31 | Service processing method and device, electronic equipment and medium |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410341219.1APendingCN118433234A (en) | 2021-12-31 | 2021-12-31 | Service processing method and device, electronic equipment and medium |
| Country | Link |
|---|---|
| CN (2) | CN114553928B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117978907A (en)* | 2022-10-26 | 2024-05-03 | 荣耀终端有限公司 | Data processing method, electronic device and medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20140245134A1 (en)* | 2013-02-25 | 2014-08-28 | Microsoft Corporation | Remotable contracts for the web |
| CN106888218A (en)* | 2017-04-01 | 2017-06-23 | 网易(杭州)网络有限公司 | Message treatment method, device, client and service end |
| CN109815025A (en)* | 2018-12-17 | 2019-05-28 | 顺丰科技有限公司 | Business model call method, device and storage medium |
| CN110457142A (en)* | 2019-07-10 | 2019-11-15 | 阿里巴巴集团控股有限公司 | Method for processing business, system, computer room, framework and electronic equipment |
| US20200007659A1 (en)* | 2013-09-13 | 2020-01-02 | John Wason | System and method for implementing augmented object members for remote procedure call |
| CN111447262A (en)* | 2020-03-23 | 2020-07-24 | 北京达佳互联信息技术有限公司 | Request sending method, client and storage medium |
| CN112788104A (en)* | 2020-12-25 | 2021-05-11 | 珠海金山网络游戏科技有限公司 | Remote procedure calling method and device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20140245134A1 (en)* | 2013-02-25 | 2014-08-28 | Microsoft Corporation | Remotable contracts for the web |
| US20200007659A1 (en)* | 2013-09-13 | 2020-01-02 | John Wason | System and method for implementing augmented object members for remote procedure call |
| CN106888218A (en)* | 2017-04-01 | 2017-06-23 | 网易(杭州)网络有限公司 | Message treatment method, device, client and service end |
| CN109815025A (en)* | 2018-12-17 | 2019-05-28 | 顺丰科技有限公司 | Business model call method, device and storage medium |
| CN110457142A (en)* | 2019-07-10 | 2019-11-15 | 阿里巴巴集团控股有限公司 | Method for processing business, system, computer room, framework and electronic equipment |
| CN111447262A (en)* | 2020-03-23 | 2020-07-24 | 北京达佳互联信息技术有限公司 | Request sending method, client and storage medium |
| CN112788104A (en)* | 2020-12-25 | 2021-05-11 | 珠海金山网络游戏科技有限公司 | Remote procedure calling method and device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117978907A (en)* | 2022-10-26 | 2024-05-03 | 荣耀终端有限公司 | Data processing method, electronic device and medium |
| Publication number | Publication date |
|---|---|
| CN114553928B (en) | 2024-04-16 |
| CN118433234A (en) | 2024-08-02 |
| Publication | Publication Date | Title |
|---|---|---|
| CN107241315B (en) | Access method, device and computer-readable storage medium for bank gateway interface | |
| CN108733496B (en) | Event processing method and device | |
| CN103595770B (en) | Method and device for achieving file downloading through SDK | |
| CN112804249A (en) | Data communication method and system for remotely calling automatic driving platform | |
| WO2021244644A1 (en) | Method for dynamically integrating application, and software system and machine therefor | |
| CN112698817B (en) | Message access method, device and system based on micro-service architecture and storage medium | |
| CN112256246A (en) | A Microservice Integration Architecture Supporting Cross-Language Calling in Power System | |
| CN111274047A (en) | Information processing method, terminal, system, computer device and storage medium | |
| CN105373563B (en) | Database switching method and device | |
| CN113835904A (en) | Remote procedure call control method, device, equipment and storage medium | |
| CN114553928B (en) | A business processing method and device, electronic equipment, and medium | |
| CN114371935B (en) | Gateway processing method, gateway, device and medium | |
| CN116028578A (en) | Block chain data synchronization method, device, electronic equipment and readable storage medium | |
| CN115378792B (en) | Alarm processing method, device and storage medium | |
| CN113259404A (en) | Industrial communication middleware based on TCP/IP protocol and use method thereof | |
| CN115114022A (en) | Method, system, device and medium for using GPU resources | |
| CN112882849A (en) | Information recommendation method, device, system, equipment and storage medium in cloud application | |
| WO2021093671A1 (en) | Task processing method, system, apparatus and device, and computer readable storage medium | |
| WO2024212598A1 (en) | Non-invasive micro-service system authority control method and system | |
| CN113259378B (en) | Operation method, device, device and storage medium of blockchain system | |
| CN113760693B (en) | Method and device for local debugging of microservice system | |
| CN115567616A (en) | Service protocol conversion method and device | |
| CN115914340A (en) | BMC communication method, system, equipment and storage medium | |
| CN115185599A (en) | Project deployment method, system and storage medium based on Golang | |
| CN114663080A (en) | Data processing method, device, equipment and medium based on blockchain system implementation |
| 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 |