SALES: 1-800-867-1380

BrokeredMessage::PartitionKey Property

Gets or sets a partition key for sending a transactional message to a queue or topic that is not session-aware.

Namespace:  Microsoft.ServiceBus.Messaging
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)

public:
property String^ PartitionKey {
	String^ get ();
	void set (String^ value);
}

Property Value

Type: System::String
The partition key for sending a transactional message.

Messages that are sent as part of a transaction must specify a partition key. This can be a SessionId, PartitionKey, or MessageId if the RequiresDuplicateDetection property is set to true. All messages that are sent as part of the same transaction must specify the same partition key.

Set the PartitionKey property if you want to send a transactional message to a queue or topic that is not session-aware. If you want to send a transactional message to a session-aware topic or queue, the message must have the SessionId property set. In this case, the PartitionKey property is optional. If you set the PartitionKey property, it must be identical to the SessionId property. If they differ, Service Bus returns an InvalidOperationException exception.

If you use a transaction to send a message without a partition key or multiple messages with different partition keys, Service Bus returns an InvalidOperationException exception.

CommittableTransaction committableTransaction = new CommittableTransaction();
using (TransactionScope ts = new TransactionScope(committableTransaction))
{
    BrokeredMessage msg = new BrokeredMessage("This is a message");
    msg.PartitionKey = "myPartitionKey";
    messageSender.Send(msg); 
    ts.Complete();
}
committableTransaction.Commit();
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft