WCF双工通信在集群环境 [英] WCF Duplex Communications in a clustered environment

查看:201
本文介绍了WCF双工通信在集群环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在寻找即当由IIS托管,并通过Silverlight的连接到人的双工通信创建的示例的例子。有很多的这个那里的例子(这个MSDN文章大),但的所有的使用相同的模式:



用户A连接到服务器A,这让他在IN-内存列表获得未来的更新。结果
的用户b连接到服务器A,它会通知所有用户列表中有人登录。



。 ..但是当



用户C连接到服务器C上发生了什么,在内存中列表服务器C不包含用户A或b。



的问题是,我期待在群集(网络场)环境中实现这一点。因为我不能确认哪些机器将结束守备WCF调用,那么中继的信息传达给所有其他用户的这种复杂的事情是困难的。



最好的情况我能想到的的是居然有客户端连接到某种路由服务,是以传入的请求和客户端转发到特定的机器。当然,然后我失去了Web场的好处,因为一台机器可以有效地守备所有传入的请求。



一个不太有效的解决方案是让服务不断轮询的东西(无论是在文件服务器或文件在数据库中的表)寻找变化。一旦变化都存在,推动他们到客户端。这似乎是一个非常难看的宝宝,寿



什么我错过了



更新 - ?路由系统是不可能的我的需要。我的托管公司不会让我可以直接连接到特定的机器上通过IP农场。我只能连接到通用负载平衡器的前端,所以不能保证我的用户将结束在同一服务器上。



到目前为止,我们现在只剩下投票在db表中寻找变化。似乎仍然像一个丑陋的婴儿。


解决方案

假设你有超越你可以在每台服务器上安装什么零控制环境(即没有MSMQ,没有ESB等),那么我会考虑使用WCF服务器之间的通信。简单的问题似乎是,你有一个在内存中的列表,需要保持两个服务器之间的同步,每当列表中的内容发生变化,这两个服务器的用户需要得到通知。



使用两台服务器主机和使用,你可以使用内部WCF服务简单的发射后不管的消息,以保持列表同步。试想以下情形:




  1. 用户A登录到服务器A

    1. 用户A给在线用户

    2. 消防信息列表添加到服务器b,通知它增加了用户A的

      1. 原因服务器b为用户A添加到其在线用户列表

      2. 导致服务器b,通知用户登录的所有用户


    3. 通知所有用户在用户登录的服务器A


  2. 用户b到服务器b $日志b $ b

    1. 用户b添加到在线用户列表

    2. 消防消息,服务器A,通知ADDD的用户b'

      1. 导致服务器A用户b添加到其在线用户

      2. 列表导致服务器A,通知用户登录的所有用户


    3. 通知所有用户在用户登录的服务器b


  3. 用户A'日志服务器A

    1. 从在线用户列表中删除用户A

    2. 消防消息灭地服务器b,通知删除用户A'

      1. 导致服务器b从它的在线用户列表

      2. 导致服务器b,通知用户注销的所有用户

    3. 通知用户注销的服务器A的所有用户


  4. 定期,有服务器A和服务器b同步它们彼此
    列表(可以实现乒乓风格......一台服务器的ping其列表到其他服务器,
    其他的服务器合并和pongs合并表背面)



上面的场景显然假定你有能力到托管服务器上安装的WCF服务,使得它们可以互相通信。我不知道,如果你有能力,内部到每个服务器,知道其他服务器,正如你所提到的所有流量都需通过负载平衡器。


So I was looking at the sample examples people have created for Duplex Communications namely when hosted by IIS and connected to via Silverlight. There are plenty of examples of this out there (this MSDN article is great), but all use the same paradigm:

User A connects to server A, it puts him in an in-memory list to receive future updates.
User B connects to server A, it notifies all users in list that someone "logged in".

... but what happens when

User C connects to server C, the in-memory list for server C doesn't contain User A or B.

The problem is that I'm looking to implement this in a clustered (web farm) environment. This complicates things because I cannot verify which machine will wind up fielding the wcf call, so relaying any message out to all other users is difficult.

The best scenario I can think of is to actually have the clients connect to some sort of routing service that takes the incoming request and forwards the client to a particular machine. Of course, then I'm losing the benefit of the web farm, since a single machine is effectively fielding all incoming requests.

A less effective solution is to have the service continually polling something (either a file on the fileserver or a table in the DB) looking for changes. Once changes are present, push them out to the clients. This seems like a very ugly baby, tho.

What have I missed?

UPDATE - The routing system is impossible for my needs. My hosting company will not allow me to directly connect to a specific machine on the farm via IP. I can only connect to the generic load-balancer front-end, so cannot guarantee my users will wind up on the same server.

So far, we're down to polling the table in the db looking for changes. Still seems like an ugly baby.

解决方案

Assuming you have zero control of your environment beyond what you can install on each server (i.e. no MSMQ, no ESB, etc.), then I would look into using WCF to communicate between servers. The simple problem seems to be that you have an in-memory list that needs to remain synced between the two servers, and whenever the contents of the list changes, users of both servers need to be notified.

With an internal WCF service that both servers host and use, you could use simple fire-and-forget messaging to keep the lists in sync. Imagine the following scenario:

  1. 'User A' logs in to Server A

    1. Add 'User A' to list of online users
    2. Fire message to Server B to notify it of added 'User A'

      1. Causes Server B to add 'User A' to its list of online users
      2. Causes Server B to notify all users of user login

    3. Notify all users on Server A of user login

  2. 'User B' logs in to Server B

    1. Add 'User B' to list of online users
    2. Fire message to Server A to notify it of addd 'User B'

      1. Causes Server A to add 'User B' to its list of online users
      2. Causes Server A to notify all users of user login

    3. Notify all users on Server B of user login

  3. 'User A' logs off of Server A

    1. Remove 'User A' from list of online users
    2. Fire message to Server B to notify it of removed 'User A'

      1. Causes Server B to remove 'User A' from its list of online users
      2. Causes Server B to notify all users of user logoff

    3. Notify all users on Server A of user logoff

  4. Periodically, have Server A and Server B sync their lists with each other (Could be implemented Ping-Pong style...one server pings its list to other server, other server merges and pongs merged list back)

The above scenario obviously assumes that you have the ability to install WCF services on your hosted servers such that they can communicate with each other. I am not sure if you have the ability, internally to each server, to know of the other servers, as you mentioned all traffic had to go through a load balancer.

这篇关于WCF双工通信在集群环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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