kafka_subscribe()

Read(264) Label: connect, object,

Description:

Connect to Kafka server.

Syntax:

kafka_subscribe (prop:value,....;topic,...;keyType, valueType) 

kafka_subscribe (filename or fileObject; topic,...; keyType, valueType)

Note:

The function connects to the Kafka server, and inputs the property parameter properties in the form of k:v, or stores properties as a configuration file suffixed with .properties.

Parameters:

prop:value

The property parameter Properties, which will be input in the form of k:v and which can include multiple property parameters; refer to Kaka documents to learn more about this

topic

Query a topic or multiple topics

keyType

The data type of a Consumer key, which is by default the string; it supports int, integer, float, long and string

filename

The property parameter file suffixed with .properties

fileObject

valueType

A file object

The data type of a Consumer key, which is by default the string; it supports int, integer, float, long and string

Return value:

A Consumer object

Example:

 

A

 

1

=kafka_subscribe("D:/kafka_string.properties";"test1";"String","byte[]")

Connect to Kafka server through the configuration file kafka_string.properties where the topic is test1, key is String, and value is byte[]

2

=kafka_subscribe(file("D:/kafka_string.properties");"test1";"String","byte[]")

Connect to Kafka server through the configuration file object, with the rest of the settings being same as the above

3

=kafka_subscribe("bootstrap.servers":"192.168.0.144:9092","zookeeper.connect":"192.168.0.144:2181",

"group.id":"test","zookeeper.session.timeout.ms":"4000","zookeeper.sync.time.ms":"200",

"auto.commit.interval.ms":"500","auto.offset.reset":"latest",

"serializer.class":"kafka.serializer.StringEncoder",

"key.deserializer":"org.apache.kafka.common.serialization.StringDeserializer",

"value.deserializer":"org.apache.kafka.common.serialization.ByteArrayDeserializer";

"test1";"String","byte[]")

Connect to Kafka server through a parameter, with the rest of the settings being same as the above