SOA 是否支持方法组合? [英] Does SOA support method composition?

查看:31
本文介绍了SOA 是否支持方法组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个很好的例子这里:

There is a good example taken here:

CRUD x 业务逻辑接口.假设您正在使用发票.每张发票由一个 InvoiceHeader 和一个或多个 InvoiceLine 组成.如果您对发票使用 CRUD 接口,您将首先调用 CreateInvoiceHeader 操作来创建 InvoiceHeader,然后调用几个 AddInvoiceLine 操作来添加所有 InvoiceLine - 这是低级 CRUD 方法.但是,如果您在服务端实现业务逻辑,您将调用单个 CreateInvoice 并将复杂的对象图(包含所有行的标题)传递给服务以创建和添加所需的内容.

CRUD x Business logic interface. Suppose that you are working with Invoices. Each invoice consists of an InvoiceHeader and one or more InvoiceLine. If you use a CRUD interface for invoice you will first call CreateInvoiceHeader operation to create InvoiceHeader and then several AddInvoiceLine operations to add all InvoiceLines - that is low level CRUD approach. But if you implement business logic on the service side you will call single CreateInvoice and pass a complex object graph (header with all lines) to the service to create and add what is needed.

为什么是一个完全合法的方法组合

Why a perfectly legal method composition

var Invoice = 
    Service.CreateInvoice(
        Service.CreateInvoiceHeader(...),
        {
            Service.CreateInvoiceLine(...),
            Service.CreateInvoiceLine(...)
        }
    )

  1. 在 SOA 中使用时,从性能的角度来看绝对糟糕吗?
  2. 无法自动转换为单个服务调用?

为什么必须创建一个复杂的对象图并将其发送到服务方法

Why must one instead create a complex object graph and send it to the service method

var InvoiceDTO = new InvoiceDTO(
    new InvoiceHeaderDTO(...),
    {
         new InvoiceLineDTO(...),
         new InvoiceLineDTO(...)
    }
)

var Invoice = Service.Create(InvoiceDTO)

Service 必须遍历整个图并调用相同的 Service 方法来组合生成的 Invoice?

and the Service must traverse the whole graph and call just the same Service methods to assemble the resulting Invoice?

有没有什么方法可以使用方法组合来创建复杂的结果而不使用复杂的对象图作为数据传输?

Is there any way to use method composition to create complex results without using complex object graphs as data transport?

推荐答案

答案是,使用 SOA 架构时,您的性能瓶颈是往返成本高昂.它们会增加延迟,为您的网络和 CPU 开销工作.

The answer is that with a SOA architecture your performance bottleneck is that round trips are expensive. They add latency, work for your network and CPU overhead.

有几种基本的缓解策略.

There are several basic mitigation strategies.

  1. 将相互交流的事物放在一起.在同一个过程中是最优的.在同一台机器上有很大帮助.靠近数据中心仍然有帮助.这种方法的缺点是您可以组合多少受机器大小的限制.

  1. Put things that talk to each other close together. In the same process is optimal. On the same machine helps a lot. Close by in the data center still helps. The downside of this approach is that how much you can put together is limited by machine size.

将工作分解为更细粒度的块,以最大限度地减少往返次数.这种方法的缺点是留下的交互可能更复杂(您的复杂对象图"就是一个例子).

Break work into more granular chunks to minimize how many round trips will happen. The downside of this approach is that the interactions left are likely to be more complicated (your "complex object graph" is an example).

使用更高效的协议.上个世纪,真正聪明的人嘲笑 XML 作为 RPC 协议.十年前,聪明的人意识到这是愚蠢的.许多组织仍在使用它.停止.使用 JSON、Cap'n Proto 或其他东西.唯一的缺点是组织上的挑战,即让人们就该做什么达成一致.

Use more efficient protocols. Really smart people laughed at XML as an RPC protocol in the last millennium. Smart people realized a decade ago that it was stupid. A lot of organizations still use it. Stop. Use JSON, Cap'n Proto, or something else. The only downside is the organizational challenge of getting people to agree on what to do instead.

并行调用.也就是说,不要一次发送 50 个请求.将它们一起发送并在它们返回时进行处理.不利的一面是,这会显着增加代码的复杂性,并且只会帮助减少延迟 - 对资源消耗没有帮助.

Make calls in parallel. That is don't send 50 requests one at a time. Send them together and process them when they come back. The downside is that this adds considerably to code complexity and only helps with latency - resource consumption is not helped.

您不必在这些选项中进行选择.拥有良好 SOA 架构的公司(例如 Google)完成所有 4 项工作.

You do not have to choose among these options. Companies with good SOA architectures (eg Google) do all 4.

也就是说,回到你的问题.有一个中间立场.您可以调用创建一个对象,进行各种调用以构建数据结构,然后调用以实际发送它,而不是使用复杂的对象进行调用.代码看起来与您使用低级 CRUD 接口编写的完全一样,只是最后有一个 Service.Send() 调用,它实际上发送了请求.

That said, back to your question. There is a middle ground. Rather than making a call with a complex object what you can do is make a call to create an object, make various calls to build up the data structure, and then make a call to actually send it. The code looks exactly like what you wrote with the low level CRUD interface, except that there is a Service.Send() call at the end which actually sends off the request.

这篇关于SOA 是否支持方法组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