Table of Contents

Class Producer

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

Produces the messages to an endpoint.

public abstract class Producer : IProducer, IDisposable
Inheritance
Producer
Implements
Derived
Inherited Members

Constructors

Producer(string, IBrokerClient, ProducerEndpointConfiguration, IBrokerBehaviorsProvider<IProducerBehavior>, IServiceProvider, ISilverbackLogger<IProducer>)

Initializes a new instance of the Producer class.

protected Producer(string name, IBrokerClient client, ProducerEndpointConfiguration endpointConfiguration, IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider, IServiceProvider serviceProvider, ISilverbackLogger<IProducer> logger)

Parameters

name string

The producer name.

client IBrokerClient

The IBrokerClient.

endpointConfiguration ProducerEndpointConfiguration

The ProducerEndpointConfiguration<TEndpoint>.

behaviorsProvider IBrokerBehaviorsProvider<IProducerBehavior>

The IBrokerBehaviorsProvider<TBehavior>.

serviceProvider IServiceProvider

The IServiceProvider to be used to resolve the necessary services.

logger ISilverbackLogger<IProducer>

The ISilverbackLogger<TCategoryName>.

Properties

Client

Gets the related IBrokerClient.

public IBrokerClient Client { get; }

Property Value

IBrokerClient

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

EndpointConfiguration

Gets the endpoint configuration.

public ProducerEndpointConfiguration EndpointConfiguration { get; }

Property Value

ProducerEndpointConfiguration

Name

Gets the producer name.

public string Name { get; }

Property Value

string

Methods

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.

Produce(IOutboundEnvelope)

Publishes the specified message.

public IBrokerMessageIdentifier? Produce(IOutboundEnvelope envelope)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

Returns

IBrokerMessageIdentifier

The IBrokerMessageIdentifier of the produced record.

Produce(IOutboundEnvelope, Action<IBrokerMessageIdentifier?>, Action<Exception>)

Publishes the specified message.

