简体   繁体   English

C ++:具有API的应用程序体系结构

[英]C++: Application architecture with API

My application it's C++ service. 我的应用程序是C ++服务。 And I need to add API for it. 而且我需要为其添加API。 I consider that it will be XML/JSON RPC based API. 我认为它将是基于XML / JSON RPC的API。 How should I design a program for reusing existing code base and provide API. 我应该如何设计一个程序以重用现有代码库并提供API。

I see following options: 我看到以下选项:

  1. My application will work via RPC layer. 我的应用程序将通过RPC层工作。 Seems that it's bad option due to low performance; 由于性能低下,这似乎是个不好的选择;
  2. Before starting of service I will fork it and run my application in the first process and RPC server in the second; 在开始服务之前,我会先将其派生并在第一个进程中运行我的应用程序,然后在第二个进程中运行RPC服务器。 Seems ok, but how to restart RPC server in this case? 似乎可以,但是在这种情况下如何重新启动RPC服务器?
  3. I guess there is a well known pattern for such issues. 我猜有一个众所周知的模式可以解决此类问题。

Thanks. 谢谢。

If you can use a web server, then the FastCGI concept might be what you're looking for. 如果您可以使用Web服务器,那么FastCGI概念可能就是您想要的。 One of the main duties of FastCGI is to allow you to put on a public API (from the web server) that internally calls the "real" application, in your case the resident C++ service. FastCGI的主要职责之一是允许您放置一个公共API(来自Web服务器),该API在内部调用“真实”应用程序(在您的情况下为常驻C ++服务)。 So all work is done at the web server to create the public API using any technology you wish, and little or no code changes done in your C++ service. 因此,所有工作都在Web服务器上完成,以使用您希望使用的任何技术来创建公共API,并且在C ++服务中几乎没有代码更改或根本没有代码更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM