Udostępnij za pośrednictwem


MessageReceiver Class

Definition

The MessageReceiver class is used to receive messages from the message container and acknowledge them.

public abstract class MessageReceiver : Microsoft.ServiceBus.Messaging.MessagingEntityClient
type MessageReceiver = class
    inherit MessagingEntityClient
Public MustInherit Class MessageReceiver
Inherits MessagingEntityClient
Inheritance
Derived

Remarks

Please note that message delivery mechanism does not provide by default all time reliable message receiving. Service Bus deletes the message once it goes out of the system. For a guaranteed delivery, you can use the PeekLock delivery mode.

//********************************************************************************
//                             Sending messages to a Queue
//********************************************************************************

// Create a sender
MessageSender myMessageSender = myQueueClient.CreateSender(SendMode.Default);

// Send messages
List<string> Issues = new List<string>();
foreach (var issue in Issues)
{
myMessageSender.Send(new BrokeredMessage(issue));
}
//********************************************************************************
//                           Recieving messages from a Queue
//********************************************************************************

// Create a receiver
MessageReceiver myMessageReceiver = 
myQueueClient.CreateReceiver(ReceiveMode.PeekLock);

// Receive messages
for (int count = 0; count < Issues.Count; count++)
{
var message = myMessageReceiver.Receive();
message.Complete();
}
//********************************************************************************
//                    Receiving messages from a particular session
//********************************************************************************

// Create subscription client
SubscriptionClient mySubscriptionClient = factory.CreateSubscriptionClient(mySubscription);

// Create a receiver
MessageReceiver myMessageReceiver = mySubscriptionClient.AcceptMessageSession(ReceiveMode.PeekLock);

// Receive messages
for (int count = 0; count *lt; Issues.Count; count++)
{
var message = myMessageReceiver.Receive();
message.Complete();
}

Properties

BatchFlushInterval

Gets the batch flush interval.

BatchingEnabled

Gets a value indicating whether the batching is enabled.

IsClosed (Inherited from ClientEntity)
LastPeekedSequenceNumber

Gets or sets the sequence number of the message last peeked.

Mode

Gets the message receive mode.

Path

Gets the queue's, topic's, or subscription's path relative to the MessagingFactory base address.

(Inherited from MessagingEntityClient)
PrefetchCount

Gets or sets the number of messages that the message receiver can simultaneously request.

RefreshEntityRuntimeDescription
RetryPolicy (Inherited from ClientEntity)
SupportsGetRuntimeEntityDescription
ThisLock (Inherited from ClientEntity)

Methods

Abandon(Guid, IDictionary<String,Object>)

Discards the message and relinquishes the message lock ownership.

Abandon(Guid)

Discards the message and relinquishes the message lock ownership.

AbandonAsync(Guid, IDictionary<String,Object>)

Asynchronously discards the message and relinquishes the message lock ownership.

AbandonAsync(Guid)

Asynchronously discards the message and relinquishes the message lock ownership.

Abort()

Performs abort functionality on the messaging entity.

(Inherited from ClientEntity)
Close()

Sends a cleanup message to Service Bus to signal the completion of the usage of an entity.

(Inherited from ClientEntity)
CloseAsync()

Sends a cleanup message asynchronously to Service Bus to signal the completion of the usage of an entity.

(Inherited from ClientEntity)
Complete(Guid)

Completes the receive operation on a message. If using AMQP, this operation can only be performed on messages that were received by this receiver.

CompleteAsync(Guid)

Asynchronously completes the receive operation on a message. If using AMQP, this operation can only be performed on messages that were received by this receiver.

CompleteBatch(IEnumerable<Guid>)

Completes the receive operation on a batch of message. If using AMQP, this operation can only be performed on messages that were received by this receiver.

CompleteBatchAsync(IEnumerable<Guid>)

Asynchronously completes the receive operation on a batch of message. If using AMQP, this operation can only be performed on messages that were received by this receiver.

DeadLetter(Guid, IDictionary<String,Object>)

