1. Overview
1.概述
In this tutorial, we’ll understand the twelve-factor app methodology.
在本教程中,我们将了解十二要素应用方法。
We’ll also understand how to develop a microservice with the help of Spring Boot. In the process, we’ll see how to apply the twelve-factor methodology for developing such a microservice.
我们还将了解如何在Spring Boot的帮助下开发一个微服务。在这个过程中,我们将看到如何应用十二要素方法来开发这样一个微服务。
2. What Is the Twelve-Factor Methodology?
2.什么是 “十二要素法”?
The twelve-factor methodology is a set of twelve best practices to develop applications developed to run as a service. This was originally drafted by Heroku for applications deployed as services on their cloud platform, back in 2011. Over time, this has proved to be generic enough for any software-as-a-service (SaaS) development.
十二要素方法论是一套开发作为服务运行的应用程序的十二种最佳实践。这最初是由Heroku在2011年为在其云平台上作为服务部署的应用程序起草的。随着时间的推移,这已被证明足够通用于任何软件即服务(SaaS)开发。
So, what do we mean by software-as-a-service? Traditionally we design, develop, deploy, and maintain software solutions to derive business value from it. But, we don’t have to engage in this process to achieve the same result necessarily. For instance, calculating applicable tax is a generic function in many domains.
那么,我们所说的软件即服务是什么意思?传统上,我们设计、开发、部署和维护软件解决方案,从中获得商业价值。但是,我们不一定非要参与这个过程来实现同样的结果。例如,计算适用税款是许多领域的通用功能。
Now, we may decide to build and manage this service our selves or subscribe to a commercial service offering. Such service offerings are what we know as software-as-a-service.
现在,我们可以决定自己建立和管理这项服务,或者订阅商业服务产品。这种服务产品就是我们所知的软件即服务。
While software-as-a-service doesn’t impose any restriction on the architecture it’s developed on; it’s quite useful to adopt some best practices.
虽然软件即服务对其开发的架构没有任何限制,但采用一些最佳实践是相当有用的。
If we design our software to be modular, portable, and scalable on modern cloud platforms, it’s quite amenable to our service offerings. This is where the twelve-factor methodology helps in. We’ll see them in action later in the tutorial.
如果我们把我们的软件设计成模块化、可移植和可在现代云平台上扩展,它就很适合我们的服务产品。这就是十二个因素方法论的作用所在。我们将在本教程的后面看到它们的作用。
3. Microservice with Spring Boot
3.使用Spring Boot的微服务
Microservice is an architectural style to develop software as loosely coupled services. The key requirement here is that the services should be organized around business domain boundaries. This is often the most difficult part to identify.
微服务是一种将软件开发为松散耦合的服务的架构风格。这里的关键要求是,服务应围绕业务领域的边界组织。这通常是最难确定的部分。
Moreover, a service here has the sole authority over its data and exposes operations to other services. Communication between services is typically over lightweight protocols like HTTP. This results in independently deployable and scalable services.
此外,这里的服务对其数据有唯一的权限,并将操作暴露给其他服务。服务之间的通信通常是通过HTTP等轻量级协议进行的。这导致了可独立部署和可扩展的服务。
Now, microservice architecture and software-as-a-service are not dependent on each other. But, it’s not difficult to understand that, when developing software-as-a-service, leveraging the microservice architecture is quite beneficial. It helps to achieve a lot of goals we discussed earlier, like modularity and scalability.
现在,微服务架构和软件即服务并不相互依赖。但是,我们不难理解,当开发软件即服务时,利用微服务架构是相当有益的。它有助于实现我们之前讨论的很多目标,如模块化和可扩展性。
Spring Boot is an application framework based on Spring which takes away a lot of boilerplate associated with developing an enterprise application. It gives us a highly-opinionated but flexible platform to develop microservices. For this tutorial, we’ll leverage Spring Boot to deliver a microservice using the twelve-factor methodology.
Spring Boot是一个基于Spring的应用程序框架,它消除了与开发企业应用程序有关的大量模板。它为我们提供了一个高度独立的平台来开发微服务。在本教程中,我们将利用Spring Boot来提供一个使用十二要素方法的微服务。
4. Applying Twelve-Factor Methodology
4.应用十二因素法
Let’s now define a simple application that we’ll try to develop with the tools and practices we just discussed. We all love watching movies, but it’s challenging to keep track of the movies we’ve already watched.
现在让我们定义一个简单的应用程序,我们将尝试用我们刚才讨论的工具和实践来开发。我们都喜欢看电影,但要跟踪我们已经看过的电影是很有挑战性的。
Now, who would like to start a movie and then abandon it later? What we need is a simple service to record and query movies that we’ve watched:
现在,谁会喜欢开始看电影,然后又放弃它呢?我们需要的是一个简单的服务来记录和查询我们看过的电影:
This is quite a simple and standard microservice with a data store and REST endpoints. We need to define a model which will map to persistence as well:
这是一个相当简单和标准的微服务,有一个数据存储和REST端点。我们需要定义一个模型,它也会映射到持久化。
@Entity
public class Movie {
@Id
private Long id;
private String title;
private String year;
private String rating;
// getters and setters
}
We’ve defined a JPA entity with an id and a few other attributes. Let’s now see what the REST controller looks like:
我们已经定义了一个带有id和其他一些属性的JPA实体。现在让我们看看REST控制器是什么样子的。
@RestController
public class MovieController {
@Autowired
private MovieRepository movieRepository;
@GetMapping("/movies")
public List<Movie> retrieveAllStudents() {
return movieRepository.findAll();
}
@GetMapping("/movies/{id}")
public Movie retrieveStudent(@PathVariable Long id) {
return movieRepository.findById(id).get();
}
@PostMapping("/movies")
public Long createStudent(@RequestBody Movie movie) {
return movieRepository.save(movie).getId();
}
}
This covers the base of our simple service. We’ll go through the rest of the application as we discuss how we implement the twelve-factor methodology in the following subsections.
这涵盖了我们简单服务的基础。我们将在下面的小节中讨论如何实现十二个因素的方法论,从而完成应用程序的其余部分。
4.1. Codebase
4.1.代码库
The first best practice of twelve-factor apps is to track it in a version control system. Git is the most popular version control system in use today and is almost ubiquitous. The principle states that an app should be tracked in a single code repository and must not share that repository with any other apps.
十二要素应用程序的第一个最佳实践是在版本控制系统中进行跟踪。Git是目前最流行的版本控制系统,几乎无处不在。该原则规定,一个应用程序应在一个单一的代码库中进行跟踪,并且不得与任何其他应用程序共享该代码库。
Spring Boot offers many convenient ways to bootstrap an application, including a command-line tool and a web interface. Once we generate the bootstrap application, we can convert this into a git repository:
Spring Boot提供了许多方便的方法来引导应用程序,包括一个命令行工具和一个Web界面。一旦我们生成了引导应用程序,我们就可以将其转换为git仓库。
git init
This command should be run from the root of the application. The application at this stage already contains a .gitignore file which effectively restricts generated files from being version-controlled. So, we can straight away create an initial commit:
这个命令应该从应用程序的根部运行。在这个阶段,应用程序已经包含了一个.gitignore文件,它有效地限制了生成的文件受版本控制。因此,我们可以直接创建一个初始提交。
git add .
git commit -m "Adding the bootstrap of the application."
Finally, we can add a remote and push our commits to the remote if we wish to (this is not a strict requirement):
最后,我们可以添加一个远程,如果我们愿意,可以把我们的提交推送到远程(这不是一个严格的要求)。
git remote add origin https://github.com/<username>/12-factor-app.git
git push -u origin master
4.2. Dependencies
依赖性
Next, the twelve-factor app should always explicitly declare all its dependencies. We should do this using a dependency declaration manifest. Java has multiple dependency management tools like Maven and Gradle. We can use one of them to achieve this goal.
接下来,十二因素应用程序应始终明确声明其所有的依赖关系。我们应该使用依赖性声明清单来做到这一点。Java有多种依赖性管理工具,如Maven和Gradle。我们可以使用其中之一来实现这一目标。
So, our simple application depends on a few external libraries, like a library to facilitate REST APIs and to connect to a database. Let’s see how can we declaratively define them using Maven.
因此,我们的简单应用需要依赖一些外部库,比如促进REST APIs和连接数据库的库。让我们看看如何用Maven声明性地定义它们。
Maven requires us to describe a project’s dependencies in an XML file, typically known as Project Object Model (POM):
Maven要求我们在一个XML文件中描述项目的依赖关系,通常被称为项目对象模型(POM)。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
Although this looks plain and simple, these dependencies usually have other transitive dependencies. This complicates it to an extent but helps us achieve our goal. Now, our application doesn’t have a direct dependency which is not explicitly described.
虽然这看起来简单明了,但这些依赖关系通常还有其他横向的依赖关系。这在一定程度上使其复杂化,但有助于我们实现我们的目标。现在,我们的应用程序没有直接的依赖关系,这一点没有明确的描述。
4.3. Configurations
4.3.配置
An application typically has lots of configuration, some of which may vary between deployments while others remain the same.
一个应用程序通常有很多配置,其中一些配置在不同的部署中可能有所不同,而另一些则保持不变。
In our example, we’ve got a persistent database. We’ll need the address and credentials of the database to connect to. This is most likely to change between deployments.
在我们的例子中,我们有一个持久的数据库。我们需要连接到数据库的地址和凭证。这很可能在不同的部署之间发生变化。
A twelve-factor app should externalize all such configurations that vary between deployments. The recommendation here is to use environment variables for such configurations. This leads to a clean separation of config and code.
一个十二因素的应用程序应该将所有这些在不同部署中不同的配置外部化。这里的建议是为这些配置使用环境变量。这将导致配置和代码的干净分离。
Spring provides a configuration file where we can declare such configurations and attach it to environment variables:
Spring提供了一个配置文件,我们可以在其中声明这样的配置并将其附加到环境变量上。
spring.datasource.url=jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/movies
spring.datasource.username=${MYSQL_USER}
spring.datasource.password=${MYSQL_PASSWORD}
Here, we’ve defined the database URL and credentials as configurations and have mapped the actual values to be picked from the environment variable.
在这里,我们将数据库的URL和证书定义为配置,并将实际值映射到环境变量中去。
On Windows, we can set the environment variable before starting the application:
在Windows上,我们可以在启动应用程序之前设置环境变量。
set MYSQL_HOST=localhost
set MYSQL_PORT=3306
set MYSQL_USER=movies
set MYSQL_PASSWORD=password
We can use a configuration management tool like Ansible or Chef to automate this process.
我们可以使用像Ansible或Chef这样的配置管理工具来实现这一过程的自动化。
4.4. Backing Services
4.4.后援服务
Backing services are services that the application depends on for operation. For instance a database or a message broker. A twelve-factor app should treat all such backing services as attached resources. What this effectively means is that it shouldn’t require any code change to swap a compatible backing service. The only change should be in configurations.
后援服务是应用程序依赖的操作服务。例如,数据库或消息代理。十二因素应用程序应将所有此类支持服务视为附加资源。这实际上意味着,不应要求对代码进行任何更改以交换兼容的支持服务。唯一的变化应该是在配置方面。
In our application, we’ve used MySQL as the backing service to provide persistence.
在我们的应用程序中,我们使用MySQL作为支持服务来提供持久性。
Spring JPA makes the code quite agnostic to the actual database provider. We only need to define a repository which provides all standard operations:
Spring JPA使得代码与实际的数据库提供者无关。我们只需要定义一个提供所有标准操作的存储库。
@Repository
public interface MovieRepository extends JpaRepository<Movie, Long> {
}
As we can see, this is not dependent on MySQL directly. Spring detects the MySQL driver on the classpath and provides a MySQL-specific implementation of this interface dynamically. Moreover, it pulls other details from configurations directly.
我们可以看到,这并不直接依赖于MySQL。Spring会检测classpath上的MySQL驱动,并动态地提供该接口的MySQL特定实现。此外,它还直接从配置中提取其他细节。
So, if we’ve to change from MySQL to Oracle, all we’ve to do is replace the driver in our dependencies and replace the configurations.
因此,如果我们要从MySQL改为Oracle,我们所要做的就是在我们的依赖中替换驱动程序,并替换配置。
4.5. Build, Release and Run
4.5.构建、发布和运行
The twelve-factor methodology strictly separates the process of converting codebase into a running application as three distinct stages:
这十二个因素的方法论将代码库转换为运行中的应用程序的过程严格地分为三个不同的阶段。
- Build Stage: This is where we take the codebase, perform static and dynamic checks, and then generate an executable bundle like a JAR. Using a tool like Maven, this is quite trivial:
mvn clean compile test package
- Release Stage: This is the stage where we take the executable bundle and combine this with the right configurations. Here, we can use Packer with a provisioner like Ansible to create Docker images:
packer build application.json
- Run Stage: Finally, this is the stage where we run the application in a target execution environment. If we use Docker as the container to release our application, running the application can be simple enough:
docker run --name <container_id> -it <image_id>
Finally, we don’t necessarily have to perform these stages manually. This is where Jenkins comes in as pretty handy with their declarative pipeline.
最后,我们不一定要手动执行这些阶段。这就是Jenkins的声明式管道相当方便的地方。
4.6. Processes
4.6.过程
A twelve-factor app is expected to run in an execution environment as stateless processes. In other words, they can not store persistent state locally between requests. They may generate persistent data which is required to be stored in one or more stateful backing services.
十二因素应用程序预计将作为无状态进程在执行环境中运行。换句话说,它们不能在请求之间在本地存储持久性状态。它们可能会产生持久性数据,这些数据需要存储在一个或多个有状态的备份服务中。
In the case of our example, we’ve got multiple endpoints exposed. A request on any of these endpoints is entirely independent of any request made before it. For instance, if we keep track of user requests in-memory and use that information to serve future requests, it violates a twelve-factor app.
在我们的例子中,我们有多个暴露的端点。任何一个端点的请求都是完全独立于之前的任何请求的。例如,如果我们在内存中跟踪用户的请求,并使用这些信息为未来的请求提供服务,这就违反了12个因素的应用程序。
Hence, a twelve-factor app imposes no such restriction like sticky sessions. This makes such an app highly portable and scalable. In a cloud execution environment offering automated scaling, it’s quite a desirable behavior from applications.
因此,12个因素的应用程序没有像粘性会话那样的限制。这使得这样一个应用程序具有高度的可移植性和可扩展性。在一个提供自动扩展的云执行环境中,这是一个相当理想的应用程序行为。
4.7. Port Binding
4.7.端口绑定
A traditional web application in Java is developed as a WAR or web archive. This is typically a collection of Servlets with dependencies, and it expects a conformant container runtime like Tomcat. A twelve-factor app, on the contrary, expects no such runtime dependency. It’s completely self-contained and only requires an execution runtime like Java.
传统的Java网络应用是以WAR或网络档案的形式开发的。这通常是带有依赖关系的Servlet的集合,它期望有一个符合要求的容器运行时,如Tomcat。相反,一个12因素的应用程序不期望有这样的运行时依赖关系。它是完全独立的,只需要一个像Java一样的执行运行时。
In our case, we’ve developed an application using Spring Boot. Spring Boot, apart from many other benefits, provides us with a default embedded application server. Hence, the JAR we generated earlier using Maven is fully capable of executing in any environment just by having a compatible Java runtime:
在我们的案例中,我们使用Spring Boot开发了一个应用程序。Spring Boot除了有很多其他好处外,还为我们提供了一个默认的嵌入式应用服务器。因此,我们之前用Maven生成的JAR完全可以在任何环境下执行,只需拥有一个兼容的Java运行时即可。
java -jar application.jar
Here, our simple application exposes its endpoints over an HTTP binding to a specific port like 8080. Upon starting the application as we did above, it should be possible to access the exported services like HTTP.
在这里,我们的简单应用通过HTTP绑定向一个特定的端口(如8080)暴露其端点。像上面那样启动应用程序后,应该可以访问像HTTP这样的输出服务。
An application may export multiple services like FTP or WebSocket by binding to multiple ports.
一个应用程序可以通过与多个端口绑定来输出多个服务,如FTP或WebSocket。
4.8. Concurrency
4.8.并发
Java offers Thread as a classical model to handle concurrency in an application. Threads are like lightweight processes and represent multiple paths of execution in a program. Threads are powerful but have limitations in terms of how much it can help an application scale.
Java提供了Thread作为一个经典的模型来处理应用程序中的并发性。线程就像轻量级进程,代表了程序中的多条执行路径。线程的功能很强大,但在帮助应用程序扩展的程度上也有局限性。
The twelve-factor methodology suggests apps to rely on processes for scaling. What this effectively means is that applications should be designed to distribute workload across multiple processes. Individual processes are, however, free to leverage a concurrency model like Thread internally.
十二要素方法论建议应用程序依靠进程进行扩展。这实际上意味着应用程序应被设计为在多个进程中分配工作负载。然而,单个进程可以自由地在内部利用Thread等并发模型。
A Java application, when launched gets a single process which is bound to the underlying JVM. What we effectively need is a way to launch multiple instances of the application with intelligent load distribution between them. Since we’ve already packaged our application as a Docker container, Kubernetes is a natural choice for such orchestration.
一个Java应用程序在启动时得到一个与底层JVM绑定的单一进程。我们实际上需要的是一种启动应用程序的多个实例并在它们之间进行智能负载分配的方法。由于我们已经将应用程序打包成Docker容器,因此Kubernetes是进行此类协调的自然选择。
4.9. Disposability
4.9.可支配性
Application processes can be shut down on purpose or through an unexpected event. In either case, a twelve-factor app is supposed to handle it gracefully. In other words, an application process should be completely disposable without any unwanted side-effects. Moreover, processes should start quickly
应用程序进程可能是故意关闭的,也可能是通过一个意外事件关闭的。在这两种情况下,十二因素应用程序应该优雅地处理它。换句话说,一个应用进程应该是完全可抛弃的,没有任何不必要的副作用。此外,进程应快速启动
For instance, in our application, one of the endpoints is to create a new database record for a movie. Now, an application handling such a request may crash unexpectedly. This should, however, not impact the state of the application. When a client sends the same request again, it shouldn’t result in duplicate records.
例如,在我们的应用程序中,其中一个端点是为一部电影创建一个新的数据库记录。现在,处理这样一个请求的应用程序可能会意外地崩溃。然而,这不应该影响应用程序的状态。当客户端再次发送相同的请求时,不应该导致重复的记录。
In summary, the application should expose idempotent services. This is another very desirable attribute of a service destined for cloud deployments. This gives the flexibility to stop, move, or spin new services at any time without any other considerations.
总之,应用程序应该暴露idempotent服务。这是注定用于云部署的服务的另一个非常理想的属性。这使得人们可以在任何时候灵活地停止、移动或旋转新的服务,而无需考虑其他因素。
4.10. Dev/Prod Parity
4.10.发展/发展平价
It’s typical for applications to be developed on local machines, tested on some other environments and finally deployed to production. It’s often the case where these environments are different. For instance, the development team works on Windows machines whereas production deployment happens on Linux machines.
典型的情况是,应用程序在本地机器上开发,在其他一些环境中测试,最后部署到生产中。通常情况下,这些环境是不同的。例如,开发团队在Windows机器上工作,而生产部署发生在Linux机器上。
The twelve-factor methodology suggests keeping the gap between development and production environment as minimal as possible. These gaps can result from long development cycles, different teams involved, or different technology stack in use.
十二要素方法论建议尽可能地保持开发和生产环境之间的差距。这些差距可能是由漫长的开发周期、参与的不同团队或使用的不同技术栈造成的。
Now, technology like Spring Boot and Docker automatically bridge this gap to a great extent. A containerized application is expected to behave the same, no matter where we run it. We must use the same backing services – like the database – as well.
现在,Spring Boot和Docker等技术在很大程度上自动弥合了这一差距。一个容器化的应用程序被期望表现得相同,无论我们在哪里运行它。我们必须使用相同的支持服务–比如数据库–也是如此。
Moreover, we should have the right processes like continuous integration and delivery to facilitate bridging this gap further.
此外,我们应该有正确的流程,如持续集成和交付,以促进进一步弥合这一差距。
4.11. Logs
4.11. 日志
Logs are essential data that an application generates during its lifetime. They provide invaluable insights into the working of the application. Typically an application can generate logs at multiple levels with varying details and output ii in multiple different formats.
日志是一个应用程序在其生命周期内产生的重要数据。它们为应用程序的工作提供了宝贵的洞察力。通常情况下,一个应用程序可以在多个层面产生不同细节的日志,并以多种不同的格式输出。
A twelve-factor app, however, separates itself from log generation and its processing. For such an app, logs are nothing but a time-ordered stream of events. It merely writes these events to the standard output of the execution environment. The capture, storage, curation, and archival of such stream should be handled by the execution environment.
然而,一个十二个因素的应用程序将自己与日志生成及其处理分开。对于这样的应用程序,日志只不过是一个有时间顺序的事件流。它只是将这些事件写到执行环境的标准输出。这种流的捕获、存储、整理和归档应该由执行环境来处理。
There are quite several tools available to us for this purpose. To begin with, we can use SLF4J to handle logging abstractly within our application. Moreover, we can use a tool like Fluentd to collect the stream of logs from applications and backing services.
有相当多的工具可供我们用于这一目的。首先,我们可以使用SLF4J来抽象地处理我们应用程序中的日志。此外,我们可以使用像Fluentd这样的工具来收集来自应用程序和支持服务的日志流。
This we can feed into Elasticsearch for storage and indexing. Finally, we can generate meaningful dashboards for visualization in Kibana.
我们可以将其送入Elasticsearch进行存储和索引。最后,我们可以在Kibana中生成有意义的仪表盘进行可视化。
4.12. Admin Processes
4.12.行政程序
Often we need to perform some one-off tasks or routine procedure with our application state. For instance, fixing bad records. Now, there are various ways in which we can achieve this. Since we may not often require it, we can write a small script to run it separately from another environment.
通常我们需要对我们的应用程序状态执行一些一次性的任务或常规程序。例如,修复不良记录。现在,我们有各种方法来实现这个目标。由于我们可能不经常需要,我们可以写一个小脚本,从另一个环境中单独运行它。
Now, the twelve-factor methodology strongly suggests keeping such admin scripts together with the application codebase. In doing so, it should follow the same principles as we apply to the main application codebase. It’s also advisable to use a built-in REPL tool of the execution environment to run such scripts on production servers.
现在,十二要素方法论强烈建议将此类管理脚本与应用程序代码库放在一起。在这样做的时候,它应该遵循与我们适用于主应用程序代码库的相同原则。此外,建议使用执行环境的内置REPL工具,在生产服务器上运行此类脚本。
In our example, how do we seed our application with the already watched movies so far? While we can use our sweet little endpoint, but that may seem to be impractical. What we need is a script to perform a one-time load. We can write a small Java function to read a list of movies from a file and save them in batch into the database.
在我们的例子中,我们如何用到目前为止已经看过的电影作为我们应用程序的种子?虽然我们可以使用我们可爱的小端点,但这似乎是不切实际的。我们需要的是一个脚本来进行一次性的加载。我们可以写一个小的Java函数,从文件中读取一个电影列表,并将它们批量保存到数据库中。
Moreover, we can use Groovy integrated with Java runtime to start such processes.
此外,我们可以使用与Java集成的Groovy运行时来启动此类进程。
5. Practical Applications
5.实际应用
So, now we’ve seen all the factors suggested by the twelve-factor methodology. Developing an application to be a twelve-factor app certainly has its benefits, especially when we wish to deploy them as services on the cloud. But, like all other guidelines, framework, patterns, we must ask, is this a silver bullet?
所以,现在我们已经看到了十二要素方法论所建议的所有因素。将应用程序开发成十二要素应用程序当然有其好处,特别是当我们希望将它们作为服务部署在云端时。但是,就像所有其他准则、框架、模式一样,我们必须问,这是不是银弹?
Honestly, no single methodology in software design and development claim to be a silver bullet. The twelve-factor methodology is no exception. While some of these factors are quite intuitive, and most likely we’re already doing them, others may not apply to us. It’s essential to evaluate these factors in the backdrop of our objectives and then choose wisely.
老实说,在软件设计和开发中,没有任何一种方法论声称是银弹。十二个因素的方法论也不例外。虽然其中一些因素非常直观,而且很可能我们已经在做了,但其他因素可能对我们不适用。必须在我们的目标背景下评估这些因素,然后做出明智的选择。
It’s important to note that all these factors are there to help us develop an application which is modular, independent, portable, scalable, and observable. Depending upon the application, we may be able to achieve them through other means better. It’s also not necessary to adopt all the factors together, adopting even some of these may make us better than we were.
需要注意的是,所有这些因素都是为了帮助我们开发一个模块化、独立、可移植、可扩展和可观察的应用程序。根据不同的应用,我们可能会通过其他手段更好地实现它们。也没有必要把所有的因素都一起采用,即使采用其中的一些因素也可能使我们比原来更好。
Finally, these factors are quite simple and elegant. They hold greater importance in an age where we demand our applications to have higher throughput and lower latency with virtually no downtime and failure. Adopting these factors gives us the right start from the beginning. Combined with microservice architecture and containerization of applications, they just seem to hit the right spot.
最后,这些因素是相当简单和优雅的。在这个时代,我们要求我们的应用程序具有更高的吞吐量和更低的延迟,并且几乎没有停机和故障,因此它们具有更大的重要性。采用这些因素让我们从一开始就有一个正确的起点。结合微服务架构和应用程序的容器化,它们似乎正好击中了要害。
6. Conclusion
6.结语
In this tutorial, we went through the concepts of twelve-factor methodology. We discussed how to leverage a microservice architecture with Spring Boot to deliver them effectively. Further, we explored each factor in detail and how to apply them to our application. We also explored several tools to apply these individual factors in an effective manner successfully.
在本教程中,我们了解了十二要素方法论的概念。我们讨论了如何利用Spring Boot的微服务架构来有效提供这些服务。此外,我们详细探讨了每个因素,以及如何将它们应用于我们的应用程序。我们还探讨了几个工具,以有效的方式成功应用这些单个因素。