produce
produce writes a Kafka stream from an in-memory table.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| table | Table | Source table with data to write to the Kafka stream. |
| kafka_config | dict | Configuration for the associated Kafka producer. This is used to call the constructor of |
| topic | String | Name of the topic to write to. |
| key_spec | KeyValueSpec | Specifies how to map table column(s) to the Key field in produced Kafka messages. It can be any of the following, found in
|
| value_spec | KeyValueSpec | Specifies how to map table column(s) to the Value field in produced Kafka messages. It can be any of the following, found in
|
| last_by_key_columns optional | bool |
|
Returns
A Kafka stream from an in-memory table.
Examples
In the following example, produce is used to write to the Kafka topic testTopic from a Deephaven table.
- The first positional argument,
{'bootstrap.servers': 'redpanda:9092'}, is a Python dictionary that is standard for any Python library consuming messages from Kafka. This dictionary gives the underlying Kafka library information about the Kafka infrastructure.- Here, we specify the host and port for the Kafka server to use to bootstrap the subscription. This is the minimal amount of required information.
- The value
redpanda:9092corresponds to the current setup for development testing with Docker images (which uses an instance of redpanda).
- The second positional argument is the name of the topic (
testTopic). - The third positional argument writes column
Xto the stream. - The fourth positional argument says to ignore values.
In the following example, produce is used to write Kafka topic topic_group with additional settings last_by_key_columns as True. This indicates that we want to perform a last_by on the keys before writing to the stream.