Moves the undelivered message to the dead letter queue.

DeadLetter(Guid, String, String)

Moves the undelivered message to the dead letter queue.

DeadLetter(Guid)

Moves the undelivered message to the dead letter queue.

DeadLetterAsync(Guid, IDictionary<String,Object>)

Asynchronously moves the undelivered message to the dead letter queue.

DeadLetterAsync(Guid, String, String)

Asynchronously moves the undelivered message to the dead letter queue.

DeadLetterAsync(Guid)

Asynchronously moves the undelivered message to the dead letter queue.

Defer(Guid, IDictionary<String,Object>)

Indicates that the receiver wants to defer the processing for the message.

Defer(Guid)

Indicates that the receiver wants to defer the processing for the message.

DeferAsync(Guid, IDictionary<String,Object>)

Asynchronously defer the processing of the message.

DeferAsync(Guid)

Asynchronously defer the processing of the message.

Fault()

For internal use only. Do not inherit from this class.

(Inherited from ClientEntity)
GetLockToken(BrokeredMessage)

Gets the lock token bound to the message.

GetLockTokens(IEnumerable<BrokeredMessage>)

Gets the collection of lock tokens from the specified collection of messages.

GetProperty<T>()
OnAbandon(TrackingContext, IEnumerable<Guid>, IDictionary<String,Object>, TimeSpan)

Executes the abandon action.

