Syntax

kafkaSend(
    producer: "producer-id", 
    message: $message, 
    key: $key, 
    headers: $headers,
    topic: "my-topic", 
    timeout: 3000,
    partition: 0
)

Description

Sends a message via an Apache Kafka server. The message is passed to the named producer, which sends it according to its configuration.

Parameters

Message name Type Type Description Mandatory Default
producer Character string Name of the Kafka producer Yes -
message any value The message to be sent. The value must be able to be processed by the producer's serializer. yes -
key any value The key for the message. The value must be able to be processed by the producer's serializer. See the Apache Kafka documentation for details. no -
headers Dictionary, list

A set of key/value pairs. If only a list (no dictionary) is passed, the values of the list are used as header keys, each of which has no value.

no -
topic Character string The topic on the Kafka server to which the message is to be sent. no The default topic of the producer
timeout Integer Time in milliseconds before sending is considered to have failed. no 10 seconds
partition Integer Partition of the topic from which the message is to be processed, see Apache Kafka documentation. no -

Return value

There is no return value. Communication using Apache Kafka is asynchronous.

Examples

Sending a string message to the default topic of the producer

kafkaSend(producer: "your-producer", message: "Hello World");

Sending a JSON message to a special topic

For sending JSON messages, the "generic serializer" must be configured at the producer.

kafkaSend(
    producer: "your-producer", 
    topic: "your-topic"	

    message: {
        "question": "Hello World! How are you?",
        "priority": 42
    },
    key: {
        "channel": "irrelevant questions",
        "some-key": "some-value"
    }
    headers: {
        "key-1": "value-1",
        "key-2": "value-2",
        "key-3": "value-3"
    },

    timeout: 10000,
    partition: 0
)

Configuration of the producer

Producers are defined in the application configuration. They can be viewed and edited in the Service Editor under "Kafka Producer Service". The Service Editor is located in the "Administration > Development > Service Editor" view.

The message content (message) and the key (key) must be able to be processed by the serializers for content and key stored in the producer. To send JSON-formatted messages, it is advisable to use the generic serializer.

Receiving messages

To receive messages from an Apache Kafka server, a "receiver" with a "message processor" must be configured in the "Kafka Receiver Service". The "TL script message processor" is available for the in-app configuration. This is configured with a TL script that is called as soon as a message is received.