Udostępnij za pośrednictwem


ServiceBusSender Class

Definition

A client responsible for sending ServiceBusMessage to a specific Service Bus entity (Queue or Topic). It can be used for both session and non-session entities. It is constructed by calling CreateSender(String).

public class ServiceBusSender : IAsyncDisposable
type ServiceBusSender = class
    interface IAsyncDisposable
Public Class ServiceBusSender
Implements IAsyncDisposable
Inheritance
ServiceBusSender
Implements

Remarks

The ServiceBusSender is safe to cache and use for the lifetime of an application or until the ServiceBusClient that it was created by is disposed. Caching the sender is recommended when the application is publishing messages regularly or semi-regularly. The sender is responsible for ensuring efficient network, CPU, and memory use. Calling DisposeAsync() on the associated ServiceBusClient as the application is shutting down will ensure that network resources and other unmanaged objects used by the sender are properly cleaned up.

Constructors

ServiceBusSender()

Initializes a new instance of the ServiceBusSender class for mocking.

ServiceBusSender(ServiceBusClient, String, ServiceBusSenderOptions)

Initializes a new instance of the ServiceBusSender class for use with derived types.

ServiceBusSender(ServiceBusClient, String)

Initializes a new instance of the ServiceBusSender class for use with derived types.

Properties

EntityPath

The path of the entity that the sender is connected to, specific to the Service Bus namespace that contains it.

FullyQualifiedNamespace

The fully qualified Service Bus namespace that the producer is associated with. This is likely to be similar to {yournamespace}.servicebus.windows.net.

Identifier

Gets the ID to identify this client. This can be used to correlate logs and exceptions.

IsClosed

Indicates whether or not this ServiceBusSender has been closed.

Methods

CancelScheduledMessageAsync(Int64, CancellationToken)

Cancels a message that was scheduled.

CancelScheduledMessagesAsync(IEnumerable<Int64>, CancellationToken)

Cancels a set of messages that were scheduled.

CloseAsync(CancellationToken)

Performs the task needed to clean up resources used by the ServiceBusSender.

CreateMessageBatchAsync(CancellationToken)

Creates a size-constraint batch to which ServiceBusMessage may be added using a TryAddMessage(ServiceBusMessage). If a message would exceed the maximum allowable size of the batch, the batch will not allow adding the message and signal that scenario using it return value.

Because messages that would violate the size constraint cannot be added, publishing a batch will not trigger an exception when attempting to send the messages to the Queue/Topic.

CreateMessageBatchAsync(CreateMessageBatchOptions, CancellationToken)

Creates a size-constraint batch to which ServiceBusMessage may be added using a try-based pattern. If a message would exceed the maximum allowable size of the batch, the batch will not allow adding the message and signal that scenario using its return value.

Because messages that would violate the size constraint cannot be added, publishing a batch will not trigger an exception when attempting to send the messages to the Queue/Topic.

DisposeAsync()

Performs the task needed to clean up resources used by the ServiceBusSender. This is equivalent to calling CloseAsync(CancellationToken).

ScheduleMessageAsync(ServiceBusMessage, DateTimeOffset, CancellationToken)

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

ScheduleMessagesAsync(IEnumerable<ServiceBusMessage>, DateTimeOffset, CancellationToken)

Schedules a set of messages to appear on Service Bus at a later time.

SendMessageAsync(ServiceBusMessage, CancellationToken)

Sends a message to the associated entity of Service Bus.

SendMessagesAsync(IEnumerable<ServiceBusMessage>, CancellationToken)

Sends a set of messages to the associated Service Bus entity using a batched approach. If the size of the messages exceed the maximum size of a single batch, an exception will be triggered and the send will fail. In order to ensure that the messages being sent will fit in a batch, use SendMessagesAsync(ServiceBusMessageBatch, CancellationToken) instead.

SendMessagesAsync(ServiceBusMessageBatch, CancellationToken)

Sends a ServiceBusMessageBatch containing a set of ServiceBusMessage to the associated Service Bus entity.

Applies to