QueueClient QueueClient QueueClient Class

Definition

QueueClient can be used for all basic interactions with a Service Bus Queue.

public class QueueClient : Microsoft.Azure.ServiceBus.ClientEntity, Microsoft.Azure.ServiceBus.IQueueClient
type QueueClient = class
    inherit ClientEntity
    interface IQueueClient
    interface IReceiverClient
    interface IClientEntity
    interface ISenderClient
Public Class QueueClient
Inherits ClientEntity
Implements IQueueClient
Inheritance
Implements

Examples

Create a new QueueClient


 IQueueClient queueClient = new QueueClient(
     namespaceConnectionString,
     queueName,
     ReceiveMode.PeekLock,
     RetryExponential);
 

Send a message to the queue:


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

Register a message handler which will be invoked every time a message is received.


 queueClient.RegisterMessageHandler(
        async (message, token) =>
        {
            // Process the message
            Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}");

            // Complete the message so that it is not received again.
            // This can be done only if the queueClient is opened in ReceiveMode.PeekLock mode.
            await queueClient.CompleteAsync(message.SystemProperties.LockToken);
        },
        async (exceptionEvent) =>
        {
            // Process the exception
            Console.WriteLine("Exception = " + exceptionEvent.Exception);
            return Task.CompletedTask;
        });
 

Remarks

Use MessageSender or MessageReceiver for advanced set of functionality. It uses AMQP protocol for communicating with servicebus.

Constructors

QueueClient(ServiceBusConnection, String, ReceiveMode, RetryPolicy) QueueClient(ServiceBusConnection, String, ReceiveMode, RetryPolicy) QueueClient(ServiceBusConnection, String, ReceiveMode, RetryPolicy)

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

QueueClient(ServiceBusConnectionStringBuilder, ReceiveMode, RetryPolicy) QueueClient(ServiceBusConnectionStringBuilder, ReceiveMode, RetryPolicy) QueueClient(ServiceBusConnectionStringBuilder, ReceiveMode, RetryPolicy)

Instantiates a new QueueClient to perform operations on a queue.

QueueClient(String, String, ITokenProvider, TransportType, ReceiveMode, RetryPolicy) QueueClient(String, String, ITokenProvider, TransportType, ReceiveMode, RetryPolicy) QueueClient(String, String, ITokenProvider, TransportType, ReceiveMode, RetryPolicy)

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

QueueClient(String, String, ReceiveMode, RetryPolicy) QueueClient(String, String, ReceiveMode, RetryPolicy) QueueClient(String, String, ReceiveMode, RetryPolicy)

Instantiates a new QueueClient to perform operations on a queue.

Properties

ClientId ClientId ClientId

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

(Inherited from ClientEntity)
IsClosedOrClosing IsClosedOrClosing IsClosedOrClosing

Returns true if the client is closed or closing.

(Inherited from ClientEntity)
OperationTimeout OperationTimeout OperationTimeout

Duration after which individual operations will timeout.

OwnsConnection OwnsConnection OwnsConnection

Returns true if connection is owned and false if connection is shared.

(Inherited from ClientEntity)
Path Path Path

Gets the name of the queue.

PrefetchCount PrefetchCount PrefetchCount

Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and before the application asks for one using Receive. Setting a non-zero value prefetches PrefetchCount number of messages. Setting the value to zero turns prefetch off. Defaults to 0.

QueueName QueueName QueueName

Gets the name of the queue.

ReceiveMode ReceiveMode ReceiveMode

Gets the ReceiveMode for the QueueClient.

RegisteredPlugins RegisteredPlugins RegisteredPlugins

Gets a list of currently registered plugins for this QueueClient.

RetryPolicy RetryPolicy RetryPolicy

Gets the RetryPolicy defined on the client.

(Inherited from ClientEntity)
ServiceBusConnection ServiceBusConnection ServiceBusConnection

Connection object to the service bus namespace.

Methods

AbandonAsync(String, IDictionary<String,Object>) AbandonAsync(String, IDictionary<String,Object>) AbandonAsync(String, IDictionary<String,Object>)

Abandons a Message using a lock token. This will make the message available again for processing.

CancelScheduledMessageAsync(Int64) CancelScheduledMessageAsync(Int64) CancelScheduledMessageAsync(Int64)

Cancels a message that was scheduled.

CloseAsync() CloseAsync() CloseAsync()

Closes the Client. Closes the connections opened by it.

(Inherited from ClientEntity)
CompleteAsync(String) CompleteAsync(String) CompleteAsync(String)

Completes a Message using its lock token. This will delete the message from the queue.

DeadLetterAsync(String, IDictionary<String,Object>) DeadLetterAsync(String, IDictionary<String,Object>) DeadLetterAsync(String, IDictionary<String,Object>)

Moves a message to the deadletter sub-queue.

DeadLetterAsync(String, String, String) DeadLetterAsync(String, String, String) DeadLetterAsync(String, String, String)

Moves a message to the deadletter sub-queue.

OnClosingAsync() OnClosingAsync() OnClosingAsync()
RegisterMessageHandler(Func<Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>) RegisterMessageHandler(Func<Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>) RegisterMessageHandler(Func<Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>)

Receive messages continuously from the entity. Registers a message handler and begins a new thread to receive messages. This handler(Func<T1,T2,TResult>) is awaited on every time a new message is received by the receiver.

RegisterMessageHandler(Func<Message,CancellationToken,Task>, MessageHandlerOptions) RegisterMessageHandler(Func<Message,CancellationToken,Task>, MessageHandlerOptions) RegisterMessageHandler(Func<Message,CancellationToken,Task>, MessageHandlerOptions)

Receive messages continuously from the entity. Registers a message handler and begins a new thread to receive messages. This handler(Func<T1,T2,TResult>) is awaited on every time a new message is received by the receiver.

RegisterPlugin(ServiceBusPlugin) RegisterPlugin(ServiceBusPlugin) RegisterPlugin(ServiceBusPlugin)

Registers a ServiceBusPlugin to be used with this queue client.

RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>) RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>) RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>)

Receive session messages continuously from the queue. Registers a message handler and begins a new thread to receive session-messages. This handler(Func<T1,T2,T3,TResult>) is awaited on every time a new message is received by the queue client.

RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, SessionHandlerOptions) RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, SessionHandlerOptions) RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, SessionHandlerOptions)

Receive session messages continuously from the queue. Registers a message handler and begins a new thread to receive session-messages. This handler(Func<T1,T2,T3,TResult>) is awaited on every time a new message is received by the queue client.

ScheduleMessageAsync(Message, DateTimeOffset) ScheduleMessageAsync(Message, DateTimeOffset) ScheduleMessageAsync(Message, DateTimeOffset)

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

SendAsync(IList<Message>) SendAsync(IList<Message>) SendAsync(IList<Message>)

Sends a list of messages to Service Bus.

SendAsync(Message) SendAsync(Message) SendAsync(Message)

Sends a message to Service Bus.

ThrowIfClosed() ThrowIfClosed() ThrowIfClosed()

Throw an OperationCanceledException if the object is Closing.

(Inherited from ClientEntity)
UnregisterPlugin(String) UnregisterPlugin(String) UnregisterPlugin(String)

Unregisters a ServiceBusPlugin.

Extension Methods

IsDefined(Object) IsDefined(Object) IsDefined(Object)

Determines if a certain property is defined or not.

IsNull(Object) IsNull(Object) IsNull(Object)

Determines if a certain property is null or not.

IsPrimitive(Object) IsPrimitive(Object) IsPrimitive(Object)

Determines if a certain property is of premitive JSON type.

Applies to