简体   繁体   English

Web服务体系结构-多租户设计模式(也许)

[英]Web Service Architecture - multi tenancy design pattern (maybe)

I having a slight design problem : I have to create a Web Service (asmx or wcf) that retrieves customer data from multiple database servers, each one is exactly the same except they will contain data for different States (1 DB server per state, big states can have multiples etc). 我有一个轻微的设计问题:我必须创建一个Web服务(asmx或wcf),该服务从多个数据库服务器检索客户数据,每个服务器都完全相同,除了它们将包含不同状态的数据(每个状态1个DB服务器,大)状态可以有多个等)。

This will be used by a call center, for example, someone calls the call center and says, can i have an indication when my order will be delivered my order no is "aa_etc" and the service should run a query on all servers and return all the orders details for that order. 这将由呼叫中心使用,例如,有人呼叫呼叫中心并说,我可以指示我的订单何时交付,我的订单编号是“ aa_etc”,并且该服务应在所有服务器上运行查询并返回该订单的所有订单详细信息。

This is straight forward, except there is multiple servers to query.My idea is to have central sqlite db with all connection strings of the current online servers and then query each one in turn 这很简单,除了要查询多个服务器。我的想法是让中央sqlite db具有当前在线服务器的所有连接字符串,然后依次查询每个


public class OnlineServer 
{
 public string Name {get;set;}
 public string ConnectionString {get;set;} 
}
...
public class Order
{
   public List OrderDetail getDetails(string orderno,string connstring)
   {
     //Code to get all orders from database using specified connstring
   }
   ....
}
....

List servers = getOnlineServers();

foreach(OnlineServer in servers)
{
  OrderDetails d = Order.getDetails("aa_etc",OnlineServer.ConnectionString);
}


Just writing down this idea feels totally wrong. 仅仅写下这个想法是完全错误的。

I would really appreciate it if someone can help me get going with this in the right direction, this is a really big project and starting this wrong will just end up in tears later on. 如果有人能帮助我朝正确的方向前进,我将非常感激,这是一个非常大的项目,而开始犯错将在后来流下眼泪。

Thanks 谢谢

If you cannot some how merge the data in to a single DB. 如果您无法通过某种方式将数据合并到单个DB中。 You may be able to use nHibernate. 您可能可以使用nHibernate。 It can query multiple databases see http://mikehadlow.blogspot.com/2008/10/mapping-entities-to-multiple-databases.html 它可以查询多个数据库,请参见http://mikehadlow.blogspot.com/2008/10/mapping-entities-to-multiple-databases.html

You would have to set up a different entity per server. 您将必须为每个服务器设置不同的实体。 By doing it this way it would take care of all your DB connections, pooling, sessions etc. 通过这种方式,它将可以处理所有数据库连接,池,会话等。

I want to consider this problem a bit futher but I have an off-the-wall idea which might be of interest so I'll through it out there. 我想进一步考虑这个问题,但是我有一个可能很感兴趣的现成想法,因此我将继续解决它。

My idea is to have central sqlite db with all connection strings of the current online servers and then query each one in turn 我的想法是让中央sqlite db具有当前在线服务器的所有连接字符串,然后依次查询每个

This gave me an idea: why not fire off a search query to each system asynchonously? 这给了我一个主意:为什么不异步地向每个系统启动搜索查询? I'm thinking AJAX here (but you could use iFrames)... 我在这里想使用AJAX(但是您可以使用iFrame)...

  1. The user enters a search and hits "Go". 用户输入搜索并点击“开始”。
  2. Somehow you loop through your collection of known data sources, but each "sub" search is seperate and asynchonous (think federated search). 您会以某种方式遍历已知数据源的集合,但是每个“子”搜索都是独立且异步的(请考虑联合搜索)。
  3. As results come back they are displayed on screen to the user - who can then stop the search process if they get a match they like. 结果返回时,它们会在屏幕上显示给用户-如果他们得到自己喜欢的匹配项,然后他们可以停止搜索过程。

I'm assuming the data would be "pulled together" visually by the UI - either by straight layout or via clever client-side code - this would give you further options to tailor the UI but at the expense of a more complex client-side code base. 我假设数据将通过UI可视化“拉在一起”-通过直接布局或通过巧妙的客户端代码-这将为您提供定制UI的更多选择,但以更复杂的客户端为代价代码库。

You'd have other options too, like allowing the user to narrow their search by data source if they wanted to. 您还会有其他选择,例如允许用户根据需要缩小数据源搜索范围。

Also, adding / removing data sources would be simple. 同样,添加/删除数据源也很简单。

This is where I need to address you're actual question more directly; 这是我需要直接解决您实际问题的地方。 in my opinion you'd most definately want a seperate service per database - but there's flexibility in how you do that. 在我看来,您绝对希望每个数据库都提供单独的服务-但是您可以灵活地做到这一点。

  • Having a collection of services that reflects the data sources gives you a clean logical architecture. 拥有反映数据源的服务集合可以为您提供干净的逻辑体系结构。
  • Doing this doesn't preclude putting something over the top that brings it together (thinking of loose-coupling here). 这样做并不排除将某些东西放到顶部以将它们放在一起(此处考虑的是松散耦合)。
  • It's always much easier to put stuff together than tear them apart. 它总是容易把东西一起比撕裂他们。
  • You'd still be able to re-use code: multiple instances perhaps. 您仍然可以重复使用代码:也许有多个实例。
  • You'd have some management overhead due to multiple instances - but also the flexibility to management them better: access control, dedication of resources, etc. 由于有多个实例,您将有一些管理开销-但还具有更好地管理它们的灵活性:访问控制,资源专用等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM