Show / Hide Table of Contents

    Class Producer

    Produces the messages to an endpoint.

    Inheritance
    object
    Producer
    KafkaProducer
    MqttProducer
    Implements
    IProducer
    IDisposable
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Silverback.Messaging.Broker
    Assembly: Silverback.Integration.dll
    Syntax
    public abstract class Producer : IProducer, IDisposable

    Constructors

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

    Initializes a new instance of the Producer class.

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

    The producer name.

    IBrokerClient client

    The IBrokerClient.

    ProducerEndpointConfiguration endpointConfiguration

    The ProducerEndpointConfiguration<TEndpoint>.

    IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider

    The IBrokerBehaviorsProvider<TBehavior>.

    IServiceProvider serviceProvider

    The IServiceProvider to be used to resolve the necessary services.

    ISilverbackLogger<IProducer> logger

    The ISilverbackLogger<TCategoryName>.

    Properties

    Client

    Gets the related IBrokerClient.

    Declaration
    public IBrokerClient Client { get; }
    Property Value
    Type Description
    IBrokerClient

    DisplayName

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

    Declaration
    public string DisplayName { get; }
    Property Value
    Type Description
    string

    EndpointConfiguration

    Gets the endpoint configuration.

    Declaration
    public ProducerEndpointConfiguration EndpointConfiguration { get; }
    Property Value
    Type Description
    ProducerEndpointConfiguration

    Name

    Gets the producer name.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    string

    Methods

    Dispose()

    Produces the messages to an endpoint.

    Declaration
    public void Dispose()

    Dispose(bool)

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

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

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

    Produce(IOutboundEnvelope)

    Publishes the specified message.

    Declaration
    public IBrokerMessageIdentifier? Produce(IOutboundEnvelope envelope)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    Returns
    Type Description
    IBrokerMessageIdentifier

    The IBrokerMessageIdentifier of the produced record.

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

    Publishes the specified message.

    Declaration
    public void Produce(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    Action<IBrokerMessageIdentifier> onSuccess

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

    Action<Exception> onError

    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.

    Declaration
    public IBrokerMessageIdentifier? Produce(object? message, IReadOnlyCollection<MessageHeader>? headers = null)
    Parameters
    Type Name Description
    object message

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Returns
    Type Description
    IBrokerMessageIdentifier

    The IBrokerMessageIdentifier of the produced record.

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

    Publishes the specified message.

    Declaration
    public void Produce(object? message, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)
    Parameters
    Type Name Description
    object message

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Action<IBrokerMessageIdentifier> onSuccess

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

    Action<Exception> onError

    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.

    Declaration
    public ValueTask<IBrokerMessageIdentifier?> ProduceAsync(IOutboundEnvelope envelope, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    CancellationToken cancellationToken

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

    Returns
    Type Description
    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    CancellationToken cancellationToken

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

    Returns
    Type Description
    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.

    Declaration
    protected abstract IBrokerMessageIdentifier? ProduceCore(IOutboundEnvelope envelope)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    Returns
    Type Description
    IBrokerMessageIdentifier

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

    ProduceCoreAsync(IOutboundEnvelope, CancellationToken)

    Publishes the specified message and returns its identifier.

    Declaration
    protected abstract ValueTask<IBrokerMessageIdentifier?> ProduceCoreAsync(IOutboundEnvelope envelope, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    CancellationToken cancellationToken

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

    Returns
    Type Description
    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.

    Declaration
    protected abstract void ProduceCore<TState>(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    Action<IBrokerMessageIdentifier, TState> onSuccess

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

    Action<Exception, TState> onError

    The callback to be invoked when the produce fails.

    TState state

    The state object that will be passed to the callbacks.

    Type Parameters
    Name Description
    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.

    Declaration
    public void Produce<TState>(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)
    Parameters
    Type Name Description
    IOutboundEnvelope envelope

    The envelope containing the message to be produced.

    Action<IBrokerMessageIdentifier, TState> onSuccess

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

    Action<Exception, TState> onError

    The callback to be invoked when the produce fails.

    TState state

    The state object to be passed to the callbacks.

    Type Parameters
    Name Description
    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Action<IBrokerMessageIdentifier, TState> onSuccess

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

    Action<Exception, TState> onError

    The callback to be invoked when the produce fails.

    TState state

    The state object to be passed to the callbacks.

    Type Parameters
    Name Description
    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.

    Declaration
    public IBrokerMessageIdentifier? RawProduce(byte[]? messageContent, IReadOnlyCollection<MessageHeader>? headers = null)
    Parameters
    Type Name Description
    byte[] messageContent

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Returns
    Type Description
    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Action<IBrokerMessageIdentifier> onSuccess

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

    Action<Exception> onError

    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.

    Declaration
    public IBrokerMessageIdentifier? RawProduce(Stream? messageStream, IReadOnlyCollection<MessageHeader>? headers = null)
    Parameters
    Type Name Description
    Stream messageStream

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Returns
    Type Description
    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.

    Declaration
    public void RawProduce(Stream? messageStream, IReadOnlyCollection<MessageHeader>? headers, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)
    Parameters
    Type Name Description
    Stream messageStream

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Action<IBrokerMessageIdentifier> onSuccess

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

    Action<Exception> onError

    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    CancellationToken cancellationToken

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

    Returns
    Type Description
    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    CancellationToken cancellationToken

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

    Returns
    Type Description
    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Action<IBrokerMessageIdentifier, TState> onSuccess

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

    Action<Exception, TState> onError

    The callback to be invoked when the produce fails.

    TState state

    The state object to be passed to the callbacks.

    Type Parameters
    Name Description
    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.

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

    The message.

    IReadOnlyCollection<MessageHeader> headers

    The optional message headers.

    Action<IBrokerMessageIdentifier, TState> onSuccess

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

    Action<Exception, TState> onError

    The callback to be invoked when the produce fails.

    TState state

    The state object to be passed to the callbacks.

    Type Parameters
    Name Description
    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).

    Implements

    IProducer
    IDisposable
    GitHub E-Mail
    ↑ Back to top © 2026 Sergio Aquilini