kafka_send()

Read(161) 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:

The external library function enables a producer to send messages according to configurations by the server. It supports both single-machine mode and cluster mode.

With the single-machine mode, parameter key can be absent; and with the cluster mode, parameters partition, key and value must be present.

Parameters:

fd

A consumer object

key

The key word of a message

value

Value of a message

partition

The index number of a topic partition in a cluster, which is an integer 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")

Omitt parameter key with a single-machine node

4

=kafka_open@c(file("D://kafka.properties");"topic-test")

 

5

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

Parameters must be present with a cluster mode

6

=kafka_close(A1)

Close the Kafka connection