同一个工作人员是否可以收听不同主题的 2 个不同订阅

Is it possible for the same worker to listen to 2 different subscriptions for different topics

我有两个不同的主题,一个应用程序正在向其发送消息。

我可以只有一个工作者角色同时订阅这两个主题吗?

试试这个:

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 方法。