Class MessageSender
- Namespace
- Microsoft.Azure.ServiceBus.Core
- Assembly
- Microsoft.Azure.ServiceBus.dll
The MessageSender can be used to send messages to Queues or Topics.
public class MessageSender : ClientEntity, IMessageSender, ISenderClient, IClientEntity
- Inheritance
-
MessageSender
- Implements
- Inherited Members
Examples
Create a new MessageSender to send to a Queue
IMessageSender messageSender = new MessageSender(
namespaceConnectionString,
queueName)
Send message
byte[] data = GetData();
await messageSender.SendAsync(data);
Remarks
This uses AMQP protocol to communicate with service.
Constructors
MessageSender(ServiceBusConnection, string, RetryPolicy)
Creates a new AMQP MessageSender on a given ServiceBusConnection
public MessageSender(ServiceBusConnection serviceBusConnection, string entityPath, RetryPolicy retryPolicy = null)
Parameters
serviceBusConnection
ServiceBusConnectionConnection object to the service bus namespace.
entityPath
stringThe path of the entity this sender should connect to.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with Service Bus. Defaults to Default
MessageSender(ServiceBusConnection, string, string, RetryPolicy)
Creates a ViaMessageSender. This can be used to send messages to a destination entity via another another entity.
public MessageSender(ServiceBusConnection serviceBusConnection, string entityPath, string viaEntityPath, RetryPolicy retryPolicy = null)
Parameters
serviceBusConnection
ServiceBusConnectionConnection object to the service bus namespace.
entityPath
stringThe final destination of the message.
viaEntityPath
stringThe first destination of the message.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with Service Bus. Defaults to Default
Remarks
This is mainly to be used when sending messages in a transaction. When messages need to be sent across entities in a single transaction, this can be used to ensure all the messages land initially in the same entity/partition for local transactions, and then let service bus handle transferring the message to the actual destination.
MessageSender(ServiceBusConnectionStringBuilder, RetryPolicy)
Creates a new AMQP MessageSender.
public MessageSender(ServiceBusConnectionStringBuilder connectionStringBuilder, RetryPolicy retryPolicy = null)
Parameters
connectionStringBuilder
ServiceBusConnectionStringBuilderThe ServiceBusConnectionStringBuilder having entity level connection details.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with Service Bus. Defaults to Default
Remarks
Creates a new connection to the entity, which is opened during the first operation.
MessageSender(string, string, ITokenProvider, TransportType, RetryPolicy)
Creates a new MessageSender
public MessageSender(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
stringQueue path.
tokenProvider
ITokenProviderToken provider which will generate security tokens for authorization.
transportType
TransportTypeTransport type.
retryPolicy
RetryPolicyRetry policy for queue operations. Defaults to Default
Remarks
Creates a new connection to the entity, which is opened during the first operation.
MessageSender(string, string, RetryPolicy)
Creates a new AMQP MessageSender.
public MessageSender(string connectionString, string entityPath, RetryPolicy retryPolicy = null)
Parameters
connectionString
stringNamespace connection string used to communicate with Service Bus. Must not contain Entity details.
entityPath
stringThe path of the entity this sender should connect to.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with Service Bus. Defaults to Default
Remarks
Creates a new connection to the entity, which is opened during the first operation.
Properties
OperationTimeout
Duration after which individual operations will timeout.
public override TimeSpan OperationTimeout { get; set; }
Property Value
Path
Gets the entity path of the MessageSender.
public override string Path { get; }
Property Value
RegisteredPlugins
Gets a list of currently registered plugins for this sender.
public override IList<ServiceBusPlugin> RegisteredPlugins { get; }
Property Value
- See Also
ServiceBusConnection
Connection object to the service bus namespace.
public override ServiceBusConnection ServiceBusConnection { 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()
Closes the connection.
protected override Task OnClosingAsync()
Returns
RegisterPlugin(ServiceBusPlugin)
Registers a ServiceBusPlugin to be used with this sender.
public override void RegisterPlugin(ServiceBusPlugin serviceBusPlugin)
Parameters
serviceBusPlugin
ServiceBusPluginThe ServiceBusPlugin to register.
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 the entity as described by Path.
public Task SendAsync(Message message)
Parameters
message
Message
Returns
SendAsync(IList<Message>)
Sends a list of messages to the entity as described by Path.
public Task SendAsync(IList<Message> messageList)
Parameters
Returns
UnregisterPlugin(string)
Unregisters a ServiceBusPlugin.
public override void UnregisterPlugin(string serviceBusPluginName)