Class KafkaProducer
Produces to an endpoint.
Inheritance
Inherited Members
Namespace: Silverback.Messaging.Broker
Assembly: Silverback.Integration.Kafka.dll
Syntax
public class KafkaProducer : Producer<KafkaBroker, KafkaProducerEndpoint>, IProducer, IDisposable
Constructors
| Improve this doc View sourceKafkaProducer(KafkaBroker, KafkaProducerEndpoint, IBrokerBehaviorsProvider<IProducerBehavior>, IConfluentProducersCache, IServiceProvider, IOutboundLogger<KafkaProducer>)
Initializes a new instance of the KafkaProducer class.
Declaration
public KafkaProducer(KafkaBroker broker, KafkaProducerEndpoint endpoint, IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider, IConfluentProducersCache producersCache, IServiceProvider serviceProvider, IOutboundLogger<KafkaProducer> logger)
Parameters
Type | Name | Description |
---|---|---|
KafkaBroker | broker | The IBroker that instantiated this producer. |
KafkaProducerEndpoint | endpoint | The endpoint to produce to. |
IBrokerBehaviorsProvider<IProducerBehavior> | behaviorsProvider | |
IConfluentProducersCache | producersCache | |
System.IServiceProvider | serviceProvider | The System.IServiceProvider to be used to resolve the required services. |
IOutboundLogger<KafkaProducer> | logger |
Methods
| Improve this doc View sourceDispose()
Declaration
public void Dispose()
Dispose(Boolean)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | A value indicating whether the method has been called by the |
GetConfluentProducer()
Returns the cached Confluent.Kafka.IProducer<TKey, TValue> or creates a new one.
Declaration
protected IProducer<byte[], byte[]> GetConfluentProducer()
Returns
Type | Description |
---|---|
Confluent.Kafka.IProducer<System.Byte[], System.Byte[]> | The Confluent.Kafka.IProducer<TKey, TValue>. |
ProduceCore(Object, Byte[], IReadOnlyCollection<MessageHeader>, String)
Publishes the specified message and returns its identifier.
Declaration
protected override IBrokerMessageIdentifier ProduceCore(object message, byte[] messageBytes, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.Byte[] | messageBytes | The actual serialized message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
Returns
Type | Description |
---|---|
IBrokerMessageIdentifier | The message identifier assigned by the broker (the Kafka offset or similar). |
Overrides
| Improve this doc View sourceProduceCore(Object, Byte[], IReadOnlyCollection<MessageHeader>, String, Action<IBrokerMessageIdentifier>, Action<Exception>)
Publishes the specified message and returns its identifier.
Declaration
protected override void ProduceCore(object message, byte[] messageBytes, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName, Action<IBrokerMessageIdentifier> onSuccess, Action<Exception> onError)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.Byte[] | messageBytes | The actual serialized message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
System.Action<IBrokerMessageIdentifier> | onSuccess | The callback to be invoked when the message is successfully produced. |
System.Action<System.Exception> | onError | The callback to be invoked when the produce fails. |
Overrides
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).
ProduceCore(Object, Stream, IReadOnlyCollection<MessageHeader>, String)
Publishes the specified message and returns its identifier.
Declaration
protected override IBrokerMessageIdentifier ProduceCore(object message, Stream messageStream, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.IO.Stream | messageStream | The actual serialized message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
Returns
Type | Description |
---|---|
IBrokerMessageIdentifier | The message identifier assigned by the broker (the Kafka offset or similar). |
Overrides
| Improve this doc View sourceProduceCore(Object, Stream, IReadOnlyCollection<MessageHeader>, String, Action<IBrokerMessageIdentifier>, Action<Exception>)
Publishes the specified message and returns its identifier.
Declaration
protected override void ProduceCore(object message, Stream messageStream, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName, Action<IBrokerMessageIdentifier> onSuccess, Action<Exception> onError)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.IO.Stream | messageStream | The message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
System.Action<IBrokerMessageIdentifier> | onSuccess | The callback to be invoked when the message is successfully produced. |
System.Action<System.Exception> | onError | The callback to be invoked when the produce fails. |
Overrides
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).
ProduceCoreAsync(Object, Byte[], IReadOnlyCollection<MessageHeader>, String)
Publishes the specified message and returns its identifier.
Declaration
protected override async Task<IBrokerMessageIdentifier> ProduceCoreAsync(object message, byte[] messageBytes, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.Byte[] | messageBytes | The actual serialized message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IBrokerMessageIdentifier> | A System.Threading.Tasks.Task<TResult> representing the asynchronous operation. The task result contains the message identifier assigned by the broker (the Kafka offset or similar). |
Overrides
| Improve this doc View sourceProduceCoreAsync(Object, Byte[], IReadOnlyCollection<MessageHeader>, String, Action<IBrokerMessageIdentifier>, Action<Exception>)
Publishes the specified message and returns its identifier.
Declaration
protected override Task ProduceCoreAsync(object message, byte[] messageBytes, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName, Action<IBrokerMessageIdentifier> onSuccess, Action<Exception> onError)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.Byte[] | messageBytes | The actual serialized message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
System.Action<IBrokerMessageIdentifier> | onSuccess | The callback to be invoked when the message is successfully produced. |
System.Action<System.Exception> | onError | The callback to be invoked when the produce fails. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A System.Threading.Tasks.Task representing the asynchronous operation. The System.Threading.Tasks.Task will complete as soon as the message is enqueued. |
Overrides
Remarks
The returned System.Threading.Tasks.Task completes when the message is enqueued while the callbacks are called when the message is actually produced (or the produce failed).
ProduceCoreAsync(Object, Stream, IReadOnlyCollection<MessageHeader>, String)
Publishes the specified message and returns its identifier.
Declaration
protected override async Task<IBrokerMessageIdentifier> ProduceCoreAsync(object message, Stream messageStream, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.IO.Stream | messageStream | The message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IBrokerMessageIdentifier> | A System.Threading.Tasks.Task<TResult> representing the asynchronous operation. The task result contains the message identifier assigned by the broker (the Kafka offset or similar). |
Overrides
| Improve this doc View sourceProduceCoreAsync(Object, Stream, IReadOnlyCollection<MessageHeader>, String, Action<IBrokerMessageIdentifier>, Action<Exception>)
Publishes the specified message and returns its identifier.
Declaration
protected override async Task ProduceCoreAsync(object message, Stream messageStream, IReadOnlyCollection<MessageHeader> headers, string actualEndpointName, Action<IBrokerMessageIdentifier> onSuccess, Action<Exception> onError)
Parameters
Type | Name | Description |
---|---|---|
System.Object | message | The message to be delivered before serialization. This might be null if RawProduce(Byte[], IReadOnlyCollection<MessageHeader>), RawProduce(Stream, IReadOnlyCollection<MessageHeader>), RawProduceAsync(Byte[], IReadOnlyCollection<MessageHeader>) or RawProduceAsync(Stream, IReadOnlyCollection<MessageHeader>) have been used to produce. |
System.IO.Stream | messageStream | The message to be delivered. |
System.Collections.Generic.IReadOnlyCollection<MessageHeader> | headers | The message headers. |
System.String | actualEndpointName | The actual endpoint to produce to. |
System.Action<IBrokerMessageIdentifier> | onSuccess | The callback to be invoked when the message is successfully produced. |
System.Action<System.Exception> | onError | The callback to be invoked when the produce fails. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A System.Threading.Tasks.Task representing the asynchronous operation. The System.Threading.Tasks.Task will complete as soon as the message is enqueued. |
Overrides
Remarks
The returned System.Threading.Tasks.Task completes when the message is enqueued while the callbacks are called when the message is actually produced (or the produce failed).