.NET 微服务:适用于容器化 .NET 应用程序的体系结构.NET Microservices: Architecture for Containerized .NET Applications

封面

版本 v2.2.00 - 已更新到 ASP.NET Core 2.2EDITION v2.2.00 - Updated to ASP.NET Core 2.2

本指南介绍如何使用容器开发基于微服务的应用程序并对其进行管理。This guide is an introduction to developing microservices-based applications and managing them using containers. 本指南探讨使用 .NET Core 和 Docker 容器的体系结构设计和实现方法。It discusses architectural design and implementation approaches using .NET Core and Docker containers.

为了更加轻松地开始使用,本指南重点介绍一个容器化和基于微服务的参考应用程序(用户可获取该应用程序)。To make it easier to get started, the guide focuses on a reference containerized and microservice-based application that you can explore. 可通过 eShopOnContainers GitHub 存储库获取该参考应用程序。The reference application is available at the eShopOnContainers GitHub repo.

介绍Introduction

企业通过使用容器,日益实现成本节约、解决部署问题并改进 DevOps 和生产操作。Enterprises are increasingly realizing cost savings, solving deployment problems, and improving DevOps and production operations by using containers. 通过创建 Azure Kubernetes 服务、Azure Service Fabric 等产品,同时与 Docker、Mesosphere 和 Kubernetes 等行业领先者合作,Microsoft 一直在推出适用于 Windows 和 Linux 的容器创新。Microsoft has been releasing container innovations for Windows and Linux by creating products like Azure Kubernetes Service and Azure Service Fabric, and by partnering with industry leaders like Docker, Mesosphere, and Kubernetes. 这些产品提供容器解决方案,可帮助公司以云的速度和规模生成并部署应用程序,而无需考虑其选用的平台或工具。These products deliver container solutions that help companies build and deploy applications at cloud speed and scale, whatever their choice of platform or tools.

Docker 正在逐渐成为容器行业的事实标准,受到 Windows 和 Linux 生态系统领域最重要供应商的支持。Docker is becoming the de facto standard in the container industry, supported by the most significant vendors in the Windows and Linux ecosystems. (Microsoft 是支持 Docker 的主要云供应商之一。)将来,Docker 可能会在云端或本地的任何数据中心普及。(Microsoft is one of the main cloud vendors supporting Docker.) In the future, Docker will probably be ubiquitous in any datacenter in the cloud or on-premises.

此外,microservices(微服务)体系结构兴起,成为分布式任务关键型应用程序的重要方法。In addition, the microservices architecture is emerging as an important approach for distributed mission-critical applications. 在基于微服务的体系结构中,应用程序在可独立开发、测试、部署和版本控制的一系列服务上生成。In a microservice-based architecture, the application is built on a collection of services that can be developed, tested, deployed, and versioned independently.

关于本指南About this guide

本指南介绍如何使用容器开发基于微服务的应用程序并对其进行管理。This guide is an introduction to developing microservices-based applications and managing them using containers. 本指南探讨使用 .NET Core 和 Docker 容器的体系结构设计和实现方法。It discusses architectural design and implementation approaches using .NET Core and Docker containers. 为了更加轻松地开始使用容器和微服务,本指南重点介绍一个容器化和基于微服务的参考应用程序(用户可获取该应用程序)。To make it easier to get started with containers and microservices, the guide focuses on a reference containerized and microservice-based application that you can explore. 可通过 eShopOnContainers GitHub 存储库获取该示例应用程序。The sample application is available at the eShopOnContainers GitHub repo.

本指南主要在开发环境级别提供基础开发和体系结构指导,重点介绍以下两种技术:Docker 和 .NET Core。This guide provides foundational development and architectural guidance primarily at a development environment level with a focus on two technologies: Docker and .NET Core. 我们的目标是为用户在应用程序设计时提供指导,使用户无需将重点放在其生产环境的基础结构(云端或本地)上。Our intention is that you read this guide when thinking about your application design without focusing on the infrastructure (cloud or on-premises) of your production environment. 用户可在创建生产就绪的应用程序时,稍后制定有关基础结构的决策。You will make decisions about your infrastructure later, when you create your production-ready applications. 因此,本指南不区分基础结构,更侧重于考虑开发环境。Therefore, this guide is intended to be infrastructure agnostic and more development-environment-centric.

学习本指南后,接下来将了解 Microsoft Azure 上的生产就绪微服务。After you have studied this guide, your next step would be to learn about production-ready microservices on Microsoft Azure.

VersionVersion

本指南已进行了修订,涵盖 .NET Core 2.2 版本以及与 .NET Core 2.2 同期的同一“批”技术 This guide has been revised to cover .NET Core 2.2 version plus many additional updates related to the same “wave” of technologies (that is. (即 Azure 和其他第三方技术)的许多其他更新。Azure and additional 3rd party technologies) coinciding in time with .NET Core 2.2. 这就是书本版本也更新到 2.2 的原因 。That’s why the book version has also been updated to version 2.2.

本指南未涵盖的内容What this guide does not cover

