Struct MessageBrokerListenerCollection
- Namespace
- LfrlAnvil.MessageBroker.Client
- Assembly
- LfrlAnvil.MessageBroker.Client.dll
Represents a collection of MessageBrokerListener instances.
public readonly struct MessageBrokerListenerCollection
- Inherited Members
Properties
Count
Specifies the number of listeners.
public int Count { get; }
Property Value
Methods
BindAsync(string, MessageBrokerListenerCallback, MessageBrokerListenerOptions, string?, bool, bool)
Attempts to bind the client to a channel as a message listener.
public ValueTask<Result<MessageBrokerBindListenerResult?>> BindAsync(string channelName, MessageBrokerListenerCallback callback, MessageBrokerListenerOptions options = default, string? queueName = null, bool createChannelIfNotExists = true, bool isEphemeral = false)
Parameters
channelNamestringUnique name of the channel to bind as listener to.
callbackMessageBrokerListenerCallbackCallback invoked when the created listener receives a message from the server.
optionsMessageBrokerListenerOptionsOptional creation options. Equal to Default by default.
queueNamestringOptional unique name of the queue that will store pending messages to this client server-side. Equal to the provided
channelNameby default.createChannelIfNotExistsboolSpecifies whether the server should create the channel if it does not exist yet. Equal to true by default.
isEphemeralboolSpecifies whether the listener will be ephemeral. Equal to false by default.
Returns
- ValueTask<Result<MessageBrokerBindListenerResult?>>
A task that represents the operation, which returns a Result<T> instance, with underlying MessageBrokerBindListenerResult instance.
Remarks
Unexpected errors encountered during listener binding attempt will cause the client to be automatically disposed. Returned Result<T> will only be valid when either the client has been successfully bound as listener to the channel on the server side, or the client is already locally bound as listener to the channel, which will cancel the request to the server.
Exceptions
- ArgumentOutOfRangeException
When
channelNameorqueueName(if not null) length is less than 1 or greater than 512.- MessageBrokerClientDisposedException
When client has already been disposed.
- MessageBrokerClientStateException
When client is not disposed and not in Running state.
GetAll()
Returns all listeners.
[Pure]
public ReadOnlyArray<MessageBrokerListener> GetAll()
Returns
- ReadOnlyArray<MessageBrokerListener>
All listeners.
TryGetByChannelId(int)
Attempts to return a listener by related channel id.
[Pure]
public MessageBrokerListener? TryGetByChannelId(int channelId)
Parameters
channelIdintUnique id of the channel to which the listener is related.
Returns
- MessageBrokerListener
MessageBrokerListener instance associated with the provided
channelIdor null, when such a listener does not exist.
TryGetByChannelName(string)
Attempts to return a listener by related channel name.
[Pure]
public MessageBrokerListener? TryGetByChannelName(string channelName)
Parameters
channelNamestringUnique name of the channel to which the listener is related.
Returns
- MessageBrokerListener
MessageBrokerListener instance associated with the provided
channelNameor null, when such a listener does not exist.
UnbindAsync(string)
Attempts to unbind a listener from the provided channel.
public ValueTask<Result<MessageBrokerUnbindListenerResult>> UnbindAsync(string channelName)
Parameters
channelNamestringName of the channel to unbind a listener from.
Returns
- ValueTask<Result<MessageBrokerUnbindListenerResult>>
A task that represents the operation, which returns a Result<T> instance, with underlying MessageBrokerUnbindListenerResult instance.
Remarks
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
- ArgumentOutOfRangeException
When
channelNamelength is less than 1 or greater than 512.- MessageBrokerClientDisposedException
When client has already been disposed.
- MessageBrokerClientStateException
When client is not disposed and not in Running state.