Class ReceiverLink
The ReceiverLink class represents a link that accepts incoming messages.
Inherited Members
Namespace: Amqp
Assembly: Amqp.Net.dll
Syntax
public class ReceiverLink : Link, IReceiverLink, ILink, IAmqpObject
Constructors
ReceiverLink(Session, String, Attach, OnAttached)
Initializes a receiver link.
Declaration
public ReceiverLink(Session session, string name, Attach attach, OnAttached onAttached)
Parameters
Type | Name | Description |
---|---|---|
Session | session | The session within which to create the link. |
System.String | name | The link name. |
Attach | attach | The attach frame to send for this link. |
OnAttached | onAttached | The callback to invoke when an attach is received from peer. |
ReceiverLink(Session, String, Source, OnAttached)
Initializes a receiver link.
Declaration
public ReceiverLink(Session session, string name, Source source, OnAttached onAttached)
Parameters
Type | Name | Description |
---|---|---|
Session | session | The session within which to create the link. |
System.String | name | The link name. |
Source | source | The source on attach that specifies the message source. |
OnAttached | onAttached | The callback to invoke when an attach is received from peer. |
ReceiverLink(Session, String, String)
Initializes a receiver link.
Declaration
public ReceiverLink(Session session, string name, string address)
Parameters
Type | Name | Description |
---|---|---|
Session | session | The session within which to create the link. |
System.String | name | The link name. |
System.String | address | The node address. |
Methods
Accept(Message)
Accepts a message. It sends an accepted outcome to the peer.
Declaration
public void Accept(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to accept. |
Complete(Message, DeliveryState)
Completes a received message. It settles the delivery and sends a disposition with the delivery state to the remote peer.
Declaration
public void Complete(Message message, DeliveryState deliveryState)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to complete. |
DeliveryState | deliveryState | An Outcome or a TransactionalState. |
Remarks
This method is not transaction aware. It should be used to bypass
transaction context look up when transactions are not used at all, or
to manage AMQP transactions directly by providing a TransactionalState to
deliveryState
.
Modify(Message, Boolean, Boolean, Fields)
Modifies a message. It sends a modified outcome to the peer.
Declaration
public void Modify(Message message, bool deliveryFailed, bool undeliverableHere = false, Fields messageAnnotations = null)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to modify. |
System.Boolean | deliveryFailed | If set, the message's delivery-count is incremented. |
System.Boolean | undeliverableHere | Indicates if the message should not be redelivered to this endpoint. |
Fields | messageAnnotations | Annotations to be combined with the current message annotations. |
OnAbort(Error)
Aborts the receiver link.
Declaration
protected override void OnAbort(Error error)
Parameters
Type | Name | Description |
---|---|---|
Error | error | The error for the abort. |
Overrides
OnClose(Error)
Closes the receiver link.
Declaration
protected override bool OnClose(Error error)
Parameters
Type | Name | Description |
---|---|---|
Error | error | The error for the closure. |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Receive()
Receives a message. The call is blocked until a message is available or after a default wait time.
Declaration
public Message Receive()
Returns
Type | Description |
---|---|
Message | A Message object if available; otherwise a null value. |
Receive(TimeSpan)
Receives a message. The call is blocked until a message is available or the timeout duration expires.
Declaration
public Message Receive(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | timeout | The time to wait for a message. |
Returns
Type | Description |
---|---|
Message | A Message object if available; otherwise a null value. |
Remarks
Use TimeSpan.MaxValue or Timeout.InfiniteTimeSpan to wait infinitely. If TimeSpan.Zero is supplied, the call returns immediately.
ReceiveAsync()
Receives a message asynchronously.
Declaration
public Task<Message> ReceiveAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Message> | A Task for the asynchronous receive operation. The result is a Message object if available within a default timeout; otherwise a null value. |
ReceiveAsync(TimeSpan)
Receives a message asynchronously.
Declaration
public Task<Message> ReceiveAsync(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | timeout | The time to wait for a message. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Message> | A Task for the asynchronous receive operation. The result is a Message object if available within the specified timeout; otherwise a null value. |
Remarks
Use TimeSpan.MaxValue or Timeout.InfiniteTimeSpan to wait infinitely. If TimeSpan.Zero is supplied, the task completes immediately.
Reject(Message, Error)
Rejects a message. It sends a rejected outcome to the peer.
Declaration
public void Reject(Message message, Error error = null)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to reject. |
Error | error | The error, if any, for the rejection. |
Release(Message)
Releases a message. It sends a released outcome to the peer.
Declaration
public void Release(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to release. |
SetCredit(Int32, CreditMode, Int32)
Sets a credit on the link and the credit management mode.
Declaration
public void SetCredit(int credit, CreditMode creditMode, int flowThreshold = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | credit | The new link credit. |
CreditMode | creditMode | The credit management mode. |
System.Int32 | flowThreshold | If credit mode is Auto, it is the threshold of restored credits that trigers a flow; ignored otherwise. |
Remarks
The receiver link has a default link credit (200). If the default value is not optimal,
application should call this method once after the receiver link is created.
In Auto credit mode, the credit
parameter defines the total credits
of the link which is also the total number messages the remote peer can send.
The link keeps track of acknowledged messages and triggers a flow
when a threshold is reached. The default threshold is half of Amqp.ReceiverLink.credit. Application
acknowledges a message by calling Accept(Message), Reject(Message, Error),
Release(Message) or Modify(Message, Boolean, Boolean, Fields) method.
In Manual credit mode, the credit
parameter defines the extra credits
of the link which is the additional messages the remote peer can send.
Please note the following.
- In Auto mode, calling this method multiple times with different credits is allowed but not recommended. Application may do this if, for example, it needs to control local queue depth based on resource usage. If credit is reduced, the link maintains a buffer so incoming messages are still allowed.
- The creditMode should not be changed after it is initially set.
- To stop a receiver link, set
credit
to 0. However application should expect in-flight messages to come as a result of the previous credit. It is recommended to use the Drain mode if the application wishes to stop the messages after a given credit is used. - In drain credit mode, if a drain cycle is still in progress, the call simply returns without sending a flow. Application is expected to keep calling Receive() in a loop until all messages are received or a null message is returned.
- In manual credit mode, application is responsible for keeping track of processed messages and issue more credits when certain conditions are met.
SetCredit(Int32, Boolean)
Sets a credit on the link. The credit controls how many messages the peer can send.
Declaration
public void SetCredit(int credit, bool autoRestore = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | credit | The new link credit. |
System.Boolean | autoRestore | If true, this method is the same as SetCredit(credit, CreditMode.Auto); if false, it is the same as SetCredit(credit, CreditMode.Manual). |
Start(Int32, MessageCallback)
Starts the message pump.
Declaration
public void Start(int credit, MessageCallback onMessage = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | credit | The link credit to issue. See SetCredit(Int32, Boolean) for more details. |
MessageCallback | onMessage | If specified, the callback to invoke when messages are received. If not specified, call Receive method to get the messages. |