TopicClient TopicClient Class

Definition

An anchor class used to access a TopicDescription to perform run-time operations.

public abstract class TopicClient : ClientEntity, IMessageClientEntity, ICloseable, IMessageSender, IMessageBrowserPublic MustInherit Class TopicClient
    Inherits ClientEntity
    Implements IMessageClientEntity, ICloseable, IMessageSender, IMessageBrowser
Inheritance
TopicClientTopicClient

Inherited Members

Microsoft.ServiceBus.Messaging.ClientEntity

System.Object

Examples

// Create settings for the MessagingFactory (for rutime operations)
MessagingFactorySettings factorySettings = new MessagingFactorySettings()
{
   NetMessagingTransportSettings = new NetMessagingTransportSettings(),
   Credential = TransportClientCredentialBase.CreateSharedSecretCredential(IssuerName, IssuerKey),
};

// Create the MessagingFactory
MessagingFactory factory = 
MessagingFactory.Create(myServiceBusNamespace, factorySettings);

//********************************************************************************
//                          Sending messages to a Topic
//********************************************************************************

// Create topic client
TopicClient myTopicClient = factory.CreateTopicClient(myTopic);

// Create a sender
//MessageSender myMessageSender = myTopicClient.CreateSender(SendMode.Default);

// Send messages
List <object> Issues = new List <object>();
foreach (var issue in Issues)
{
   myMessageSender.Send(new BrokeredMessage(issue));
}

Properties

IsSubQueue IsSubQueue

Gets or sets a value that indicates whether the message receiver is created from a subqueue.

protected bool IsSubQueue { get; }Protected ReadOnly Property IsSubQueue As Boolean
Value
Boolean Boolean

true if the message receiver is created from a subqueue; otherwise, false.

MessagingFactory MessagingFactory

Gets or sets the messaging factory that was used in creating this TopicClient object.

public MessagingFactory MessagingFactory { get; }Public ReadOnly Property MessagingFactory As MessagingFactory
Value
MessagingFactory MessagingFactory

The messaging factory that was used in creating this TopicClient object.

Path Path

Gets or sets the full pathname of the file.

public string Path { get; }Public ReadOnly Property Path As String
Value
String String

The full pathname of the file.

Methods

CancelScheduledMessageAsync(Int64) CancelScheduledMessageAsync(Int64)

Cancels a scheduled message

public Task CancelScheduledMessageAsync(long sequenceNumber)Public Function CancelScheduledMessageAsync(sequenceNumber As Long) As Task
Parameters
sequenceNumber
Int64 Int64

Returned on scheduling a message.

Returns

Create(String) Create(String)

Creates a new instance of TopicClient.

public static TopicClient Create(string path)Public Shared Function Create(path As String) As TopicClient
Parameters
path
String String

The path.

Returns

Remarks

This method will attempt to retrieve the connection string information from either app.config, or web.config files. User must supply the connection string using the "AppSettings" section of the configuration. The format of the section is as follows:




CreateFromConnectionString(String) CreateFromConnectionString(String)

Creates a new instance of TopicClient using the specified connection string.

public static TopicClient CreateFromConnectionString(string connectionString)Public Shared Function CreateFromConnectionString(connectionString As String) As TopicClient
Parameters
connectionString
String String

The connection string to use.

Returns

Remarks

This method expects the connection string supplied has entity level information such as the entity path and authentication information supplied.

CreateFromConnectionString(String, String) CreateFromConnectionString(String, String)

Creates a new instance of TopicClient using the specified connection string and path to the topic. Use this overload only when the connection string does not use the EntityPath property.

public static TopicClient CreateFromConnectionString(string connectionString, string path)Public Shared Function CreateFromConnectionString(connectionString As String, path As String) As TopicClient
Parameters
connectionString
String String

The connection string to use.

path
String String

The path.

Returns
Exceptions

Thrown when the format of the parameters is incorrect.

Remarks

This method should only be used with a connection string that has namespace level authentication because the connection string supplied should not have entity level information associated with it.

FormatTransferDeadLetterPath(String) FormatTransferDeadLetterPath(String)

A utility method that, given the topic path and subscription name, forms a full path that points to the dead letter queue of the topic's transfer topic.

public static string FormatTransferDeadLetterPath(string topicPath)Public Shared Function FormatTransferDeadLetterPath(topicPath As String) As String
Parameters
topicPath
String String

The topic path.

Returns

