Export (0) Print
Expand All

MessageBufferClient Class

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

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

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

public sealed class MessageBufferClient

The MessageBufferClient type exposes the following members.

  NameDescription
Public propertyMessageBufferUriRetrieves the URI for the message buffer.
Top

  NameDescription
Public methodStatic memberCreateMessageBuffer(TransportClientEndpointBehavior, Uri, MessageBufferPolicy)Creates a new message buffer on the Windows Azure Service Bus, using the specified credentials, URI, and policy.
Public methodStatic memberCreateMessageBuffer(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 methodDeleteLockedMessageDeletes the specified locked message from the message buffer.
Public methodDeleteMessageBufferDeletes the message buffer associated with this client.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodStatic memberGetMessageBuffer(TransportClientEndpointBehavior, Uri)Retrieves a message buffer client, based on the specified credentials and URI.
Public methodStatic memberGetMessageBuffer(TransportClientEndpointBehavior, Uri, MessageVersion)Retrieves a message buffer from the specified URI, using the specified credentials and message version.
Public methodGetPolicyRetrieves the policy of the message buffer with which the current instance is associated.
Public methodGetType (Inherited from Object.)
Public methodPeekLock()()()()Retrieves the first available message from the message buffer, and locks that message on the buffer.
Public methodPeekLock(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 methodPeekLock(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 methodReleaseLock(Message)Releases the lock on the specified message in the message buffer.
Public methodReleaseLock(Uri)Releases the lock on the message contained at the specified URI.
Public methodRetrieve()()()()Retrieves the first message from the message buffer.
Public methodRetrieve(TimeSpan)Retrieves the first message from the message buffer, using the specified timeout.
Public methodSend(Message)Sends the specified message to the message buffer.
Public methodSend(Message, TimeSpan)Sends the specified message, using the specified timeout.
Public methodToString (Inherited from Object.)
Top

Important noteImportant

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.

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();

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

Community Additions

Show:
© 2014 Microsoft