-
-
Notifications
You must be signed in to change notification settings - Fork 3
Document NATS integration #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mavam
wants to merge
6
commits into
topic/new-executor
Choose a base branch
from
topic/nats
base: topic/new-executor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
487b60f
Document NATS integration
mavam 9e64c27
Merge topic/new-executor into topic/nats
mavam 41689e1
Document NATS TLS min version behavior
mavam 35def45
Document message-based from_nats
mavam 781a3e5
Document default message serialization
mavam a8dbe4a
Align broker serialization examples
mavam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| title: NATS | ||
| --- | ||
|
|
||
| [NATS](https://nats.io/) is a messaging system for services, edge deployments, | ||
| and cloud-native applications. Tenzir integrates with NATS JetStream to consume | ||
| messages from subjects and publish events back to subjects. | ||
|
|
||
| Use <Op>from_nats</Op> to consume JetStream messages and <Op>to_nats</Op> to | ||
| publish messages. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Consume JSON messages from a subject | ||
|
|
||
| ```tql | ||
| from_nats "alerts", durable="tenzir-alerts" | ||
| this = string(message).parse_json() | ||
| ``` | ||
|
|
||
| The NATS server must have a JetStream stream that captures the subject you | ||
| consume from. | ||
|
|
||
| ### Publish events to a subject | ||
|
|
||
| ```tql | ||
| subscribe "alerts" | ||
| to_nats "alerts", message=this.print_json() | ||
| ``` | ||
|
|
||
| ### Connect to a secured NATS server | ||
|
|
||
| ```tql | ||
| from_nats "alerts", | ||
| url="tls://nats.example.com:4222", | ||
| auth={token: secret("NATS_TOKEN")}, | ||
| tls={} | ||
| this = string(message).parse_json() | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| - <Op>from_nats</Op> | ||
| - <Op>to_nats</Op> | ||
| - <Guide>collecting/read-from-message-brokers</Guide> | ||
| - <Guide>routing/send-to-destinations</Guide> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| --- | ||
| title: from_nats | ||
| category: Inputs/Events | ||
| example: 'from_nats "alerts"' | ||
| --- | ||
|
|
||
| import TLSOptions from '@partials/operators/TLSOptions.mdx'; | ||
|
|
||
| Consumes messages from a NATS JetStream subject. | ||
|
|
||
| ```tql | ||
| from_nats subject:string, [url=secret, durable=string, count=int, tls=record, | ||
| auth=record, metadata_field=field, _batch_size=int, | ||
| _queue_capacity=int, _batch_timeout=duration] | ||
| ``` | ||
|
|
||
| ## Description | ||
|
|
||
| The `from_nats` operator consumes messages from a NATS JetStream subject. The | ||
| operator produces one event per NATS message with a `message` field of type | ||
| `blob`. It acknowledges messages after the events were pushed downstream. | ||
|
|
||
| The NATS server must have a JetStream stream that captures the subject you | ||
| consume from. The operator uses the default URL `nats://localhost:4222` unless | ||
| you provide `url` or configure `plugins.nats.url`. | ||
|
|
||
| Durable consumers must use explicit acknowledgments. If `from_nats` creates the | ||
| durable consumer, it configures the consumer with explicit acknowledgments. If a | ||
| durable consumer already exists with a different acknowledgment policy, the | ||
| operator exits with an error. | ||
|
|
||
| ### `subject: string` | ||
|
|
||
| The NATS subject to consume from. | ||
|
|
||
| ### `url = secret (optional)` | ||
|
|
||
| The NATS server URL. | ||
|
|
||
| If the URL has no scheme, Tenzir uses `nats://` by default or `tls://` when TLS | ||
| is enabled. Use `nats://`, `tls://`, `ws://`, or `wss://` to select a specific | ||
| transport. | ||
|
|
||
| ### `durable = string (optional)` | ||
|
|
||
| The durable consumer name to use for the JetStream subscription. | ||
|
|
||
| ### `count = int (optional)` | ||
|
|
||
| Exit successfully after consuming `count` messages. | ||
|
|
||
| ### `metadata_field = field (optional)` | ||
|
|
||
| The field that receives a record with NATS message metadata. | ||
|
|
||
| The metadata record contains these fields: | ||
|
|
||
| | Field | Type | Description | | ||
| | :------------------ | :------------- | :----------------------------------------------- | | ||
| | `subject` | `string` | The message subject. | | ||
| | `reply` | `string` | The reply subject, or `null` when absent. | | ||
| | `headers` | `record` | NATS headers as `list<string>` values. | | ||
| | `stream` | `string` | The JetStream stream name, or `null` when absent. | | ||
| | `consumer` | `string` | The JetStream consumer name, or `null` when absent. | | ||
| | `stream_sequence` | `uint64` | The stream sequence number. | | ||
| | `consumer_sequence` | `uint64` | The consumer sequence number. | | ||
| | `num_delivered` | `uint64` | The message delivery count. | | ||
| | `num_pending` | `uint64` | The number of pending messages for the consumer. | | ||
| | `timestamp` | `time` | The JetStream message timestamp. | | ||
|
|
||
| ### `auth = record (optional)` | ||
|
|
||
| Authentication settings for the NATS connection. Each value can be a string or a | ||
| secret. | ||
|
|
||
| Supported authentication records are: | ||
|
|
||
| - `{token: secret("NATS_TOKEN")}` for token authentication. | ||
| - `{user: "alice", password: secret("NATS_PASSWORD")}` for user/password | ||
| authentication. | ||
| - `{credentials: "/path/to/user.creds"}` for NATS credentials files. | ||
| - `{credentials: "/path/to/user.creds", seed: "/path/to/user.nk"}` for | ||
| credentials files with a separate seed file. | ||
| - `{credentials_memory: secret("NATS_CREDS")}` for credentials content stored in | ||
| a secret. | ||
|
|
||
| <TLSOptions /> | ||
|
|
||
| NATS uses the standard Tenzir `tls` record. The nats.c library doesn't expose a | ||
| minimum TLS version setting, so `tls.min_version` is accepted for record | ||
| compatibility but ignored with a warning. | ||
|
|
||
| ### `_batch_size = int (optional)` | ||
|
|
||
| The maximum number of messages to emit in one batch. | ||
|
|
||
| ### `_queue_capacity = int (optional)` | ||
|
|
||
| The maximum number of received messages to queue before applying backpressure. | ||
|
|
||
| ### `_batch_timeout = duration (optional)` | ||
|
|
||
| The maximum time to wait before emitting a partial batch. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Consume messages | ||
|
|
||
| ```tql | ||
| from_nats "alerts" | ||
| ``` | ||
|
|
||
| ### Consume JSON messages | ||
|
|
||
| ```tql | ||
| from_nats "alerts" | ||
| this = string(message).parse_json() | ||
| ``` | ||
|
|
||
| ### Collect NATS metadata | ||
|
|
||
| ```tql | ||
| from_nats "alerts", durable="tenzir-alerts", metadata_field=nats | ||
| parsed = string(message).parse_json() | ||
| nats_subject = nats.subject | ||
| nats_stream_sequence = nats.stream_sequence | ||
| ``` | ||
|
|
||
| ### Connect with token authentication and TLS | ||
|
|
||
| ```tql | ||
| from_nats "alerts", | ||
| url="tls://nats.example.com:4222", | ||
| auth={token: secret("NATS_TOKEN")}, | ||
| tls={} | ||
| this = string(message).parse_json() | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| - <Op>to_nats</Op> | ||
| - <Guide>collecting/read-from-message-brokers</Guide> | ||
| - <Integration>nats</Integration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.