Skip to content
DuckDB community extension

nats_js

Query NATS JetStream message streams directly with SQL

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL nats_js FROM community;
LOAD nats_js FROM community;

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Read messages from a stream (the server defaults to nats://localhost:4222)

SQL
-- Read messages from a stream (the server defaults to nats://localhost:4222)
SELECT subject, seq, ts_nats, payload
FROM nats_scan('telemetry', start_seq := 1, end_seq := 100);

-- Filter subjects with NATS wildcards and extract JSON fields, including nested ones
SELECT seq, device_id, location_zone, kw
FROM nats_scan('telemetry',
    subject := 'telemetry.*.power.>',
    json_extract := ['device_id', 'location.zone', 'kw']
);

-- Extract Protocol Buffers fields with native types
SELECT device_id, location_zone, metrics_kw
FROM nats_scan('telemetry_proto',
    proto_file := 'telemetry.proto',
    proto_message := 'Telemetry',
    proto_extract := ['device_id', 'location.zone', 'metrics.kw']
);

Provided by brannn. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

The nats_js extension reads the messages stored in NATS JetStream streams with SQL. It creates no consumers.

Documentation: https://github.com/brannn/duckdb-nats-jetstream

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
brannn/duckdb-nats-jetstream
License
MIT
Maintainers
brannn
Written in
C++
Build source
e3a8038757a1
Build definition
Community descriptor