Returns a String representing a full path that points to the dead letter queue of the transfer topic of the specified topic. This path can be used in receiver creation or in URI formation (such as a REST URI).

OnAbort() OnAbort()

Executes the abort action.

protected override void OnAbort()Protected Overrides Sub OnAbort
Overrides

OnBeginClose(TimeSpan, AsyncCallback, Object) OnBeginClose(TimeSpan, AsyncCallback, Object)

Executes the begin close action.

protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)Protected Overrides Function OnBeginClose(timeout As TimeSpan, callback As AsyncCallback, state As Object) As IAsyncResult
Parameters
timeout
TimeSpan TimeSpan

The wait time before the operation times out.

callback
AsyncCallback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state
Object Object

A user-defined object that contains information about the receive operation. This object is passed to the EndClose delegate when the operation is complete.

Returns

An IAsyncResult that references the asynchronous Close operation.

Overrides

OnBeginCreateSender(TimeSpan, AsyncCallback, Object) OnBeginCreateSender(TimeSpan, AsyncCallback, Object)

Executes the begin create sender action.

protected abstract IAsyncResult OnBeginCreateSender(TimeSpan timeout, AsyncCallback callback, object state)Protected MustOverride Function OnBeginCreateSender(timeout As TimeSpan, callback As AsyncCallback, state As Object) As IAsyncResult
Parameters
timeout
TimeSpan TimeSpan

The wait time before the operation times out.

callback
AsyncCallback AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state
Object Object

A user-defined object that contains information about the receive operation. This object is passed to the Microsoft.ServiceBus.Messaging.TopicClient.EndCreateSender(System.IAsyncResult) when the operation is complete.

Returns

An IAsyncResult that references the asynchronous parent method.

OnClose(TimeSpan) OnClose(TimeSpan)

Executes the close action.

protected override void OnClose(TimeSpan timeout)Protected Overrides Sub OnClose(timeout As TimeSpan)
Parameters
timeout
TimeSpan TimeSpan

The wait time before the operation times out.

Overrides

OnEndClose(IAsyncResult) OnEndClose(IAsyncResult)

Executes the end close action.

protected override void OnEndClose(IAsyncResult result)Protected Overrides Sub OnEndClose(result As IAsyncResult)
Parameters
result
IAsyncResult IAsyncResult

An IAsyncResult that references the asynchronous Close operation.

Overrides

OnEndCreateSender(IAsyncResult) OnEndCreateSender(IAsyncResult)

Executes the end create sender action.

protected abstract MessageSender OnEndCreateSender(IAsyncResult result)Protected MustOverride Function OnEndCreateSender(result As IAsyncResult) As MessageSender
Parameters
result
IAsyncResult IAsyncResult

An IAsyncResult that references the asynchronous parent method.

Returns

The newly created MessageSender object.

Peek() Peek()

Peeks a BrokeredMessage from current queue/topic.

public BrokeredMessage Peek()Public Function Peek As BrokeredMessage
Returns

return the peeked BrokeredMessage. A null is return if peek operation cannot obtain the message within OperationTimeout.

Remarks

A Null can be return by this API if operation exceeded the timeout specified, or the operations succeeded but there are no more messages to be received.

Peek(Int64) Peek(Int64)

Peeks a BrokeredMessage from current queue/topic.

public BrokeredMessage Peek(long fromSequenceNumber)Public Function Peek(fromSequenceNumber As Long) As BrokeredMessage
Parameters
fromSequenceNumber
Int64 Int64

The sequence number of message to start peeking from.

Returns

return the peeked BrokeredMessage. A null is return if peek operation cannot obtain the message within OperationTimeout.

Remarks

A Null can be return by this API if operation exceeded the timeout specified, or the operations succeeded but there are no more messages to be received.

PeekAsync() PeekAsync()

public Task<BrokeredMessage> PeekAsync()Public Function PeekAsync As Task(Of BrokeredMessage)
Returns

PeekAsync(Int64) PeekAsync(Int64)

public Task<BrokeredMessage> PeekAsync(long fromSequenceNumber)Public Function PeekAsync(fromSequenceNumber As Long) As Task(Of BrokeredMessage)
Parameters
fromSequenceNumber
Int64 Int64
Returns

PeekBatch(Int32) PeekBatch(Int32)

Peeks a BrokeredMessage from current queue/topic.

public IEnumerable<BrokeredMessage> PeekBatch(int messageCount)Public Function PeekBatch(messageCount As Integer) As IEnumerable(Of BrokeredMessage)
Parameters
messageCount
Int32 Int32

