public interface Producer
extends java.lang.AutoCloseable
The Producer interface only exposes the Channel methods to produce records. It does not expose
methods to consume records. Objects complying with Producer interface are instantiated using
ProducerBuilder which implements a build pattern for Producer.
Producer is easier to use than Channel when you only need to produce records and not to consume
them. Benefits are:
Channel
consume operations (e.g.: consumerGroup, consumerPathPrefix, extraConfigs)
- a slim set of operations to produce only. Consume operations are not exposed, then it is not possible to call them
by accident.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the Producer channel.
|
void |
produce(ProducerRecords producerRecords)
Produce records to the channel.
|
void |
produce(java.lang.String jsonProducerRecords)
Produce records to the channel.
|
void produce(ProducerRecords producerRecords) throws PermanentError, TemporaryError
Produce records to the channel.
producerRecords - a ProducerRecords object containing the records to be posted to the channel.PermanentError - if produce request was malformed or produce RESTful service was not found.TemporaryError - if produce request was temporarily not authorized or there was an internal RESTful error
while serving the request.void produce(java.lang.String jsonProducerRecords)
throws PermanentError,
TemporaryError
Produce records to the channel.
jsonProducerRecords - a String object containing the records to be posted to the channel in
JSON string format.PermanentError - if produce request was malformed or produce RESTful service was not found.TemporaryError - if produce request was temporarily not authorized or there was an internal RESTful error
while serving the request.void close()
throws TemporaryError,
StopError,
PermanentError
Closes the Producer channel.
It calls Channel.destroy() to stop the channel and to release its resources.
This method is added to allow Channel to be used in conjunction with Java try-with-resources statement.
close in interface java.lang.AutoCloseableStopError - if the attempt to stop the channel fails.TemporaryErrorPermanentError