Show / Hide Table of Contents

    Class KafkaProducer

    Produces the messages to an endpoint.

    Inheritance
    object
    Producer
    KafkaProducer
    Implements
    IProducer
    IDisposable
    Inherited Members
    Producer.Produce(object, IReadOnlyCollection<MessageHeader>)
    Producer.Produce(IOutboundEnvelope)
    Producer.Produce(object, IReadOnlyCollection<MessageHeader>, Action<IBrokerMessageIdentifier>, Action<Exception>)
    Producer.Produce<TState>(object, IReadOnlyCollection<MessageHeader>, Action<IBrokerMessageIdentifier, TState>, Action<Exception, TState>, TState)
    Producer.Produce(IOutboundEnvelope, Action<IBrokerMessageIdentifier>, Action<Exception>)
    Producer.Produce<TState>(IOutboundEnvelope, Action<IBrokerMessageIdentifier, TState>, Action<Exception, TState>, TState)
    Producer.RawProduce(byte[], IReadOnlyCollection<MessageHeader>)
    Producer.RawProduce(Stream, IReadOnlyCollection<MessageHeader>)
    Producer.RawProduce(byte[], IReadOnlyCollection<MessageHeader>, Action<IBrokerMessageIdentifier>, Action<Exception>)
    Producer.RawProduce<TState>(byte[], IReadOnlyCollection<MessageHeader>, Action<IBrokerMessageIdentifier, TState>, Action<Exception, TState>, TState)
    Producer.RawProduce(Stream, IReadOnlyCollection<MessageHeader>, Action<IBrokerMessageIdentifier>, Action<Exception>)
    Producer.RawProduce<TState>(Stream, IReadOnlyCollection<MessageHeader>, Action<IBrokerMessageIdentifier, TState>, Action<Exception, TState>, TState)
    Producer.ProduceAsync(object, IReadOnlyCollection<MessageHeader>, CancellationToken)
    Producer.ProduceAsync(IOutboundEnvelope, CancellationToken)
    Producer.RawProduceAsync(byte[], IReadOnlyCollection<MessageHeader>, CancellationToken)
    Producer.RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>, CancellationToken)
    Producer.Dispose()
    Producer.Name
    Producer.DisplayName
    object.GetType()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Silverback.Messaging.Broker
    Assembly: Silverback.Integration.Kafka.dll
    Syntax
    public sealed class KafkaProducer : Producer, IProducer, IDisposable

    Constructors

    KafkaProducer(string, IConfluentProducerWrapper, KafkaProducerConfiguration, IBrokerBehaviorsProvider<IProducerBehavior>, IServiceProvider, ISilverbackLogger<KafkaProducer>)

    Initializes a new instance of the KafkaProducer class.

    Declaration
    public KafkaProducer(string name, IConfluentProducerWrapper client, KafkaProducerConfiguration configuration, IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider, IServiceProvider serviceProvider, ISilverbackLogger<KafkaProducer> logger)
    Parameters
    Type Name Description
    string name

    The producer identifier.

    IConfluentProducerWrapper client

    The IConfluentProducerWrapper.

    KafkaProducerConfiguration configuration

    The configuration containing only the actual endpoint.

    IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider

    The IBrokerBehaviorsProvider<TBehavior>.

    IServiceProvider serviceProvider

    The IServiceProvider to be used to resolve the required services.

    ISilverbackLogger<KafkaProducer> logger

    The ISilverbackLogger<TCategoryName>.

    Properties

    Client

    Gets the related IBrokerClient.

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

    Configuration

    Gets the producer configuration.

    Declaration
    public KafkaProducerConfiguration Configuration { get; }
    Property Value
    Type Description
    KafkaProducerConfiguration

    EndpointConfiguration

    Gets the endpoint configuration.

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

    Methods

    ProduceCore(IOutboundEnvelope)

    Publishes the specified message and returns its identifier.

    Declaration
    protected override 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).

    Overrides
    Producer.ProduceCore(IOutboundEnvelope)

    ProduceCoreAsync(IOutboundEnvelope, CancellationToken)

    Publishes the specified message and returns its identifier.

    Declaration
    protected override 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).

    Overrides
    Producer.ProduceCoreAsync(IOutboundEnvelope, CancellationToken)

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

    Publishes the specified message and returns its identifier.

    Declaration
    protected override 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.

    Overrides
    Producer.ProduceCore<TState>(IOutboundEnvelope, Action<IBrokerMessageIdentifier, TState>, Action<Exception, TState>, TState)
    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