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
ServiceBusConnectionConnection object to the service bus namespace.
entityPath
stringTopic path.
retryPolicy
RetryPolicyRetry 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
ServiceBusConnectionStringBuilderServiceBusConnectionStringBuilder having namespace and topic information.
retryPolicy
RetryPolicyRetry 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
stringFully qualified domain name for Service Bus. Most likely, {yournamespace}.servicebus.windows.net
entityPath
stringTopic path.
tokenProvider
ITokenProviderToken provider which will generate security tokens for authorization.
transportType
TransportTypeTransport type.
retryPolicy
RetryPolicyRetry 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
stringNamespace connection string. Must not contain topic information.
entityPath
stringPath to the topic
retryPolicy
RetryPolicyRetry 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
Path
Gets the name of the topic.
public override string Path { get; }
Property Value
RegisteredPlugins
Gets a list of currently registered plugins for this TopicClient.
public override IList<ServiceBusPlugin> RegisteredPlugins { get; }
Property Value
ServiceBusConnection
Connection object to the service bus namespace.
public override ServiceBusConnection ServiceBusConnection { get; }
Property Value
TopicName
Gets the name of the topic.
public string TopicName { get; }
Property Value
Methods
CancelScheduledMessageAsync(long)
Cancels a message that was scheduled.
public Task CancelScheduledMessageAsync(long sequenceNumber)
Parameters
sequenceNumber
longThe SequenceNumber of the message to be cancelled.
Returns
OnClosingAsync()
protected override Task OnClosingAsync()
Returns
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
MessageThe Message that needs to be scheduled.
scheduleEnqueueTimeUtc
DateTimeOffsetThe UTC time at which the message should be available for processing.
Returns
SendAsync(Message)
Sends a message to Service Bus.
public Task SendAsync(Message message)
Parameters
message
Message
Returns
SendAsync(IList<Message>)
Sends a list of messages to Service Bus.
public Task SendAsync(IList<Message> messageList)
Parameters
Returns
UnregisterPlugin(string)
Unregisters a ServiceBusPlugin.
public override void UnregisterPlugin(string serviceBusPluginName)