KafkaProducer
Path
com.roma.apic.livedata.client.v1.KafkaProducer
Description
This class is used to produce Kafka messages.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
importClass(com.roma.apic.livedata.client.v1.KafkaProducer);
importClass(com.roma.apic.livedata.config.v1.KafkaConfig);
var kafka_brokers = '1.1.1.1:26330,2.2.2.2:26330'
var topic = 'YourKafkaTopic'
function execute(data) {
var config = KafkaConfig.getConfig(kafka_brokers, null)
var producer = new KafkaProducer(config)
var record = producer.produce(topic, "hello, kafka.")
return {
offset: record.offset(),
partition: record.partition(),
code: 0,
message: "OK"
}
}
|
Constructor Details
public KafkaProducer(Map configs)
Constructs a Kafka message producer.
Parameter: configs indicates configuration information of the Kafka.
Method List
|
Returned Type |
Method and Description |
|---|---|
|
org.apache.kafka.clients.producer.RecordMetadata |
produce(String topic, String message) Produce messages. |
The produce(String topic, String message) method cannot be directly returned. Otherwise, the returned information is empty. For example, do not use the return record statement directly in the preceding example. Otherwise, the returned information is empty.
Last Article: KafkaConsumer
Next Article: KafkaConfig
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.