我有两个不同的主题,一个应用程序正在向其发送消息。
我可以只拥有一个订阅这两个主题的辅助角色吗?
答案 0 :(得分:1)
试试这个:
public class WorkerRole : RoleEntryPoint
{
ManualResetEvent CompletedEvent = new ManualResetEvent(false);
SubscriptionClient Client1 = SubscriptionClient.CreateFromConnectionString("your conn str", "TestTopic1", "HighMessages");
SubscriptionClient Client2 = SubscriptionClient.CreateFromConnectionString("your conn str", "TestTopic2", "HighMessages");
public override void Run()
{
Client1.OnMessage((receivedMessage1) =>
{
var messageFromTopic1 = receivedMessage1.GetBody<string>();
//Do stuff
});
Client2.OnMessage((receivedMessage2) =>
{
var messageFromTopic2 = receivedMessage2.GetBody<string>();
//Do stuff
});
CompletedEvent.WaitOne();
}
public override void OnStop()
{
//Also close your clients here (Client1.Close(), ...)
CompletedEvent.Set();
base.OnStop();
}
}
为简洁起见,我已跳过OnStart方法。