Class MessageBrokerListener
- Namespace
- LfrlAnvil.MessageBroker.Client
- Assembly
- LfrlAnvil.MessageBroker.Client.dll
Represents a message broker listener, which allows the client to react to messages published to the related channel.
public sealed class MessageBrokerListener
- Inheritance
-
MessageBrokerListener
- Inherited Members
Properties
AreAcksEnabled
Specifies whether the Client is expected to send ACK or negative ACK to the server in order to confirm message notification.
public bool AreAcksEnabled { get; }
Property Value
Callback
Callback invoked when this listener receives a message from the server.
public MessageBrokerListenerCallback Callback { get; }
Property Value
ChannelId
Unique id of the channel to which this listener is related.
public int ChannelId { get; }
Property Value
ChannelName
Unique name of the channel to which this listener is related.
public string ChannelName { get; }
Property Value
Client
MessageBrokerClient instance that owns this listener.
public MessageBrokerClient Client { get; }
Property Value
DeadLetterCapacityHint
Specifies how many messages will be stored at most by the dead letter.
public int DeadLetterCapacityHint { get; }
Property Value
Remarks
This is a min value. Actual value is dependant on all listeners attached to the queue and the state of the queue's dead letter.
FilterExpression
Specifies server-side message filter expression.
public string? FilterExpression { get; }
Property Value
IsEphemeral
Specifies whether the listener is ephemeral.
public bool IsEphemeral { get; }
Property Value
Remarks
Ephemeral listeners will be removed by the server when client disconnects.
MaxRedeliveries
Specifies how many times the server will attempt to automatically send a message notification redelivery when the Client fails to respond with either an ACK or a negative ACK in time (see MinAckTimeout), before giving up.
public int MaxRedeliveries { get; }
Property Value
Remarks
Redelivery are disabled when value is equal 0.
MaxRetries
Specifies how many times the server will attempt to automatically send a message notification retry when the Client responds with a negative ACK, before giving up.
public int MaxRetries { get; }
Property Value
Remarks
Retries are disabled when value is equal 0.
MinAckTimeout
Specifies the minimum amount of time that the server will wait for the Client to send either an ACK or a negative ACK before attempting a message notification redelivery. Actual ACK timeout may be different due to the state of the queue and other listeners bound to it.
public Duration MinAckTimeout { get; }
Property Value
MinDeadLetterRetention
Specifies retention period for messages stored in the dead letter.
public Duration MinDeadLetterRetention { get; }
Property Value
Remarks
This is a min value. Actual value is dependant on all listeners attached to the queue and the state of the queue's dead letter.
PrefetchHint
Specifies how many messages intended for this listener can be sent by the server to the Client at the same time.
public short PrefetchHint { get; }
Property Value
Remarks
This is a max potential value. Actual value is dependant on all listeners attached to the queue and all of its currently pending messages.
QueueId
Unique id of the queue to which this listener is related.
public int QueueId { get; }
Property Value
QueueName
Unique name of the queue to which this listener is related.
public string QueueName { get; }
Property Value
RetryDelay
Specifies the delay between the server successfully processing negative ACK sent by the Client and the server sending a message notification retry.
public Duration RetryDelay { get; }
Property Value
State
Current listener's state.
public MessageBrokerListenerState State { get; }
Property Value
Remarks
See MessageBrokerListenerState for more information.
Methods
SendMessageAckAsync(int, int, ulong, int, int)
Attempts to send a message notification ACK.
public ValueTask<Result<bool>> SendMessageAckAsync(int ackId, int streamId, ulong messageId, int retry, int redelivery)
Parameters
ackIdintId of the pending ACK associated with the message.
streamIdintUnique id of the server-side stream that handled the message.
messageIdulongUnique message id.
retryintRetry attempt of the message.
redeliveryintRedelivery number of the message.
Returns
- ValueTask<Result<bool>>
A task that represents the operation, which returns a Result<T> instance, with underlying bool result. If the result is equal to true, then ACK sending was successful, otherwise the listener was no longer bound to the channel.
Remarks
Unexpected errors encountered during ACK sending attempt will cause the client to be automatically disposed. Returned Result<T> will only be valid when either the client has successfully sent the ACK to the server, or the listener is already locally ubound from the channel, which will cancel the request to the server.
Exceptions
- ArgumentOutOfRangeException
When
ackIdis less than or equal to 0 or whenstreamIdis less than or equal to 0 or whenretryis less than 0 or greater than the listener's MaxRetries or whenredeliveryis less than 0 or greater than the listener's MaxRedeliveries.- MessageBrokerClientDisposedException
When client has already been disposed.
- MessageBrokerClientMessageException
When ACKs are not enabled for this listener.
SendNegativeMessageAckAsync(int, int, ulong, int, int, MessageBrokerNegativeAck)
Attempts to send a negative message notification ACK.
public ValueTask<Result<bool>> SendNegativeMessageAckAsync(int ackId, int streamId, ulong messageId, int retry, int redelivery, MessageBrokerNegativeAck nack = default)
Parameters
ackIdintId of the pending ACK associated with the message.
streamIdintUnique id of the server-side stream that handled the message.
messageIdulongUnique message id.
retryintRetry attempt of the message.
redeliveryintRedelivery attempt of the message.
nackMessageBrokerNegativeAckOptional MessageBrokerNegativeAck instance that allows to modify the ACK. Equal to Default by default.
Returns
- ValueTask<Result<bool>>
A task that represents the operation, which returns a Result<T> instance, with underlying bool result. If the result is equal to true, then ACK sending was successful, otherwise the listener was no longer bound to the channel.
Remarks
Unexpected errors encountered during ACK sending attempt will cause the client to be automatically disposed. Returned Result<T> will only be valid when either the client has successfully sent the ACK to the server, or the listener is already locally ubound from the channel, which will cancel the request to the server.
Exceptions
- ArgumentOutOfRangeException
When
ackIdis less than or equal to 0 or whenstreamIdis less than or equal to 0 or whenretryis less than 0 or greater than the listener's MaxRetries or whenredeliveryis less than 0 or greater than the listener's MaxRedeliveries.- MessageBrokerClientDisposedException
When client has already been disposed.
- MessageBrokerClientMessageException
When ACKs are not enabled for this listener.
ToString()
Returns a string representation of this MessageBrokerListener instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
UnbindAsync()
Attempts to unbind this listener from the channel.
public ValueTask<Result<MessageBrokerUnbindListenerResult>> UnbindAsync()
Returns
- ValueTask<Result<MessageBrokerUnbindListenerResult>>
A task that represents the operation, which returns a Result<T> instance, with underlying MessageBrokerUnbindListenerResult instance.
Remarks
This operation will cause all pending messages for this listener to be discarded. Unexpected errors encountered during listener unbinding will cause the client to be automatically disposed. Returned Result<T> will only be valid when either the listener has been successfully unbound from the channel on the server side, or the listener is already locally unbound from the channel, which will cancel the request to the server.
Exceptions
- MessageBrokerClientDisposedException
When client has already been disposed.