Azure Service Bus topics partitioning

2019-07-09 04:53发布

问题:

I'm trying to send a message to a topic which was created with both Enable duplicate detection and Enable partitioning options checked. I do not set SessionId and PartitionKey properties on my BrokeredMessage instance. According to this:

If the queue or topic has the QueueDescription.RequiresDuplicateDetection property set to true and the BrokeredMessage.SessionId or BrokeredMessage.PartitionKey properties are not set, then the BrokeredMessage.MessageId property serves as the partition key.

After I create an instance of BrokeredMessage its MessageId property is initialized automatically so I expect partitioning to work. But it does not:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage2Async ---> System.InvalidOperationException: SessionId needs to be set for all brokered messages to a Partitioned Topic that supports Ordering, Topic Name = dev1-mtapp:Topic:response-topic~255. TrackingId:5fbe5df2-8747-4053-ba79-c29a80e9d1ed_G25_B31, SystemTracker:dev1-mtapp:topic:response-topic~255

Where am I wrong?

回答1:

You should set: topicDescription.SupportOrdering = false. For example:

        if (!this.namespaceManager.TopicExists(topicName))
        {
            TopicDescription topicDescription = new TopicDescription(topicName);
            topicDescription.SupportOrdering = false;
            this.namespaceManager.CreateTopic(topicDescription);
        }