OnAbort() (Inherited from ClientEntity)
OnBeginAbandon(TrackingContext, IEnumerable<Guid>, IDictionary<String,Object>, Boolean, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnAbandon or BeginAbandon operation.

OnBeginClose(TimeSpan, AsyncCallback, Object) (Inherited from ClientEntity)
OnBeginComplete(TrackingContext, IEnumerable<ArraySegment<Byte>>, Boolean, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnComplete or BeginComplete operation.

OnBeginComplete(TrackingContext, IEnumerable<Guid>, Boolean, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnComplete or BeginComplete operation.

OnBeginDeadLetter(TrackingContext, IEnumerable<Guid>, IDictionary<String,Object>, String, String, Boolean, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnDeadLetter or BeginDeadLetter operation.

OnBeginDefer(TrackingContext, IEnumerable<Guid>, IDictionary<String,Object>, Boolean, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnDefer or BeginDefer operation.

OnBeginOpen(TimeSpan, AsyncCallback, Object) (Inherited from ClientEntity)
OnBeginPeek(TrackingContext, Int64, Int32, TimeSpan, AsyncCallback, Object)

Executes upon calling the BeginPeek operation.

OnBeginRenewMessageLocks(TrackingContext, IEnumerable<Guid>, Boolean, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnBegin operation for lock messages.

OnBeginTryReceive(TrackingContext, IEnumerable<Int64>, TimeSpan, AsyncCallback, Object)

Executes the begin try receive action.

OnBeginTryReceive(TrackingContext, Int32, TimeSpan, AsyncCallback, Object)

Executes the begin try receive action.

OnBeginTryReceive2(TrackingContext, Int32, TimeSpan, AsyncCallback, Object)

Executes the begin try receive action.

OnBeginTryReceiveEventData(TrackingContext, Int32, TimeSpan, AsyncCallback, Object)

Executes upon calling the OnTryReceive or BeginTryReceive operation for the event data.

OnClose(TimeSpan) (Inherited from ClientEntity)
OnClosed() (Inherited from ClientEntity)
OnComplete(TrackingContext, IEnumerable<Guid>, TimeSpan)

Executes the complete action.

OnDeadLetter(TrackingContext, IEnumerable<Guid>, IDictionary<String,Object>, String, String, TimeSpan)

Executes the move to dead letter queue action.

OnDefer(TrackingContext, IEnumerable<Guid>, IDictionary<String,Object>, TimeSpan)

Executes the defer action.

OnEndAbandon(IAsyncResult)

Executes the end abandon action.

OnEndClose(IAsyncResult) (Inherited from ClientEntity)
OnEndComplete(IAsyncResult)

Executes the end complete action.

OnEndDeadLetter(IAsyncResult)

Executes the end move to dead letter queue action.

OnEndDefer(IAsyncResult)

Executes the end defer action.

OnEndOpen(IAsyncResult) (Inherited from ClientEntity)
OnEndPeek(IAsyncResult)

Executes the EndPeek operation.

OnEndRenewMessageLocks(IAsyncResult)

Executes the EndRenew action for message locks.

OnEndTryReceive(IAsyncResult, IEnumerable<BrokeredMessage>)

Executes the end try receive action.

OnEndTryReceive2(IAsyncResult, IEnumerable<BrokeredMessage>)

Executes the end try receive action.

OnEndTryReceiveEventData(IAsyncResult, IEnumerable<EventData>)

Executes the EndTryReceive action for the event data.

OnFaulted() (Inherited from ClientEntity)
OnMessage(Action<BrokeredMessage>, OnMessageOptions)

Processes a message in an event-driven message pump.

OnMessageAsync(Func<BrokeredMessage,Task>, OnMessageOptions)

Asynchronously processes a message in an event-driven message pump.

OnOpen(TimeSpan) (Inherited from ClientEntity)
OnOpened() (Inherited from ClientEntity)
OnPeek(TrackingContext, Int64, Int32, TimeSpan)

Executes upon calling the Peek operation.

OnRenewMessageLocks(TrackingContext, IEnumerable<Guid>, TimeSpan)

Executes the Renew action for lock messages.

OnTryReceive(TrackingContext, IEnumerable<Int64>, TimeSpan, IEnumerable<BrokeredMessage>)

Executes the try receive action.

OnTryReceive(TrackingContext, Int32, TimeSpan, IEnumerable<BrokeredMessage>)

Executes the try receive action.

Peek()

Reads the next message without changing the state of the receiver or the message source.

Peek(Int64)

Reads the next message without changing the state of the receiver or the message source.

PeekAsync()

Asynchronously reads the next message without changing the state of the receiver or the message source.

PeekAsync(Int64)

Asynchronously reads the next message without changing the state of the receiver or the message source.

PeekBatch(Int32)

Reads the next batch of message without changing the state of the receiver or the message source.

PeekBatch(Int64, Int32)

Reads the next batch of message without changing the state of the receiver or the message source.

PeekBatchAsync(Int32)

Asynchronously reads the next batch of message without changing the state of the receiver or the message source.

PeekBatchAsync(Int64, Int32)

Asynchronously reads the next batch of message without changing the state of the receiver or the message source.

Receive()

Receives a BrokeredMessage from the current queue or topic.

Receive(Int64)

Receives a deferred message from the current queue or topic. This method only works for deferred message, not regular one.

Receive(TimeSpan)

Receives a BrokeredMessage from the current queue or topic.

ReceiveAsync()

Asynchronously receives a message from the current queue or topic.

ReceiveAsync(Int64)

Asynchronously receives a deferred message from the current queue or topic. This method only works for deferred message, not regular one.

ReceiveAsync(TimeSpan)

Asynchronously receives a message from the current queue or topic.

ReceiveBatch(IEnumerable<Int64>)

Receives a batch of messages.

ReceiveBatch(Int32, TimeSpan)

Receives a batch of messages.

ReceiveBatch(Int32)

Receives a batch of messages.

ReceiveBatchAsync(IEnumerable<Int64>)

Asynchronously receives a batch of messages.

ReceiveBatchAsync(Int32, TimeSpan)

Asynchronously receives a batch of messages.

ReceiveBatchAsync(Int32)

Asynchronously receives a batch of messages.

ThrowIfClosed() (Inherited from ClientEntity)
ThrowIfDisposed() (Inherited from ClientEntity)
ThrowIfDisposedOrImmutable() (Inherited from ClientEntity)
ThrowIfDisposedOrNotOpen() (Inherited from ClientEntity)
ThrowIfFaulted() (Inherited from ClientEntity)

Applies to