我正在尝试从服务器向特定客户端发送有关事务更改的通知。到目前为止,我在本地和开发环境中做得很好,但是在LIVE中我们有3个带有负载均衡器的应用程序池(3个物理服务器)(所有三个都有相同的机器密钥)。
所以看起来当客户端连接在同一个池上的服务器端触发通知时 - 它可以工作,但如果池不同则不起作用。
任何人都可以建议如何处理这个 - 或者问题可能是错误的代码(不正确的集线器上下文处理或其他东西)。我是SignalR的新手 - 所以使用SignalR文档中的消息广播示例。
这是mu hub:
SELECT
{ [Measures].[Reseller Sales Amount] }
DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME , CUSTOM_ROLLUP , UNARY_OPERATOR , KEY0 ON 0
, ORDER
( HIERARCHIZE
( HIERARCHIZE ( [Geography].[Geography].Levels ( 0 ).Members )
)
, ([Measures].[Reseller Sales Amount])
, BDESC
)
DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME , CUSTOM_ROLLUP , UNARY_OPERATOR , KEY0 ON 1
FROM
( SELECT
{ Generate
( [Geography].[Geography].Levels ( 3 ).Members
, TopCount
( Filter
( [Geography].[Geography].CurrentMember.Children
, NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
)
, 3
, [Measures].[Reseller Sales Amount]
)
)
} ON COLUMNS
FROM
( SELECT
{ Generate
( [Geography].[Geography].Levels ( 2 ).Members
, TopCount
( Filter
( [Geography].[Geography].CurrentMember.Children
, NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
)
, 3
, [Measures].[Reseller Sales Amount]
)
)
} ON COLUMNS
FROM
( SELECT
{ Generate
( [Geography].[Geography].Levels ( 1 ).Members
, TopCount
( Filter
( [Geography].[Geography].CurrentMember.Children
, NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
)
, 3
, [Measures].[Reseller Sales Amount]
)
)
} ON COLUMNS
FROM
( SELECT
{ Generate
( [Geography].[Geography].Levels ( 0 ).Members
, TopCount
( Filter
( [Geography].[Geography].CurrentMember.Children
, NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
)
, 3
, [Measures].[Reseller Sales Amount]
)
)
} ON COLUMNS
FROM
( SELECT
{ [Geography].[Geography].Levels ( 0 ).Members } ON COLUMNS
FROM [Adventure Works]
)
)
)
)
)
CELL PROPERTIES BACK_COLOR , CELL_ORDINAL , FORE_COLOR , FONT_NAME , FONT_SIZE , FONT_FLAGS , FORMAT_STRING , VALUE , FORMATTED_VALUE , UPDATEABLE , ACTION_TYPE
这是提供静态实例的类:
public class ExampleClassHub : Hub
{
private readonly ExampleClass _ExampleClassInstance;
public ExampleClassHub() : this(ExampleClass.Instance) { }
public ExampleClassHub(ExampleClass ExampleClassInstance)
{
_ExampleClassInstance = ExampleClassInstance;
}
}
因此,从服务器端通知按以下方式触发:
public class ExampleClass
{
private readonly static Lazy<ExampleClass> _instance = new Lazy<ExampleClass>(() =>
new ExampleClass(GlobalHost.ConnectionManager.GetHubContext<ExampleClassHub>().Clients));
private IHubConnectionContext<dynamic> Clients { get; set; }
private ExampleClass(IHubConnectionContext<dynamic> clients)
{
Clients = clients;
}
public static ExampleClass Instance
{
get
{
return _instance.Value;
}
}
public void NotifyTransactionChange(int userId, string tid, bool isTransactionSuccessfull)
{
string json = JsonConvert.SerializeObject(new Notification { UserId = userId, Tid = tid, IsTransactionSuccessful = isTransactionSuccessfull });
Clients.User(userId.ToString()).notifyTransactionStateChange(json);
}
class Notification
{
public int UserId { get; set; }
public string Tid { get; set; }
public bool IsTransactionSuccessful { get; set; }
}
}
答案 0 :(得分:0)
使用SignalR scaleout解决: http://www.asp.net/signalr/overview/performance/scaleout-in-signalr