If Apache Iggy is useful to you, give it a star on GitHubStar apache/iggy
Skip to Content
Apache Iggy
ConnectorsSinks
These docs describe the upcoming release. They follow the master branches of apache/iggy and apache/iggy-connectors. For the last release, read the 0.10 release docs, or select a version at the top of the sidebar.

QuestDB Sink

Write messages from Iggy streams to QuestDB tables over QWP, QuestDB's native binary protocol.

The QuestDB sink connector consumes messages from Iggy streams and writes them to QuestDB over QWP, QuestDB's native binary protocol, on a WebSocket transport. Each field of a JSON payload becomes a typed column. The same plugin works with QuestDB open source and QuestDB Enterprise.

This page is a curated subset of the documentation. The canonical reference is the questdb_sink README in the apache/iggy-connectors repository.

The sink requires QuestDB 10.0 or QuestDB Enterprise 4.0, or newer. ack_level = "local_durable" requires QuestDB 10.2.0 or QuestDB Enterprise 4.2.1.

Configuration

Use the broker credentials and runtime setup from the sink guide. From the repository root, build the plugin:

cargo build --release -p iggy_connector_questdb_sink

The sample expects a local QuestDB with its default HTTP port. Save the configuration below in the runtime's connector directory. QuestDB creates the table and its columns from the first rows it receives.

type = "sink"
key = "questdb"
enabled = true
version = 0
name = "QuestDB sink"
path = "target/release/libiggy_connector_questdb_sink"
plugin_config_format = "toml"

[[streams]]
stream = "events"
topics = ["questdb_events"]
schema = "json"
batch_length = 1000
consumer_group = "questdb_sink"

[delivery]
guarantee = "at_least_once"

[plugin_config]
connection_string = "ws::addr=localhost:9000;"
table = "iggy_events"
timestamp_source = "message"
symbol_columns = ["region", "device"]
flush_timeout = "30s"
batch_size = 1000

Create the Iggy stream and topic, then send a JSON row:

./target/release/iggy --username iggy --password iggy stream create events
./target/release/iggy --username iggy --password iggy topic create events questdb_events 1 none 1d
./target/release/iggy --username iggy --password iggy message send --partition-id 0 events questdb_events '{"region":"eu","device":"d1","temperature":21.5}'

Credentials, TLS, store-and-forward, reconnect and multi-host failover are set in the connect string. Use wss:: for TLS. See the QuestDB connect string reference.

Options

OptionTypeDefaultDescription
connection_stringstringrequiredQuestDB connect string, ws:: or wss::. Treated as a secret
tablestringrequiredTarget table
timestamp_sourcestringmessageSource of the designated timestamp: message, origin, payload, or server
timestamp_fieldstringnonePayload field that holds the timestamp as a number. Required with timestamp_source = "payload", and rejected with any other source
timestamp_unitstringautoUnit of the payload timestamp: auto, seconds, millis, micros, or nanos
symbol_columnsarray[]Payload fields stored as SYMBOL
uuid_columnsarray[]Payload fields stored as UUID
integer_columnsarray[]Payload fields stored as LONG
include_stream_columnbooltrueWrite the stream name to iggy_stream
include_topic_columnbooltrueWrite the topic name to iggy_topic
include_partition_columnboolfalseWrite the partition to iggy_partition_id
include_offset_columnboolfalseWrite the offset to iggy_offset
include_headersboolfalseWrite each header to a header_<name> column
ack_levelstringfrom the connect stringok, durable, or local_durable. If unset, request_durable_ack in the connect string decides
flush_timeoutstring30sHow long a chunk waits for its acknowledgement without progress
batch_sizeu321000Maximum rows per chunk
max_flush_bytesusize1000000Flush when the buffer reaches this size, even before batch_size rows
numbers_as_doublebooltrueWrite every JSON number as a DOUBLE
log_rejected_payloadboolfalseAdd a truncated payload to the log line of a rejected record
verbose_loggingboolfalseLog per-batch details at info level instead of debug

Unknown options and invalid values are rejected at startup, and one start reports all of them.

Types

JSONQuestDB
stringVARCHAR, or SYMBOL / UUID when listed in symbol_columns / uuid_columns
numberDOUBLE, or LONG when listed in integer_columns
booleanBOOLEAN
array of numbersDOUBLE[], up to 3 dimensions, when every row of a dimension has the same length
any other arraynot supported, the record is rejected
objectVARCHAR holding the JSON text
null, empty arraycolumn omitted

A payload that is not a JSON object goes into one VARCHAR column named payload.

An auto-created table names its designated timestamp timestamp. A payload field with the same name collides with it, and QuestDB rejects the frame. Create the table first with another timestamp column, or remove the field with the delete_fields transform.

Delivery Semantics

The delivery guarantee is set in the [delivery] table of the connector, not in plugin_config. With guarantee = "at_least_once", the runtime stores the offsets of a batch only after QuestDB acknowledged every row of it at ack_level, and delivers a failed batch again. Use it for every table that must not lose rows. It is also how the official QuestDB clients work. On a disconnect or a failover they send again the rows that the server did not acknowledge yet, and the server removes the duplicates. Without the [delivery] table the runtime delivers at most once, which is best effort: a failed write loses the messages of its batch from the first one that QuestDB did not confirm to the end of the batch, and the sink only logs their offsets. The chunks that QuestDB confirmed before the failure stay written.

A retried batch writes the rows that QuestDB already took a second time. You can use the sink without DEDUP, and the table then holds those rows twice, which may or may not be a problem for your data. If duplicates do not matter to you, leave DEDUP out: ingestion is faster and lighter for the server without it. To keep one copy, let QuestDB remove the duplicates by the DEDUP keys of the table. Create the table with keys that identify a row: the designated timestamp, plus the columns of your payload that are unique for it, for example an order id.

CREATE TABLE orders (
  order_id SYMBOL, amount DOUBLE, timestamp TIMESTAMP
) TIMESTAMP(timestamp) PARTITION BY DAY WAL
DEDUP SKIP KEYS(timestamp, order_id);

DEDUP SKIP KEYS keeps the first row and needs QuestDB 10.2.0 or QuestDB Enterprise 4.2.1. DEDUP UPSERT KEYS replaces the stored row with the later one. With timestamp_source = "server", each copy gets a new timestamp, so the keys cannot match it.

Only if the payload has no unique columns, fall back to the message identity: set include_partition_column = true and include_offset_column = true, which are off by default, and use DEDUP SKIP KEYS(timestamp, iggy_stream, iggy_topic, iggy_partition_id, iggy_offset).

A record that the sink cannot write is a rejected record, for example one with a value of the wrong type in a listed column. At least once, it fails the batch with a permanent error that names its offset, and the runtime stops the delivery there until an operator skips the record. At most once, the record is logged and the rest of the batch is written.

Acknowledgements

  • ok: QuestDB accepted the rows.
  • local_durable: QuestDB flushed the rows to its own disk, so they survive a power loss on the QuestDB host. It needs request_durable_ack=local in the connect string and cairo.commit.mode=adaptive on the server. It works with QuestDB open source.
  • durable: QuestDB Enterprise shipped the write-ahead log of the rows, so they survive a failover. It needs request_durable_ack=on, replicated, local,replicated or replicated,local in the connect string and replication on the server.

If ack_level is unset, request_durable_ack in the connect string selects the level.

With sf_dir in the connect string, the client keeps unacknowledged frames on disk across disconnects and restarts.

Transforms

Transforms can be applied before writing to QuestDB. See the transforms documentation for the available types and their configuration.

On this page