MessageBufferClient Class

The message buffer client enables the management and use of an Windows Azure Service Bus message buffer.

Inheritance Hierarchy

System. . :: . .Object
  Microsoft.ServiceBus..::..MessageBufferClient

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

Syntax

'Declaration
Public NotInheritable Class MessageBufferClient
'Usage
Dim instance As MessageBufferClient
public sealed class MessageBufferClient
public ref class MessageBufferClient sealed
[<SealedAttribute>]
type MessageBufferClient =  class end
public final class MessageBufferClient

The MessageBufferClient type exposes the following members.

Properties

  Name Description
Public property MessageBufferUri Retrieves the URI for the message buffer.

Top

Methods

  Name Description
Public methodStatic member CreateMessageBuffer(TransportClientEndpointBehavior, Uri, MessageBufferPolicy) Creates a new message buffer on the Windows Azure Service Bus, using the specified credentials, URI, and policy.
Public methodStatic member CreateMessageBuffer(TransportClientEndpointBehavior, Uri, MessageBufferPolicy, MessageVersion) Creates a new message buffer on the Windows Azure Service Bus, using the specified credentials, URI, policy, and message version.
Public method DeleteLockedMessage Deletes the specified locked message from the message buffer.
Public method DeleteMessageBuffer Deletes the message buffer associated with this client.
Public method Equals (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public methodStatic member GetMessageBuffer(TransportClientEndpointBehavior, Uri) Retrieves a message buffer client, based on the specified credentials and URI.
Public methodStatic member GetMessageBuffer(TransportClientEndpointBehavior, Uri, MessageVersion) Retrieves a message buffer from the specified URI, using the specified credentials and message version.
Public method GetPolicy Retrieves the policy of the message buffer with which the current instance is associated.
Public method GetType (Inherited from Object.)
Public method PeekLock() () () () Retrieves the first available message from the message buffer, and locks that message on the buffer.
Public method PeekLock(TimeSpan) Retrieves the first message from the message buffer and locks the message on the buffer for the default lock duration of two minutes.
Public method PeekLock(TimeSpan, TimeSpan) Retrieves a copy of the first message from the message buffer, while locking the original message in the buffer, using the specified timeout and lock duration.
Public method ReleaseLock(Message) Releases the lock on the specified message in the message buffer.
Public method ReleaseLock(Uri) Releases the lock on the message contained at the specified URI.
Public method Retrieve() () () () Retrieves the first message from the message buffer.
Public method Retrieve(TimeSpan) Retrieves the first message from the message buffer, using the specified timeout.
Public method Send(Message) Sends the specified message to the message buffer.
Public method Send(Message, TimeSpan) Sends the specified message, using the specified timeout.
Public method ToString (Inherited from Object.)

Top

Remarks

Important

The current Message Buffers feature, including their management protocol, will remain supported for backwards compatibility. However, the general recommendation is that you explicitly change client code to use the new Queue feature. For more information, see Service Bus Queues, Topics, and Subscriptions.

This type is the main interface for an application to interact with a Windows Azure Service Bus message buffer.

Through the message buffer client, you can create a message buffer, access an existing message buffer, as well as send and receive messages. When receiving a message, you have two options: a destructive read, which automatically deletes the message from the buffer, or a peek/lock. When you choose to peek/lock a message, a copy of the message is sent to the client. In addition, the message is held temporarily by the message buffer, but “locked” so that no one else can retrieve it. (During this time, you or other clients can still pull other messages from the buffer.) If the client does not explicitly instruct the message buffer to delete the locked message before the lock timeout expires, the message buffer releases the lock on the message. The message then goes back into the message buffer, where it can be retrieved again.

Message buffer contents are stored in active memory. Because of this, it is important to note that there are no fault tolerance or reliability guarantees. If the server hosting a message buffer crashes, you may lose messages. In the event of a server crash, you will not necessarily lose the buffer itself: knowledge of the buffer, including policy settings, is distributed across multiple servers and may be recovered. However, any messages in your buffer at the time of the crash will be lost. Therefore, if you are designing an application that needs a high degree of message reliability, it is recommended that you provide for message redundancy and recovery through other means.

For more information about the message buffer, see Working with an AppFabric Service Bus Message Buffer.

Examples

The following code describes using the message buffer client to send and receive messages.

string serviceNamespace = "myServiceNamespace";
MessageVersion messageVersion = MessageVersion.Soap12WSAddressing10;
string messageAction = "urn:Message";

// Configure credentials
TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior();
behavior.CredentialType = TransportClientCredentialType.SharedSecret;
behavior.Credentials.SharedSecret.IssuerName = "REPLACE WITH ISSUER NAME";
behavior.Credentials.SharedSecret.IssuerSecret = "REPLACE WITH ISSUER SECRET";

// Configure buffer policy
MessageBufferPolicy policy = new MessageBufferPolicy
{
    ExpiresAfter = TimeSpan.FromMinutes(2.0d),
    MaxMessageCount = 100
};

// Create buffer
Uri bufferName = new Uri("https://" + serviceNamespace + ".servicebus.windows.net/services/MyBuffer");
MessageBufferClient client = MessageBufferClient.CreateMessageBuffer(behavior, bufferName, policy, messageVersion);

// Send some messages
for (int i = 0; i < 10; ++i)
{
    client.Send(Message.CreateMessage(messageVersion, messageAction, "Message #" + i);
}

Message message;
string content;

// Retrieve a message (destructive read)
message = client.Retrieve();
content = message.GetBody<string>();
message.Close();

Console.WriteLine("Retrieve message content: {0}", content);

// Retrieve a message (peek/lock)
message = client.PeekLock();
content = message.GetBody<string>();

Console.WriteLine("PeekLock message content: {0}", content);

// Delete the peek-locked message
client.DeleteLockedMessage(message);
message.Close();

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.ServiceBus Namespace