The maximum number of messages to peek.

Returns

return a list of peeked BrokeredMessages. An empty list is returned if peek operation cannot obtain the message within OperationTimeout.

Remarks

A Null can be return by this API if operation exceeded the timeout specified, or the operations succeeded but there are no more messages to be received.

PeekBatch(Int64, Int32) PeekBatch(Int64, Int32)

public IEnumerable<BrokeredMessage> PeekBatch(long fromSequenceNumber, int messageCount)Public Function PeekBatch(fromSequenceNumber As Long, messageCount As Integer) As IEnumerable(Of BrokeredMessage)
Parameters
fromSequenceNumber
Int64 Int64
messageCount
Int32 Int32
Returns

PeekBatchAsync(Int32) PeekBatchAsync(Int32)

public Task<IEnumerable<BrokeredMessage>> PeekBatchAsync(int messageCount)Public Function PeekBatchAsync(messageCount As Integer) As Task(Of IEnumerable(Of BrokeredMessage))
Parameters
messageCount
Int32 Int32
Returns

PeekBatchAsync(Int64, Int32) PeekBatchAsync(Int64, Int32)

public Task<IEnumerable<BrokeredMessage>> PeekBatchAsync(long fromSequenceNumber, int messageCount)Public Function PeekBatchAsync(fromSequenceNumber As Long, messageCount As Integer) As Task(Of IEnumerable(Of BrokeredMessage))
Parameters
fromSequenceNumber
Int64 Int64
messageCount
Int32 Int32
Returns

ScheduleMessageAsync(BrokeredMessage, DateTimeOffset) ScheduleMessageAsync(BrokeredMessage, DateTimeOffset)

Sends a scheduled message

public Task<long> ScheduleMessageAsync(BrokeredMessage message, DateTimeOffset scheduleEnqueueTimeUtc)Public Function ScheduleMessageAsync(message As BrokeredMessage, scheduleEnqueueTimeUtc As DateTimeOffset) As Task(Of Long)
Parameters
message
BrokeredMessage BrokeredMessage

Message to be scheduled

scheduleEnqueueTimeUtc
DateTimeOffset DateTimeOffset

Time of enqueue

Returns

Sequence number that is needed for cancelling.

Send(BrokeredMessage) Send(BrokeredMessage)

Sends a message using the Microsoft.ServiceBus.Messaging.QueueClient.InternalSender.

public void Send(BrokeredMessage message)Public Sub Send(message As BrokeredMessage)
Parameters
message
BrokeredMessage BrokeredMessage

The message to send.

Exceptions

Thrown when operation times out. Timeout period is initialized through the OperationTimeout to avoid this exception if timeout value is relatively low.

Thrown if the message has already been sent by a TopicClient or MessageSender once already.

Thrown if the client entity has been closed or aborted.

Thrown if there is an I/O or security error.

Thrown when an error occurs during serialization or deserialization.

Thrown if there is a messaging error.

SendAsync(BrokeredMessage) SendAsync(BrokeredMessage)

Asynchronously sends a message using the Microsoft.ServiceBus.Messaging.QueueClient.InternalSender.

public Task SendAsync(BrokeredMessage message)Public Function SendAsync(message As BrokeredMessage) As Task
Parameters
message
BrokeredMessage BrokeredMessage

The message to send.

Returns

The asynchronous result of the operation.

SendBatch(IEnumerable<BrokeredMessage>) SendBatch(IEnumerable(Of BrokeredMessage))

Sends a set of brokered messages (for batch processing).

public void SendBatch(IEnumerable<BrokeredMessage> messages)Public Sub SendBatch(messages As IEnumerable(Of BrokeredMessage))
Parameters
messages
IEnumerable<BrokeredMessage> IEnumerable(Of BrokeredMessage)

The messages to send.

SendBatchAsync(IEnumerable<BrokeredMessage>) SendBatchAsync(IEnumerable(Of BrokeredMessage))

Asynchronously sends a set of brokered messages (for batch processing).

public Task SendBatchAsync(IEnumerable<BrokeredMessage> messages)Public Function SendBatchAsync(messages As IEnumerable(Of BrokeredMessage)) As Task
Parameters
messages
IEnumerable<BrokeredMessage> IEnumerable(Of BrokeredMessage)

The messages to send.

Returns

The asynchronous result of the operation.

See Also