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
remoteEndPointIPEndPointThe IPEndPoint of the server to which this client will connect to.
namestringClient's unique name.
optionsMessageBrokerClientOptionsOptional 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
ConnectionTimeout
Connect to server timeout.
public Duration ConnectionTimeout { get; }
Property Value
Id
Client's unique identifier assigned by the server.
public int Id { get; }
Property Value
Remarks
Value will be initialized during handshake with the server.
IsEphemeral
Specifies whether the client is ephemeral.
public bool IsEphemeral { get; }
Property Value
Remarks
Non-ephemeral clients will be persisted by the server when offline.
IsServerLittleEndian
Indicates server's endianness.
public bool IsServerLittleEndian { get; }
Property Value
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
Listeners
Collection of MessageBrokerListener instances.
public MessageBrokerListenerCollection Listeners { get; }
Property Value
LocalEndPoint
The local EndPoint that this client is using for communications with the server.
public EndPoint? LocalEndPoint { get; }
Property Value
MaxBatchPacketCount
Max acceptable batch packet count.
public short MaxBatchPacketCount { get; }
Property Value
Remarks
Value may change during handshake with the server.
MaxNetworkBatchPacketLength
Max acceptable network batch packet length.
public MemorySize MaxNetworkBatchPacketLength { get; }
Property Value
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
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
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
Remarks
Value may change during handshake with the server.
Name
Client's unique name.
public string Name { get; }
Property Value
PingInterval
Send ping interval.
public Duration PingInterval { get; }
Property Value
Remarks
Value may change during handshake with the server.
Publishers
Collection of MessageBrokerPublisher instances.
public MessageBrokerPublisherCollection Publishers { get; }
Property Value
RemoteEndPoint
The remote IPEndPoint of the server to which this client connects to.
public IPEndPoint RemoteEndPoint { get; }
Property Value
State
Current client's state.
public MessageBrokerClientState State { get; }
Property Value
Remarks
See MessageBrokerClientState for more information.
SynchronizeExternalObjectNames
Specifies whether synchronization of external object names is enabled.
public bool SynchronizeExternalObjectNames { get; }
Property Value
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
queueIdintID of the queue whose dead letter is to be queried.
readCountintNumber 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
queueIdis less than or equal to 0 or whenreadCountis 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
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
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
cancellationTokenhas 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.