Java API
Versions of interfaces adopted by Kafka are consistent with those in Open Source Community. For details, see https://kafka.apache.org/24/documentation.html.
Major Interfaces of a Producer
Parameter |
Description |
Remarks |
---|---|---|
bootstrap.servers |
Broker address list |
The Producer creates connections with the Broker based on this parameter. |
security.protocol |
Security protocol type |
The Producer uses the security protocol of the type specified by this parameter. In security mode, only the SASL protocol is supported, so this parameter needs to be configured as SASL_PLAINTEXT. |
sasl.kerberos.service.name |
Service name |
This parameter specifies the Kerberos user name used by the Kafka cluster for running. This parameter needs to be configured as kafka. |
key.serializer |
Serialization of key values in messages |
This parameter specifies how to serialize the key values in messages. |
value.serializer |
Serialization of messages |
This parameter specifies how to serialize transmitted messages. |
Return Value |
Interface Function |
Description |
---|---|---|
java.util.concurrent.Future<RecordMetadata> |
send(ProducerRecord<K,V> record) |
Indicates a TX interface without a callback function. Generally, the get() function of Future is used for synchronous transmission. |
java.util.concurrent.Future<RecordMetadata> |
send(ProducerRecord<K,V> record, Callback callback) |
Indicates a TX interface with a callback function. Generally, this interface uses the callback function to process transmission results after asynchronous transmission. |
void |
onCompletion(RecordMetadata metadata, Exception exception); |
Indicates the interface method for a callback function. This method is used to process asynchronous transmission results. |
Major Interfaces of a Consumer
Parameter |
Description |
Remarks |
---|---|---|
bootstrap.servers |
Broker address list |
The Consumer creates connections with the Broker based on this parameter. |
security.protocol |
Security protocol type |
The Consumer uses the security protocol of the type specified by this parameter. In security mode, only the SASL protocol is supported, so this parameter needs to be configured as SASL_PLAINTEXT. |
sasl.kerberos.service.name |
Service name |
This parameter specifies the Kerberos user name used by the Kafka cluster for running. This parameter needs to be configured as kafka. |
key.deserializer |
Deserialization of key values in messages |
This parameter specifies how to deserialize the key values in messages. |
value.deserializer |
Deserialization of messages |
This parameter specifies how to deserialize received messages. |
Return Value |
Interface Function |
Description |
---|---|---|
void |
close() |
Indicates the interface method for closing the Consumer. |
void |
subscribe(java.util.Collection<java.lang.String> topics) |
Indicates the interface method for subscribing topics. |
ConsumerRecords<K,V> |
poll(final Duration timeout) |
Indicates the interface method for requesting messages. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.