kafka_send()

Read(2798) Label: publish messages, index number,

Descripition:

A producer publishes messages to topics.

Syntax:

kafka_send(fd, [key,] value)

kafka_send(fd, partition, key, value)

Note:

External library function (See External Library Guide).

 

When there aren’t partitions, parameter key can be absent; and when there are partitions, parameters partition, key and value must be present.

Parameter:

fd

A connection object

key

The key word of a message

value

Value of a message

partition

Index numbers of partitions, which is an integer or a sequence beginning from 0

Example:

 

A

 

1

=kafka_open("D://kafka.properties","topic-test")

Connect to Kafka server.

2

=kafka_send(A1, "A100","apple")

Send a message where the key is A100 and value is apple to A1.

3

=kafka_send(A1,"apple")

Omit parameter key as there are no partitions.

4

=kafka_open(file("D://kafka.properties");"topic-test1")

 

5

=kafka_send(A1,1, "A100","apple")

All parameters must be present as there are partitions.

6

=kafka_close(A1)

Close the Kafka connection.