Clients -
kafka :
Producer
Represents a Kafka producer endpoint.
Constructor
__init
(ProducerConfiguration config)
- config ProducerConfiguration
-
Configurations related to initializing a Kafka
Producer
Remote Methods
close | Closes the producer connection to the external Kafka broker.
|
commitConsumer | Commits the offsets consumed by the provided consumer. |
commitConsumerOffsets | Commits the consumer offsets in a given transaction. |
flushRecords | Flushes the batch of records already sent to the broker by the producer.
|
getTopicPartitions | Retrieves the topic partition information for the provided topic.
|
send | Produces records to the Kafka server.
|
Fields
- producerConfig ProducerConfiguration? (default ())
-
Used to store configurations related to a Kafka connection
- connectorId string (default system:uuid())
-
Unique ID for a particular connector
Closes the producer connection to the external Kafka broker.
kafka:ProducerError? result = producer->close();
-
Return Type
(ProducerError?) A
kafka:ProducerError
if closing the producer is failed or else ()
Commits the offsets consumed by the provided consumer.
Parameters
- consumer Consumer
-
Consumer, which needs offsets to be committed
-
Return Type
(ProducerError?) A
kafka:ProducerError
if committing the consumer failed or else ()
Commits the consumer offsets in a given transaction.
Parameters
- offsets PartitionOffset[]
-
Consumer offsets to commit for a given transaction
- groupID string
-
Consumer group ID
-
Return Type
(ProducerError?) A
kafka:ProducerError
if committing consumer offsets failed or else ()
Flushes the batch of records already sent to the broker by the producer.
kafka:ProducerError? result = producer->flushRecords();
-
Return Type
(ProducerError?) A
kafka:ProducerError
if records couldn't be flushed or else ()
Retrieves the topic partition information for the provided topic.
kafka:TopicPartition[]|kafka:ProducerError result = producer->getTopicPartitions("kafka-topic");
Parameters
- topic string
-
Topic of which the partition information is given
-
Return Type
(TopicPartition[] | ProducerError) A
kafka:TopicPartition
array for the given topic or else akafka:ProducerError
if the operation fails
send
(anydata value, string topic, anydata? key, int? partition, int? timestamp)
returns ProducerError?Produces records to the Kafka server.
kafka:ProducerError? result = producer->send("Hello World, Ballerina", "kafka-topic");
Parameters
- value anydata
-
Record contents
- topic string
-
Topic to which the record will be appended
- key anydata? (default ())
-
Key that will be included in the record
- partition int? (default ())
-
Partition to which the record should be sent
- timestamp int? (default ())
-
Timestamp of the record in milliseconds since epoch
-
Return Type
(ProducerError?) A
kafka:ProducerError
if send action fails to send data or else ()