本指南未涵盖应用程序生命周期、DevOps、CI/CD 管道或团队协作。This guide does not focus on the application lifecycle, DevOps, CI/CD pipelines, or team work. 补充指南 Containerized Docker Application Lifecycle with Microsoft Platform and Tools(使用 Microsoft 平台和工具的容器化 Docker 应用程序的生命周期)重点介绍该主题。The complementary guide Containerized Docker Application Lifecycle with Microsoft Platform and Tools focuses on that subject. 此外,当前指南不提供实现 Azure 基础结构的详细信息,例如有关特定业务流程的信息。The current guide also does not provide implementation details on Azure infrastructure, such as information on specific orchestrators.

其他资源Additional resources

  • 《使用 Microsoft 平台和工具的容器化 Docker 应用程序生命周期》 (可下载电子书)Containerized Docker Application Lifecycle with Microsoft Platform and Tools (downloadable e-book)
    https://aka.ms/dockerlifecycleebook

本指南的目标读者Who should use this guide

本指南的目标读者是不熟悉以下内容的开发人员和解决方案架构师:基于 Docker 的应用程序开发和基于微服务的架构。We wrote this guide for developers and solution architects who are new to Docker-based application development and to microservices-based architecture. 若要了解如何使用 Microsoft 开发技术(特别是 .NET Core)和 Docker 容器架构、设计和实现概念验证应用程序,本指南是理想之选。This guide is for you if you want to learn how to architect, design, and implement proof-of-concept applications with Microsoft development technologies (with special focus on .NET Core) and with Docker containers.

如果企业架构师等技术决策制定者想要在综合了解体系结构和技术的基础上,作出有关新式和现代分布式应用程序应选择的方法的决策,则本指南也非常有用。You will also find this guide useful if you are a technical decision maker, such as an enterprise architect, who wants an architecture and technology overview before you decide on what approach to select for new and modern distributed applications.

如何使用本指南How to use this guide

本指南的第一部分介绍 Docker 容器,探讨用作开发框架时如何在 .NET Core 和 .NET Framework 之间选择,并提供有关微服务的概述。The first part of this guide introduces Docker containers, discusses how to choose between .NET Core and the .NET Framework as a development framework, and provides an overview of microservices. 此内容适合希望大概了解而不关注代码实现细节的架构师和技术决策制定者。This content is for architects and technical decision makers who want an overview but don't need to focus on code implementation details.

本指南的第二部分从基于 Docker 的应用程序的开发过程一节开始。The second part of the guide starts with the Development process for Docker based applications section. 重点介绍使用 .NET Core 和 Docker 实现应用程序的开发和微服务模式。It focuses on development and microservice patterns for implementing applications using .NET Core and Docker. 对于要重点了解代码以及模式和实现详细信息的开发人员和架构师,此部分最有吸引力。This section will be of most interest to developers and architects who want to focus on code and on patterns and implementation details.

eShopOnContainers 应用程序是用于 .NET Core 和旨在使用 Docker 容器部署的微服务的开源参考应用。The eShopOnContainers application is an open-source reference app for .NET Core and microservices that is designed to be deployed using Docker containers. 该应用程序包含多个子系统,包括多个 e-store UI 前端(一个 Web MVC 应用、一个 Web SPA 和一个本机移动应用)。The application consists of multiple subsystems, including several e-store UI front ends (a Web MVC app, a Web SPA, and a native mobile app). 还包括用于所有所需服务器端操作的后端微服务和容器。It also includes the back-end microservices and containers for all required server-side operations.

应用程序的用途是展示体系结构模式。The purpose of the application is to showcase architectural patterns. 它不是可直接用于生产的模板,无法启动实际应用程序。IT IS NOT A PRODUCTION-READY TEMPLATE to start real-world applications. 事实上,应用程序处于永久 beta 状态,因为它还用来在出现有趣的新技术时对其进行测试。In fact, the application is in a permanent beta state, as it’s also used to test new potentially interesting technologies as they show up.

向我们发送反馈!Send us your feedback!

本指南旨在帮助用户了解 .NET 中容器化应用程序和微服务的体系结构。We wrote this guide to help you understand the architecture of containerized applications and microservices in .NET. 本指南和相关的参考应用程序会不断更新,欢迎你提供宝贵意见!The guide and related reference application will be evolving, so we welcome your feedback! 如有关于本指南的改进建议,请发送到:If you have comments about how this guide can be improved, please send them to:

dotnet-architecture-ebooks-feedback@service.microsoft.com

信用Credits

合著者:Co-Authors:

Cesar de la Torre,Microsoft Corp .NET 产品团队的高级项目经理。Cesar de la Torre, Sr. PM, .NET product team, Microsoft Corp.

Bill Wagner,Microsoft Corp C+E 高级内容开发人员。Bill Wagner, Sr. Content Developer, C+E, Microsoft Corp.

Mike Rousos,Microsoft DevDiv CAT 团队的主要软件工程师Mike Rousos, Principal Software Engineer, DevDiv CAT team, Microsoft

