Table of Contents

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

int

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

channelName string

Unique name of the channel to bind as listener to.

callback MessageBrokerListenerCallback

Callback invoked when the created listener receives a message from the server.

options MessageBrokerListenerOptions

Optional creation options. Equal to Default by default.

queueName string

Optional unique name of the queue that will store pending messages to this client server-side. Equal to the provided channelName by default.

createChannelIfNotExists bool

Specifies whether the server should create the channel if it does not exist yet. Equal to true by default.

isEphemeral bool

Specifies 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 channelName or queueName (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

channelId int

Unique id of the channel to which the listener is related.

Returns

MessageBrokerListener

MessageBrokerListener instance associated with the provided channelId or 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

channelName string

Unique name of the channel to which the listener is related.

Returns

MessageBrokerListener

MessageBrokerListener instance associated with the provided channelName or 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

channelName string

Name 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 channelName 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.