API: producer
Source:
kafka/producer.ts
Provides an API for configuring and managing Kafka producers, allowing scripts to create topics, send messages, and close the producer connection.
Usage
// Send
import { producer } from "sdk/producer";
producer.topic("topic1", "{}").send("key1", "value1");
// Close
import { producer } from "sdk/producer";
producer.close("{}");Classes
Producer
The Producer class serves as the main entry point for creating and configuring
Kafka topic producers.
Methods
topic
topic (destination:string, configuration:{[key:string]:string}={}):TopicCreates a new topic configuration wrapper that can be used to send messages
to a specific Kafka topic.
@param destination The name of the Kafka topic to send messages to.
@param configuration Optional key-value object containing Kafka producer properties
(e.g., 'bootstrap.servers', 'acks').
@returns A {@link Topic} instance configured for the specified destination and properties.
close
close (configuration:{[key:string]:string}={}):voidCloses the Kafka producer connection pool, releasing associated resources.
This should be called when message sending is complete to ensure proper cleanup.
@param configuration Optional key-value object containing the configuration
used to initialize the producer to be closed.
Topic
Represents a configured Kafka topic that can be used to send messages.
Methods
send
send (key:string, value:string):voidSends a message with an optional key to the configured Kafka topic.
@param key The key of the message. Messages with the same key go to the same partition.
@param value The content of the message to be sent.