Table of Contents

Class BrokerClient

Namespace
Silverback.Messaging.Broker
Assembly
Silverback.Integration.dll

Wraps the underlying client libraries (e.g. Kafka consumers and producers or Mqtt clients) and handles the connection lifecycle.

public abstract class BrokerClient : IBrokerClient, IDisposable, IAsyncDisposable
Inheritance
BrokerClient
Implements
Inherited Members

Constructors

BrokerClient(string, ISilverbackLogger)

Initializes a new instance of the BrokerClient class.

protected BrokerClient(string name, ISilverbackLogger logger)

Parameters

name string

The client name.

logger ISilverbackLogger

The ISilverbackLogger.

Properties

Disconnected

Gets the AsyncEvent<TArg> that is fired when the DisconnectAsync() method has been called and the client is disconnected.

public AsyncEvent<BrokerClient> Disconnected { get; }

Property Value

AsyncEvent<BrokerClient>

Disconnecting

Gets the AsyncEvent<TArg> that is fired when the DisconnectAsync() method is called and the client is disconnecting.

public AsyncEvent<BrokerClient> Disconnecting { get; }

Property Value

AsyncEvent<BrokerClient>

DisplayName

Gets the name to be displayed in the human-targeted output (e.g. logs, health checks result, etc.).

public string DisplayName { get; }

Property Value

string

Initialized

Gets the AsyncEvent<TArg> that is fired when the ConnectAsync() method has been called and the client has been successfully initialized. The connection with the broker will eventually be established.

public AsyncEvent<BrokerClient> Initialized { get; }

Property Value

AsyncEvent<BrokerClient>

Initializing

Gets the AsyncEvent<TArg> that is fired when the ConnectAsync() method is called and the client is initializing.

public AsyncEvent<BrokerClient> Initializing { get; }

Property Value

AsyncEvent<BrokerClient>

Name

Gets the client name.

public string Name { get; }

Property Value

string

Status

Gets a value indicating whether the client is connected to the broker.

public ClientStatus Status { get; }

Property Value

ClientStatus

Methods

ConnectAsync()

Initializes the connection to the message broker.

public ValueTask ConnectAsync()

Returns

ValueTask

A Task representing the asynchronous operation.

ConnectCoreAsync()

Called when ConnectAsync() is called to initialize the client.

protected abstract ValueTask ConnectCoreAsync()

Returns

ValueTask

A ValueTask representing the asynchronous operation.

DisconnectAsync()

Disconnects from the message broker.

public ValueTask DisconnectAsync()

Returns

ValueTask

A ValueTask representing the asynchronous operation.

DisconnectCoreAsync()

Called when DisconnectAsync() is called to disconnect the client.

protected abstract ValueTask DisconnectCoreAsync()

Returns

ValueTask

A ValueTask representing the asynchronous operation.

Dispose()

public void Dispose()

Dispose(bool)

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

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

A value indicating whether the method has been called by the Dispose method and not from the finalizer.

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

DisposeCoreAsync()

protected virtual ValueTask DisposeCoreAsync()

Returns

ValueTask

~BrokerClient()

Finalizes an instance of the BrokerClient class.

protected ~BrokerClient()

ReconnectAsync()

Disconnects and reconnects the client.

public ValueTask ReconnectAsync()

Returns

ValueTask

A ValueTask representing the asynchronous operation.

Remarks

This is used to recover when the consumer is stuck in state where it's not able to rollback or commit anymore.