Table of Contents

Class MessageBrokerClient

Namespace
LfrlAnvil.MessageBroker.Client
Assembly
LfrlAnvil.MessageBroker.Client.dll

Represents a message broker client.

public sealed class MessageBrokerClient : IDisposable, IAsyncDisposable
Inheritance
MessageBrokerClient
Implements
Inherited Members

Constructors

MessageBrokerClient(IPEndPoint, string, MessageBrokerClientOptions)

Creates a new MessageBrokerClient instance.

public MessageBrokerClient(IPEndPoint remoteEndPoint, string name, MessageBrokerClientOptions options = default)

Parameters

remoteEndPoint IPEndPoint

The IPEndPoint of the server to which this client will connect to.

name string

Client's unique name.

options MessageBrokerClientOptions

Optional creation options.

Exceptions

ArgumentOutOfRangeException

When name's length is less than 1 or greater than 512.

Properties

ClearBuffers

Specifies whether to clear internal buffers once the client is done using them.

public bool ClearBuffers { get; }

Property Value

bool

ConnectionTimeout

Connect to server timeout.

public Duration ConnectionTimeout { get; }

Property Value

Duration

Id

Client's unique identifier assigned by the server.

public int Id { get; }

Property Value

int

Remarks

Value will be initialized during handshake with the server.

IsEphemeral

Specifies whether the client is ephemeral.

public bool IsEphemeral { get; }

Property Value

bool

Remarks

Non-ephemeral clients will be persisted by the server when offline.

IsServerLittleEndian

Indicates server's endianness.

public bool IsServerLittleEndian { get; }

Property Value

bool

Remarks

Value will be initialized during handshake with the server.

ListenerDisposalTimeout

Amount of time that MessageBrokerListener instances will wait during their disposal for callbacks to complete before giving up.

public Duration ListenerDisposalTimeout { get; }

Property Value

Duration

Listeners

Collection of MessageBrokerListener instances.

public MessageBrokerListenerCollection Listeners { get; }

Property Value

MessageBrokerListenerCollection

LocalEndPoint

The local EndPoint that this client is using for communications with the server.

public EndPoint? LocalEndPoint { get; }

Property Value

EndPoint

MaxBatchPacketCount

Max acceptable batch packet count.

public short MaxBatchPacketCount { get; }

Property Value

short

Remarks

Value may change during handshake with the server.

MaxNetworkBatchPacketLength

Max acceptable network batch packet length.

public MemorySize MaxNetworkBatchPacketLength { get; }

Property Value

MemorySize

Remarks

Represents max possible length for packets of Batch type. Value may change during handshake with the server.

MaxNetworkMessagePacketLength

Max acceptable network message packet length.

public MemorySize MaxNetworkMessagePacketLength { get; }

Property Value

MemorySize

Remarks

Represents max possible length for inbound packets of MessageNotification type or outbound packets of PushMessage type. Value will be initialized during handshake with the server.

MaxNetworkPacketLength

Max acceptable network packet length.

public MemorySize MaxNetworkPacketLength { get; }

Property Value

MemorySize

Remarks

Represents max possible length for packets not handled by either MaxNetworkMessagePacketLength or MaxNetworkBatchPacketLength. Value will be initialized during handshake with the server.

MessageTimeout

Send or receive message timeout.

public Duration MessageTimeout { get; }

Property Value

Duration

Remarks

Value may change during handshake with the server.

Name

Client's unique name.

public string Name { get; }

Property Value

string

PingInterval

Send ping interval.

public Duration PingInterval { get; }

Property Value

Duration

Remarks

Value may change during handshake with the server.

Publishers

Collection of MessageBrokerPublisher instances.

public MessageBrokerPublisherCollection Publishers { get; }

Property Value

MessageBrokerPublisherCollection

RemoteEndPoint

The remote IPEndPoint of the server to which this client connects to.

public IPEndPoint RemoteEndPoint { get; }

Property Value

IPEndPoint

State

Current client's state.

public MessageBrokerClientState State { get; }

Property Value

MessageBrokerClientState

Remarks

See MessageBrokerClientState for more information.

SynchronizeExternalObjectNames

Specifies whether synchronization of external object names is enabled.

public bool SynchronizeExternalObjectNames { get; }

Property Value

bool

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

QueryDeadLetterAsync(int, int)

Attempts to asynchronously consume chosen queue's dead letter messages.

public ValueTask<Result<MessageBrokerDeadLetterQueryResult>> QueryDeadLetterAsync(int queueId, int readCount)

Parameters

queueId int

ID of the queue whose dead letter is to be queried.

readCount int

Number of dead letter messages to be asynchronously consumed.

Returns

ValueTask<Result<MessageBrokerDeadLetterQueryResult>>

A task that represents the operation, which returns a Result<T> instance, with underlying MessageBrokerDeadLetterQueryResult instance.

Remarks

This operation will consume dead letter messages by sending them to correct listeners, which will also cause them to be completely removed from the server. Unexpected errors encountered during dead letter querying will cause the client to be automatically disposed.

Exceptions

MessageBrokerClientDisposedException

When client has already been disposed.

ArgumentOutOfRangeException

When queueId is less than or equal to 0 or when readCount is less than 0.

StartAsync(CancellationToken)

Attempts to initialize the client, connect to the server and establish a handshake.

public ValueTask<Result> StartAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<Result>

A task that represents the operation, which returns a Result instance.

Remarks

Errors encountered during client initialization will cause it to be automatically disposed. Returned Result will only be valid when the client will successfully connect to the server, establish a handshake and proceed to the Running state.

Exceptions

OperationCanceledException

When cancellationToken has been cancelled.

MessageBrokerClientDisposedException

When this client has already been disposed.

MessageBrokerClientStateException

When this client is not disposed and not in Created state.

ToString()

Returns a string representation of this MessageBrokerClient instance.

[Pure]
public override string ToString()

Returns

string

String representation.