---
title: MQTT
slug: telemetry-pipeline/mqtt
docTags: 
createdAt: 2025-04-21T01:01:36.421Z
---

# MQTT Sink

The **MQTT** sink delivers **log events** to an **MQTT broker** by publishing messages to a configured **topic**. This guide explains what each parameter does and the operational trade-offs.

## Core Connectivity

### host (required)

The MQTT broker address (DNS name or IP).

Operational impact:

- Incorrect host or network policy issues cause publish failures and buffer growth.&#x20;
- For HA brokers (LB / cluster), make sure host matches the broker access method used in your environment.&#x20;

### port (optional, default: 1883)

TCP port used to connect to the broker.

Operational impact:

- **1883** is the common plaintext MQTT port.&#x20;
- TLS deployments commonly use different ports (often 8883) depending on broker configuration.&#x20;

### keep\_alive (optional, default: 60)

MQTT keep-alive interval in seconds.

What it controls:

- Heartbeat/ping behavior to keep the connection active and detect dead connections.&#x20;

Operational impact:

- Lower values detect failures sooner but add more keep-alive traffic.&#x20;
- Higher values reduce overhead but can increase time-to-detect broken connections.&#x20;

## Publishing Target (Routing)

### topic (required)

The MQTT topic to publish to (templating supported).

What it controls:

- How downstream subscribers receive messages (topic filters and hierarchies are central to MQTT routing).&#x20;

Operational impact:

- Highly dynamic topics (per-host/per-container/per-user) increase topic cardinality and can complicate subscriptions and broker performance.&#x20;
- A stable topic taxonomy is easier to operate and secure (ACLs are usually topic-based).&#x20;

## Delivery Semantics (MQTT QoS and Retained Messages)

### quality\_of\_service (optional, default: atleastonce)

MQTT Quality of Service (QoS) level used for publishes.

Options:

- **atmostonce (QoS 0):** “fire and forget” – lowest latency, highest loss risk.&#x20;
- **atleastonce (QoS 1):** broker acknowledges receipt – duplicates possible.&#x20;
- **exactlyonce (QoS 2):** strongest delivery guarantee – highest overhead/latency.&#x20;

Operational impact:

- QoS 1 is typically the default trade-off for telemetry: better than QoS 0, but duplicates can happen (important for downstream idempotency).&#x20;
- QoS 2 can significantly reduce throughput and increase broker/client CPU due to the extra handshake.&#x20;

### retain (optional, default: false)

Whether published messages should be retained by the broker.

What it does:

- If enabled, the broker stores the last retained message for a topic and delivers it immediately to new subscribers.&#x20;

Operational impact:

- Useful for “state-like” topics (e.g., latest status/health), not usually desirable for high-volume logs.&#x20;
- Can create misleading behavior for logs (new subscribers receive an old retained log message and interpret it as current).&#x20;

## Client Session Behavior

### client\_id (optional)

MQTT client identifier.

Operational impact:

- Many brokers require client IDs to be unique per connection.&#x20;
- Stable client\_id can be important when you rely on persistent sessions (especially with clean\_session=false).&#x20;
- Collisions (two clients using the same ID) can cause frequent disconnects.&#x20;

### clean\_session (optional, default: false)

Controls whether the broker should “clean” session state at login.

What it means:

- **true:** start fresh each time; broker forgets subscriptions/queued messages tied to that client session.&#x20;
- **false:** session may persist across reconnects (depending on broker and MQTT version behavior).&#x20;

Operational impact:

- Persistent sessions can help continuity in intermittent networks, but require stable client\_id and careful broker resource planning.&#x20;
- Clean sessions are simpler operationally and reduce broker-side session state.&#x20;

## Authentication

### user (optional)

MQTT username.

### password (optional)

MQTT password.

Operational impact:

- Use only over TLS; otherwise credentials travel without transport encryption.&#x20;
- Treat as sensitive secret material and rotate according to policy.&#x20;

## Payload Format (Encoding)

### encoding (required)

Controls how each log event is serialized into bytes before publishing.

### encoding.codec (required)

Selects the wire format (commonly json/text/logfmt/raw\_message, plus other structured codecs).

Operational considerations:

- **json:** best for structured downstream parsing, typically larger payloads.&#x20;
- **text/raw\_message:** simplest and smallest, but less queryable downstream.&#x20;
- If you later want to parse logs centrally, selecting a structured encoding early saves effort.&#x20;

### Field filtering and timestamps

- **encoding.only\_fields / encoding.except\_fields:** keep payloads small and avoid leaking sensitive fields.&#x20;
- **encoding.timestamp\_format:** ensures consistent timestamp representation for downstream parsing and correlation.&#x20;

## Buffering and Backpressure

### buffer (optional)

Controls how worker buffers log events when the broker is slow or unreachable.

buffer.type (optional, default: memory)

- **memory:** fast, but buffered data is lost on crash/restart&#x20;
- **disk:** durable across restarts, slower; requires disk sizing and IO planning&#x20;

buffer.max\_size (required)

Hard cap on buffer usage.

Operational impact:

- Too small → pipeline applies backpressure early or drops (depending on when\_full)&#x20;
- Too large → long drain time and potential burst load on broker after recovery&#x20;

buffer.max\_events (optional; memory only, default: 500)

Event-count limit for memory buffers.

buffer.when\_full (optional, default: block)

- **block:** apply backpressure upstream (prefer when you want completeness)&#x20;
- **drop\_newest:** drop new events under sustained pressure (prefer when uptime/latency matters more than completeness)&#x20;

## Safety Limits

### max\_packet\_size (optional, default: 10240)

Maximum packet size for MQTT messages.

Operational impact:

- Protects broker/client from very large events.&#x20;
- If too low, large log events may fail to publish (and may trigger retries/backlog).&#x20;

## TLS (Transport Security)

### tls (optional)

TLS settings for connecting to the broker securely.

Key knobs:

- **tls.enabled:** enable TLS&#x20;
- **tls.ca\_file:** trust roots&#x20;
- **tls.crt\_file / tls.key\_file:** client certificate identity (mTLS), if required&#x20;
- **tls.verify\_certificate / tls.verify\_hostname:** validation controls&#x20;

Operational guidance:

- Don’t disable verification in production unless you explicitly accept the risk.