编辑:Editors:

Mike PopeMike Pope

Steve HoagSteve Hoag

参与者和审阅者:Participants and reviewers:

Jeffrey Ritcher,Microsoft Azure 团队的合作伙伴软件工程师Jeffrey Richter, Partner Software Eng, Azure team, Microsoft

Jimmy Bogard,Headspring 的首席架构师Jimmy Bogard, Chief Architect at Headspring

Udi Dahan,Particular Software 的创始人兼 CEOUdi Dahan, Founder & CEO, Particular Software

Jimmy Nilsson,Factor10 的共同创始人兼 CEOJimmy Nilsson, Co-founder and CEO of Factor10

Glenn Condron,ASP.NET 团队的高级项目经理Glenn Condron, Sr. Program Manager, ASP.NET team

Mark Fussell,Microsoft Azure Service Fabric 团队的主要项目经理主管Mark Fussell, Principal PM Lead, Azure Service Fabric team, Microsoft

Diego Vega,Microsoft 实体框架团队的项目经理主管Diego Vega, PM Lead, Entity Framework team, Microsoft

Barry Dorrans,高级安全项目经理Barry Dorrans, Sr. Security Program Manager

Rowan Miller,Microsoft 高级项目经理Rowan Miller, Sr. Program Manager, Microsoft

Ankit Asthana,Microsoft .NET 团队的主要项目经理Ankit Asthana, Principal PM Manager, .NET team, Microsoft

Scott Hunter,Microsoft .NET 团队的合作伙伴总监项目经理Scott Hunter, Partner Director PM, .NET team, Microsoft

Microsoft .NET 团队高级项目经理 Nish Anil Nish Anil, Sr. Program Manager, .NET team, Microsoft

Dylan Reisenberger,Polly 的架构师兼开发主管Dylan Reisenberger, Architect and Dev Lead at Polly

Steve "ardalis" Smith - 软件设计师及培训师 - Ardalis.comSteve "ardalis" Smith - Software Architect and Trainer - Ardalis.com

Ian Cooper,Brighter 的编码架构师Ian Cooper, Coding Architect at Brighter

Unai Zorrilla,Plain Concepts 的架构师兼开发主管Unai Zorrilla, Architect and Dev Lead at Plain Concepts

Eduard Tomas,Plain Concepts 的开发主管Eduard Tomas, Dev Lead at Plain Concepts

Ramon Tomas,Plain Concepts 的开发者Ramon Tomas, Developer at Plain Concepts

David Sanz,Plain Concepts 的开发者David Sanz, Developer at Plain Concepts

Javier Valero,Grupo Solutio 的首席运营官Javier Valero, Chief Operating Officer at Grupo Solutio

Pierre Millet,Microsoft 高级顾问Pierre Millet, Sr. Consultant, Microsoft

Michael Friis,Docker Inc 的产品经理Michael Friis, Product Manager, Docker Inc

Charles Lowell,Microsoft VS CAT 团队的软件工程师Charles Lowell, Software Engineer, VS CAT team, Microsoft

Miguel Veloso,Turing Challenge 的高级顾问Miguel Veloso, Sr. Consultant at Turing Challenge

下载地址:https://aka.ms/microservicesebookDOWNLOAD available at: https://aka.ms/microservicesebook

发布者PUBLISHED BY

Microsoft 开发人员部门、.NET 和 Visual Studio 产品团队Microsoft Developer Division, .NET and Visual Studio product teams

Microsoft Corporation 的一个部门A division of Microsoft Corporation

One Microsoft WayOne Microsoft Way

Redmond, Washington 98052-6399Redmond, Washington 98052-6399

版权所有 © 2018 Microsoft CorporationCopyright © 2018 by Microsoft Corporation

保留所有权利。All rights reserved. 未经发布者书面许可,不得以任何形式或任何方式复制或传播本书中的任何内容。No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.

本书“按原样”提供,表达作者的观点和看法。This book is provided “as-is” and expresses the author’s views and opinions. 本书中表达的观点、看法和信息(包括 URL 和其他 Internet 网站引用)如有更改,恕不另行通知。The views, opinions and information expressed in this book, including URL and other Internet website references, may change without notice.

本书中提及的一些示例仅用于说明,纯属虚构。Some examples depicted herein are provided for illustration only and are fictitious. 不存在任何实际关联或联系,请勿妄加推断。No real association or connection is intended or should be inferred.

Microsoft 和 https://www.microsoft.com 上“商标”网页列出的商标是 Microsoft 集团公司的商标。Microsoft and the trademarks listed at https://www.microsoft.com on the “Trademarks” webpage are trademarks of the Microsoft group of companies.

Mac 和 macOS 是 Apple Inc. 的商标Mac and macOS are trademarks of Apple Inc.

Docker 的鲸鱼徽标是 Docker Inc. 的注册商标经许可方可使用。The Docker whale logo is a registered trademark of Docker, Inc. Used by permission.

所有其他标记和徽标均为其各自所有者的财产。All other marks and logos are property of their respective owners.