3

我正在尝试使用 Azure 服务总线将消息从 Web 角色广播到单个辅助角色的所有实例。这是我用来接收消息的代码:

// Create the topic if it does not exist already
            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
        var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

        // Configure Topic Settings
        TopicDescription td = new TopicDescription("CommandTopic");
        td.MaxSizeInMegabytes = 5120;
        td.DefaultMessageTimeToLive = new TimeSpan(0, 0, 1);

        if (!namespaceManager.TopicExists("CommandTopic"))
        {
            namespaceManager.CreateTopic(td);
        }

        Random rand = new Random();
        double randNum = rand.Next();

        if (!namespaceManager.SubscriptionExists("CommandTopic", "CommandSubscription"+randNum))
        {
            namespaceManager.CreateSubscription("CommandTopic", "CommandSubscription" + randNum);
        }

        Client = SubscriptionClient.CreateFromConnectionString(connectionString, "CommandTopic", "CommandSubscription" + randNum, ReceiveMode.ReceiveAndDelete);
        Trace.WriteLine("SUBSCRIPTION: COMMANDSUBSCRIPTION"+randNum);

为了为每个工作角色实例创建一个单独的订阅(以便所有实例都收到主题中的消息),我不得不使用一个随机数。有没有办法使用实例的一些 Id 而不是随机数。有 Instance.Id 但是它太长而不能用作订阅名称的参数。是否有不使用子字符串的较短版本?另外,为每个实例创建单独的订阅是正确的方法吗?以前所有实例都订阅了同一个订阅,因此只有 1 个实例获取消息并将其从订阅中删除。

4

2 回答 2

0

please find the following link, I hope it can help you make the intercommunication between your roles:

http://msdn.microsoft.com/en-us/library/windowsazure/hh180158.aspx

and also please have a look on the following link, I think it has exactly what you are looking for: http://windowsazurecat.com/2011/08/how-to-simplify-scale-inter-role-communication-using-windows-azure-service-bus/

I think what you are talking about would be like the Scenario 4 in the following link where a role can communicate to several other roles. I am not sure if what you asked for is possible, but try working with the Windows Azure Worker Role with Service Bus Queue, I think this might help you a lot and might also be a better solution than the topic and subscription in this case.

于 2013-04-05T22:30:03.250 回答
0

尝试将工作人员角色的虚假 InternalEndpoint 添加到您的配置中。这可确保填充角色的实例列表。

于 2013-03-13T07:03:12.700 回答