首页 > 其他分享 >Microservice - Hexagonal Architecture

Microservice - Hexagonal Architecture

时间:2023-11-15 21:25:56浏览次数:33  
标签:adapter port application actors Architecture Microservice Hexagonal adapters por

Hexagonal architecture (https://alistair.cockburn.us/hexagonal-architecture/), proposed by Alistair Cockburn in 2005, is an architectural pattern that aims to build loosely coupled application components that can be connected via ports and adapters. In this pattern, the consumer opens the application at a port via an adapter, and the output is sent through a port to an adapter. Therefore, hexagonal architecture is also known as a ports and adapters system. Using ports and adapters creates an abstraction layer that isolates the application’s core from external dependencies. 

 

Application
An application is a technology-agnostic component that contains the business logic that orchestrates functionalities or use cases. A hexagon represents the application that receives write and read queries from the ports and sends them to external actors,
such as database and third-party services, via ports. A hexagon visually represents multiple port/adapter combinations for an application and shows the difference between the left side (or driving side) and right side (or driven side).

 

Actors
Actors are designed to interact with humans, other applications, and any other software or hardware device. There are two types of actors: driver (or primary) and driven (or secondary). Driver actors are responsible for triggering communication with the application to invoke a service on it. Command-line interfaces (CLIs), controllers, are good examples of driver actors since they take user input and send it to the application via a port. Driven actors expect to see communication triggered by the application itself. For example, an application triggers a communication to save data into MySQL.

 

Ports
Ports are generally interfaces that contain information about interactions between an actor and an application. Driver ports have a set of actions, and actors should implement them. Driver ports contain a set of actions that the application provides and exposes to the public.

 

Adapters
Adapters deal primarily with transforming a request from an actor to an application, and vice versa. Data transformation helps the application understand the requests that come from actors. For example, a specific driver adapter can transform a technology-specific request into a call to an application service. In the same way, a driven adapter can convert a technology-agnostic request from the application into a technology-specific request on the driven port.

As you can see in figure 4.1, the application has a hexagon that contains business logic, and adapters can orchestrate the hexagon by using ports. CLI and web applications are two candidates for adapters; data is saved into MySQL or sent to another application.

Using gRPC makes implementing hexagonal architecture easier because we become familiar with adapters out of the box by using gRPC stubs to access other services. gRPC can also be used to handle business models with the help of proto messages, which is especially helpful for duplicating models between hexagonal layers for better portability. 

标签:adapter,port,application,actors,Architecture,Microservice,Hexagonal,adapters,por
From: https://www.cnblogs.com/zhangzhihui/p/17834809.html

相关文章

  • Microservice - Data Consistency
    Tohavedataconsistencyinadistributedsystem, youhavetwooptions:atwo-phasecommit(2PC)andsaga. 2PCcoordinatesallthe processesthatformdistributedatomictransactionsanddetermineswhetherthey shouldbecommittedoraborted.  As......
  • From monolithic application to microservice framework
    challenges:1.versioncontrol AftertestingthebranchA,pullthelatestcode(mergedB)->confilcts?noconflicts?->regressiontesting 2. changetogolanguage3.upgradethelibrarygo1.12-go1.134.onlyonetestingserverwaitingformulti......
  • [k8s] Kubernetes Architecture
    ControlPlaneMaster节点主要有4个主要组件:APIServer跟集群进行交互的接口(kubectl)etcd,集群数据存储Scheduler,根据不同的因素决定最终的容器运行在哪个节点node上ControllerManager,管理不同的controller的WorkerNodeWorker节点的三个主要组件:kubelet运行在每一个node上的age......
  • Microservice - What are microservices, and why are microservices?
    Theconceptof microservicesissimplybreakingasinglelargepotentialserviceintomanysmaller servicesthatworktogether,hence,thename.Oneveryobviousadvantagewhenitcomestobuildinganapplicationwitha microservicearchitecturewouldbe......
  • 什么是 SAP S/4HANA 的 VDM Layering Architecture 的 CDS Cube View
    SAPS/4HANA的VDMLayeringArchitecture的CDSCubeView在深入探讨"SAPS/4HANA的VDMLayeringArchitecture的CDSCubeView"之前,让我们逐步了解这个概念的不同组成部分。SAPS/4HANA:SAPS/4HANA是SAP的下一代企业资源计划(ERP)套件,通过内存数据库和先进的分析功能,实现更快......
  • 什么是 SAP S/4HANA 的 VDM Layering Architecture 的 CDS Hierarchy View
    当涉及SAPS/4HANA的CDSHierarchyView时,我们正在谈论一种高级数据建模技术,用于构建层次结构化的数据视图,以支持树状和分层数据的处理和分析。CDS(CoreDataServices)是SAP的一种数据建模和定义语言,而CDSHierarchyView则是CDS的一个重要组成部分,用于处理层次数据,如组织结构、产......
  • 什么是 SAP S/4HANA 的 VDM Layering Architecture 的 CDS Analytical Query View
    CDS,即CoreDataServices,是一种用于定义数据模型和数据库访问的语言,广泛用于SAP应用程序开发。AnalyticalQueryView(AQV)是CDS的一种扩展,专门用于支持分析性查询和报表。什么是CDSAnalyticalQueryView?CDSAnalyticalQueryView是一种在SAPS/4HANA中用于创建高性能分析查询......
  • 什么是 SAP S/4HANA 的 VDM Layering Architecture 的 CDS Dimension View
    在深入探讨"SAPS/4HANA的VDMLayeringArchitecture的CDSDimensionView"之前,让我们逐步了解这个概念的不同组成部分。SAPS/4HANA:SAPS/4HANA是SAP的下一代企业资源计划(ERP)套件,通过内存数据库和先进的分析功能,实现更快的数据处理和实时决策。它包含了各种模块,涵盖了企业各个......
  • 什么是 SAP S/4HANA 的 VDM Layering Architecture 的 VDM Composite View
    SAPS/4HANA的VDMLayeringArchitecture的VDMCompositeView在理解"SAPS/4HANA的VDMLayeringArchitecture的VDMCompositeView"之前,让我们先逐步了解这个概念的各个组成部分。SAPS/4HANA:SAPS/4HANA是SAP的下一代企业资源计划(ERP)套件,它通过内存数据库和先进的分析功......
  • 什么是 SAP S/4HANA 的 VDM Layering Architecture 的 VDM Comsumption View
    SAPS/4HANA的VDMLayeringArchitecture的VDMConsumptionView在深入探讨"SAPS/4HANA的VDMLayeringArchitecture的VDMConsumptionView"之前,让我们逐步了解这个概念的不同组成部分。SAPS/4HANA:SAPS/4HANA是SAP的下一代企业资源计划(ERP)套件,通过内存数据库和先进的分......