WebSocket source
The WebSocket source opens a connection to a WebSocket server and lands each message it receives as one or more records. Use it to capture a live feed, such as market prices or an internal event stream, that publishes JSON over a WebSocket. Mfd captures only what arrives while it is connected; WebSocket feeds have no replay.
Before you begin
You need:
- A
ws://URL that the machine running Mfd can reach. - A feed that starts sending messages as soon as a client connects. Mfd doesn't send anything after the handshake, so feeds that need a subscribe message aren't supported.
Current limits
wss://(TLS) URLs aren't supported in current builds.headersandping_interval_secondsare accepted in the config but not yet applied, so endpoints that need anAuthorizationheader can't be reached. Use an endpoint that accepts the connection without custom headers, or pass credentials in the URL query string if the service supports it.
Configure
from mfd import Config, DataSourceWebsocket, Pipeline
cfg = Config.discover()
src = cfg.data_source(
"price_feed",
DataSourceWebsocket(url="ws://feeds.internal:8080/prices"),
)
cfg.pipeline("prices", Pipeline(data_source=src))
cfg.save()mfd connect data-source websocket \
--pipeline prices \
--name price_feed \
--url ws://feeds.internal:8080/pricespipelines:
prices:
data_source: data_sources.price_feed
data_sources:
price_feed:
Websocket:
url: "ws://feeds.internal:8080/prices"Run the pipeline and check the result:
Start the sync. Without
--once, Mfd stays connected until you stop it or the server closes the connection.bashmfd sync --pipeline prices --logIn another terminal, read what landed:
bashmfd df --pipeline prices
To capture a fixed window instead, set mode: batch and idle_timeout_seconds, then run mfd sync --pipeline prices --once.
To load the data into a warehouse, add a destination to the pipeline. See Destinations.
Options
| Key | Type | Default | Description |
|---|---|---|---|
url | string | Required | WebSocket URL. Use ws://. |
headers | map of strings | — | Not yet applied to the connection. |
ping_interval_seconds | integer | — | Not yet applied to the connection. |
mode | string | stream | stream stays connected until Mfd stops or the server closes. batch disconnects after idle_timeout_seconds with no new message. |
idle_timeout_seconds | integer | 5 | In batch mode, seconds without a message before the source finishes. |
format | string | json | How each message is parsed: json, csv, xml, or avro. |
batch_size_bytes | integer | — | Not used by this connector. Each message is written individually; tune landing batches with the pipeline buffer thresholds. |
batch_size_seconds | integer | — | Not used by this connector. |
Environment variables
| Key | Type | Default | Description |
|---|---|---|---|
SKIPPR_RUNTIME_ONCE_IDLE_TIMEOUT_SECONDS | integer | 60 | With mfd sync --once in stream mode, seconds without a new message before the run finishes. |
What gets synced
Records. Text messages land as received. Binary messages land as bytes. Empty messages and ping and pong frames are skipped. With the default format: json, a JSON object becomes one record and a JSON array becomes one record per element. With format: avro, send a binary Avro Object Container File.
Namespace. All records land in the namespace websocket.<host>, using the host from url, for example websocket.feeds.internal.
Delivery. Messages that arrive while Mfd isn't connected are lost; the server doesn't resend them. Once received, each message is written to the write-ahead log (WAL) before the next one is read.
Ordering. Mfd processes messages one at a time, in the order the server sends them.
Restarts. When the server closes the connection or the connection fails, the source stops. In continuous mode, the next sync loop reconnects; messages sent in between are not captured.
Schema discovery. The first time a pipeline runs, Mfd discovers the schema from live messages. mfd sync does this automatically if you haven't run mfd discover. Messages received during discover aren't landed.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Error mentioning TLS or an unsupported URL scheme | The URL uses wss://. | Use a ws:// endpoint. |
Handshake fails with 401 or 403 | The endpoint needs an auth header, which isn't applied yet. | Use an endpoint or query-string credential that doesn't need custom headers. |
| Connected, but no records | The feed waits for a subscribe message. | Point Mfd at a feed that streams on connect. |
| Run stops on its own | The server closed the connection. | Check the server's idle and session limits. In continuous mode Mfd reconnects on the next sync loop. |
Next steps
- Destinations: land the feed in a warehouse.
- HTTP client source: poll an HTTP API instead.
- WAL and buffering: control how often batches land.
