Reputation: 308
I have two different topics that one application is sending messages to.
Can I have just one worker role that subscribes to both topics?
Upvotes: 0
Views: 36
Reputation: 1061
Try this:
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();
}
}
I've skipped the OnStart method for brevity.
Upvotes: 1