SOA 中的循环依赖 [英] Circular dependency in SOA

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

问题描述

我猜,这是一个常见问题,但我会尽量描述我当前的问题.

I'm guessing, it is a common question, but I will try to describe my current issue.

我有一个基本服务,我们将其命名为CoreService",它提供我会说的主要"功能:处理数据库中的数据(我们的应用程序中有一个集中式数据库).还有许多其他应用程序,其中一些具有用于本地目的的自己的数据库.还有一个简单的NotificationService".其目的是向不同的订阅者广播消息.

I have a base service, lets name it 'CoreService', that provides I would say "main" functionality: handle data in DB (we have a centralized DB in our applications). There are a number of other applications, some of them have their own DB for local purposes. And there is one simple 'NotificationService'. Its purpose is to broadcast messages to different subscribers.

通常,此 NotificationService 是从ExternalWorld"调用的,并将通知发送到不同的服务(其中包括CoreService").

Usually, this NotificationService is called from 'ExternalWorld' and sends notifications to different services (among them is 'CoreService').

今天我看到有必要从CoreService"中调用NotificationService".

Today I saw a necessity to call 'NotificationService' from 'CoreService'.

我在这里担心的是我引入了循环依赖:NotificationService 需要知道如何向每个服务发送消息(包括CoreService",因此它需要了解CoreService"接口,因此它需要引用'CoreService') 和 'CoreService' 需要向 'NotificationService' 发送消息(所以它也需要引用它)...循环依赖...

My concern here is that I am introducing a circular dependency: NotificationService needs to know how to send messages to each service (including 'CoreService' so it needs to know about the 'CoreService' interface and as a result it needs to reference 'CoreService') and 'CoreService' needs to send messages to 'NotificationService (so it needs to reference it too)... Circular dependency...

问题:我们应该如何构建我们的架构来处理此类问题?

Question: How should we build our architecture to handle such issue?

非常感谢!

推荐答案

当我完成写作问题时,我发现了一些想法:

When I completed writing question I found some idea:

在NotificationService"内部,我需要定义 2 个接口IMessagesSender"和IMessagesReceiver".

Inside of 'NotificationService' I need to define 2 interfaces 'IMessagesSender' and 'IMessagesReceiver'.

  1. 每个订阅者都应该实现IMessagesReceiver",并将其地址写入NotificationService"的配置文件中;
  2. 每个消息发送者都应该使用描述IMessageSender"接口的wsdl"文件,并且应该在自己的配置文件中记录通知服务的地址".

在这种情况下,我们不会删除循环依赖,但它似乎是一个解决方案......

In this case we won't remove circular dependency, but it seems like a solution...

现在,我很难说出这个解决方案的最佳方法和优缺点,所以请发表评论(和/或建议更好的方法).

Right now, it is hard for me to say what is the best way ans what are pros and cons of this solution, so please comment it (and/or suggest the better one).

非常感谢!

这篇关于SOA 中的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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