public void Produce(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

onSuccess Action<IBrokerMessageIdentifier>

The callback to be invoked when the message is successfully produced.

onError Action<Exception>

The callback to be invoked when the produce fails.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

Produce(object?, IReadOnlyCollection<MessageHeader>?)

Publishes the specified message.

public IBrokerMessageIdentifier? Produce(object? message, IReadOnlyCollection<MessageHeader>? headers = null)

Parameters

message object

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

Returns

IBrokerMessageIdentifier

The IBrokerMessageIdentifier of the produced record.

Produce(object?, IReadOnlyCollection<MessageHeader>?, Action<IBrokerMessageIdentifier?>, Action<Exception>)

Publishes the specified message.

public void Produce(object? message, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)

Parameters

message object

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

onSuccess Action<IBrokerMessageIdentifier>

The callback to be invoked when the message is successfully produced.

onError Action<Exception>

The callback to be invoked when the produce fails.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

ProduceAsync(IOutboundEnvelope, CancellationToken)

Publishes the specified message.

public ValueTask<IBrokerMessageIdentifier?> ProduceAsync(IOutboundEnvelope envelope, CancellationToken cancellationToken = default)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

cancellationToken CancellationToken

The cancellation token that can be used to cancel the operation.

Returns

ValueTask<IBrokerMessageIdentifier>

A ValueTask<TResult> representing the asynchronous operation. The ValueTask result contains the IBrokerMessageIdentifier of the produced record.

ProduceAsync(object?, IReadOnlyCollection<MessageHeader>?, CancellationToken)

Publishes the specified message.

public ValueTask<IBrokerMessageIdentifier?> ProduceAsync(object? message, IReadOnlyCollection<MessageHeader>? headers = null, CancellationToken cancellationToken = default)

Parameters

message object

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

cancellationToken CancellationToken

The cancellation token that can be used to cancel the operation.

Returns

ValueTask<IBrokerMessageIdentifier>

A ValueTask<TResult> representing the asynchronous operation. The ValueTask result contains the IBrokerMessageIdentifier of the produced record.

ProduceCore(IOutboundEnvelope)

Publishes the specified message and returns its identifier.

protected abstract IBrokerMessageIdentifier? ProduceCore(IOutboundEnvelope envelope)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

Returns

IBrokerMessageIdentifier

The message identifier assigned by the broker (the Kafka offset or similar).

ProduceCoreAsync(IOutboundEnvelope, CancellationToken)

Publishes the specified message and returns its identifier.

protected abstract ValueTask<IBrokerMessageIdentifier?> ProduceCoreAsync(IOutboundEnvelope envelope, CancellationToken cancellationToken)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

cancellationToken CancellationToken

The cancellation token that can be used to cancel the operation.

Returns

ValueTask<IBrokerMessageIdentifier>

A ValueTask<TResult> representing the asynchronous operation. The task result contains the message identifier assigned by the broker (the Kafka offset or similar).

ProduceCore<TState>(IOutboundEnvelope, Action<IBrokerMessageIdentifier?, TState>, Action<Exception, TState>, TState)

Publishes the specified message and returns its identifier.

protected abstract void ProduceCore<TState>(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

onSuccess Action<IBrokerMessageIdentifier, TState>

The callback to be invoked when the message is successfully produced.

onError Action<Exception, TState>

The callback to be invoked when the produce fails.

state TState

The state object that will be passed to the callbacks.

Type Parameters

TState

The type of the state object that will be passed to the callbacks.

Remarks

In this implementation, the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

Produce<TState>(IOutboundEnvelope, Action<IBrokerMessageIdentifier?, TState>, Action<Exception, TState>, TState)

Publishes the specified message.

public void Produce<TState>(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)

Parameters

envelope IOutboundEnvelope

The envelope containing the message to be produced.

onSuccess Action<IBrokerMessageIdentifier, TState>

The callback to be invoked when the message is successfully produced.

onError Action<Exception, TState>

The callback to be invoked when the produce fails.

state TState

The state object to be passed to the callbacks.

Type Parameters

TState

The type of the state object to be passed to the callbacks.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

Produce<TState>(object?, IReadOnlyCollection<MessageHeader>?, Action<IBrokerMessageIdentifier?, TState>, Action<Exception, TState>, TState)

Publishes the specified message.

public void Produce<TState>(object? message, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)

Parameters

message object

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

onSuccess Action<IBrokerMessageIdentifier, TState>

The callback to be invoked when the message is successfully produced.

onError Action<Exception, TState>

The callback to be invoked when the produce fails.

state TState

The state object to be passed to the callbacks.

Type Parameters

TState

The type of the state object to be passed to the callbacks.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

RawProduce(byte[]?, IReadOnlyCollection<MessageHeader>?)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public IBrokerMessageIdentifier? RawProduce(byte[]? messageContent, IReadOnlyCollection<MessageHeader>? headers = null)

Parameters

messageContent byte[]

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

Returns

IBrokerMessageIdentifier

The IBrokerMessageIdentifier of the produced record.

RawProduce(byte[]?, IReadOnlyCollection<MessageHeader>?, Action<IBrokerMessageIdentifier?>, Action<Exception>)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public void RawProduce(byte[]? messageContent, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)

Parameters

messageContent byte[]

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

onSuccess Action<IBrokerMessageIdentifier>

The callback to be invoked when the message is successfully produced.

onError Action<Exception>

The callback to be invoked when the produce fails.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

RawProduce(Stream?, IReadOnlyCollection<MessageHeader>?)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public IBrokerMessageIdentifier? RawProduce(Stream? messageStream, IReadOnlyCollection<MessageHeader>? headers = null)

Parameters

messageStream Stream

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

Returns

IBrokerMessageIdentifier

The IBrokerMessageIdentifier of the produced record.

RawProduce(Stream?, IReadOnlyCollection<MessageHeader>?, Action<IBrokerMessageIdentifier?>, Action<Exception>)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public void RawProduce(Stream? messageStream, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)

Parameters

messageStream Stream

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

onSuccess Action<IBrokerMessageIdentifier>

The callback to be invoked when the message is successfully produced.

onError Action<Exception>

The callback to be invoked when the produce fails.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

RawProduceAsync(byte[]?, IReadOnlyCollection<MessageHeader>?, CancellationToken)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public ValueTask<IBrokerMessageIdentifier?> RawProduceAsync(byte[]? messageContent, IReadOnlyCollection<MessageHeader>? headers = null, CancellationToken cancellationToken = default)

Parameters

messageContent byte[]

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

cancellationToken CancellationToken

The cancellation token that can be used to cancel the operation.

Returns

ValueTask<IBrokerMessageIdentifier>

A ValueTask<TResult> representing the asynchronous operation. The ValueTask result contains the IBrokerMessageIdentifier of the produced record.

RawProduceAsync(Stream?, IReadOnlyCollection<MessageHeader>?, CancellationToken)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public ValueTask<IBrokerMessageIdentifier?> RawProduceAsync(Stream? messageStream, IReadOnlyCollection<MessageHeader>? headers = null, CancellationToken cancellationToken = default)

Parameters

messageStream Stream

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

cancellationToken CancellationToken

The cancellation token that can be used to cancel the operation.

Returns

ValueTask<IBrokerMessageIdentifier>

A ValueTask<TResult> representing the asynchronous operation. The ValueTask result contains the IBrokerMessageIdentifier of the produced record.

RawProduce<TState>(byte[]?, IReadOnlyCollection<MessageHeader>?, Action<IBrokerMessageIdentifier?, TState>, Action<Exception, TState>, TState)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public void RawProduce<TState>(byte[]? messageContent, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)

Parameters

messageContent byte[]

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

onSuccess Action<IBrokerMessageIdentifier, TState>

The callback to be invoked when the message is successfully produced.

onError Action<Exception, TState>

The callback to be invoked when the produce fails.

state TState

The state object to be passed to the callbacks.

Type Parameters

TState

The type of the state object to be passed to the callbacks.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).

RawProduce<TState>(Stream?, IReadOnlyCollection<MessageHeader>?, Action<IBrokerMessageIdentifier?, TState>, Action<Exception, TState>, TState)

Publishes the specified message as-is, without sending it through the behaviors pipeline.

public void RawProduce<TState>(Stream? messageStream, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)

Parameters

messageStream Stream

The message.

headers IReadOnlyCollection<MessageHeader>

The optional message headers.

onSuccess Action<IBrokerMessageIdentifier, TState>

The callback to be invoked when the message is successfully produced.

onError Action<Exception, TState>

The callback to be invoked when the produce fails.

state TState

The state object to be passed to the callbacks.

Type Parameters

TState

The type of the state object to be passed to the callbacks.

Remarks

In this implementation the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).