Table of Contents

Class TopicClient

Namespace
Microsoft.Azure.ServiceBus
Assembly
Microsoft.Azure.ServiceBus.dll

TopicClient can be used for all basic interactions with a Service Bus topic.

public class TopicClient : ClientEntity, ITopicClient, ISenderClient, IClientEntity
Inheritance
TopicClient
Implements
Inherited Members

Examples

Create a new TopicClient

ITopicClient topicClient = new TopicClient(
    namespaceConnectionString,
    topicName,
    RetryExponential);

Send a message to the topic:

byte[] data = GetData();
await topicClient.SendAsync(data);

Remarks

It uses AMQP protocol for communicating with servicebus.

Constructors

TopicClient(ServiceBusConnection, string, RetryPolicy)

Creates a new instance of the Topic client on a given ServiceBusConnection

public TopicClient(ServiceBusConnection serviceBusConnection, string entityPath, RetryPolicy retryPolicy)

Parameters

serviceBusConnection ServiceBusConnection

Connection object to the service bus namespace.

entityPath string

Topic path.

retryPolicy RetryPolicy

Retry policy for topic operations. Defaults to Default

TopicClient(ServiceBusConnectionStringBuilder, RetryPolicy)

Instantiates a new TopicClient to perform operations on a topic.

public TopicClient(ServiceBusConnectionStringBuilder connectionStringBuilder, RetryPolicy retryPolicy = null)

Parameters

connectionStringBuilder ServiceBusConnectionStringBuilder

ServiceBusConnectionStringBuilder having namespace and topic information.

retryPolicy RetryPolicy

Retry policy for topic operations. Defaults to Default

Remarks

Creates a new connection to the topic, which is opened during the first send operation.

TopicClient(string, string, ITokenProvider, TransportType, RetryPolicy)

Creates a new instance of the Topic client using the specified endpoint, entity path, and token provider.

public TopicClient(string endpoint, string entityPath, ITokenProvider tokenProvider, TransportType transportType = TransportType.Amqp, RetryPolicy retryPolicy = null)

Parameters

endpoint string

Fully qualified domain name for Service Bus. Most likely, {yournamespace}.servicebus.windows.net

entityPath string

Topic path.

tokenProvider ITokenProvider

Token provider which will generate security tokens for authorization.

transportType TransportType

Transport type.

retryPolicy RetryPolicy

Retry policy for topic operations. Defaults to Default

Remarks

Creates a new connection to the topic, which is opened during the first send operation.

TopicClient(string, string, RetryPolicy)

Instantiates a new TopicClient to perform operations on a topic.

public TopicClient(string connectionString, string entityPath, RetryPolicy retryPolicy = null)

Parameters

connectionString string

Namespace connection string. Must not contain topic information.

entityPath string

Path to the topic

retryPolicy RetryPolicy

Retry policy for topic operations. Defaults to Default

Remarks

Creates a new connection to the topic, which is opened during the first send operation.

Properties

OperationTimeout

Duration after which individual operations will timeout.

public override TimeSpan OperationTimeout { get; set; }

Property Value

TimeSpan

Path

Gets the name of the topic.

public override string Path { get; }

Property Value

string

RegisteredPlugins

Gets a list of currently registered plugins for this TopicClient.

public override IList<ServiceBusPlugin> RegisteredPlugins { get; }

Property Value

IList<ServiceBusPlugin>

ServiceBusConnection

Connection object to the service bus namespace.

public override ServiceBusConnection ServiceBusConnection { get; }

Property Value

ServiceBusConnection

TopicName

Gets the name of the topic.

public string TopicName { get; }

Property Value

string

Methods

CancelScheduledMessageAsync(long)

Cancels a message that was scheduled.

public Task CancelScheduledMessageAsync(long sequenceNumber)

Parameters

sequenceNumber long

The SequenceNumber of the message to be cancelled.

Returns

Task

OnClosingAsync()

protected override Task OnClosingAsync()

Returns

Task

RegisterPlugin(ServiceBusPlugin)

Registers a ServiceBusPlugin to be used with this topic client.

public override void RegisterPlugin(ServiceBusPlugin serviceBusPlugin)

Parameters

serviceBusPlugin ServiceBusPlugin

ScheduleMessageAsync(Message, DateTimeOffset)

Schedules a message to appear on Service Bus at a later time.

public Task<long> ScheduleMessageAsync(Message message, DateTimeOffset scheduleEnqueueTimeUtc)

Parameters

message Message

The Message that needs to be scheduled.

scheduleEnqueueTimeUtc DateTimeOffset

The UTC time at which the message should be available for processing.

Returns

Task<long>

The sequence number of the message that was scheduled.

SendAsync(Message)

Sends a message to Service Bus.

public Task SendAsync(Message message)

Parameters

message Message

Returns

Task

SendAsync(IList<Message>)

Sends a list of messages to Service Bus.

public Task SendAsync(IList<Message> messageList)

Parameters

messageList IList<Message>

Returns

Task

UnregisterPlugin(string)

Unregisters a ServiceBusPlugin.

public override void UnregisterPlugin(string serviceBusPluginName)

Parameters

serviceBusPluginName string

The name Name to be unregistered