Connector Guide: WebSocket
This page is generated from the Open Location Hub source documentation and should not be edited in the website repository.
Use WebSocket when you want the simplest connector path into the hub. It maps well to the current bundled demos, it works cleanly with the hub’s auth model, and it does not require you to design topic routing beyond the OMLOX WebSocket topic names.
The bundled connector demonstrators in this repository currently use this approach:
Protocol details live in
specifications/omlox/websocket.md.
When To Choose WebSocket
Choose WebSocket when:
- your connector is an application-style process that already manages a direct connection to the hub
- you want the same ingest path as the bundled examples
- you want per-message auth through
params.token - you want to subscribe to hub topics for validation, logging, or downstream processing in the same transport family
Required Inputs
Most WebSocket-based connectors need:
HUB_HTTP_URL: REST base URL for metadata bootstrap such ashttp://localhost:8080HUB_WS_URL: WebSocket endpoint such asws://localhost:8080/v2/ws/socketHUB_TOKEN: optional JWT access token; required when auth is enabled
The bundled examples also keep upstream URLs, polling intervals, provider IDs, and source-specific settings in environment variables.
Minimal Runtime Flow
The common flow is:
- Load environment variables.
- Create a REST client for provider or trackable upserts when needed.
- Open a WebSocket connection to
GET /v2/ws/socket. - Map upstream data to OMLOX payloads.
- Send wrapper
messageevents to the right topic. - Reconnect and retry when the socket breaks.
The bundled helper modules also keep the connection alive with periodic ping frames and reconnect on send failure.
Publish Shape
For ingest, the connector sends OMLOX wrapper messages. A typical
location_updates publish looks like this:
{
"event": "message",
"topic": "location_updates",
"payload": [
{
"position": { "type": "Point", "coordinates": [8.5705, 50.0333] },
"crs": "EPSG:4326",
"provider_id": "my-connector",
"provider_type": "virtual",
"source": "upstream:object-123"
}
],
"params": {
"token": "..."
}
}
Notes:
payloadis an array, even when you only send one item- omit
params.tokenonly when hub auth is disabled - publish to the topic that matches the payload type and intended behavior
location_updatesis the normal entry point for live location ingest
Subscribe Shape
The same transport can be used to observe hub output topics. A minimal subscription message looks like this:
{
"event": "subscribe",
"topic": "fence_events",
"params": {
"token": "..."
}
}
This is useful when you want to:
- validate what the hub emits after ingest
- capture NDJSON logs during local testing
- confirm that your metadata bootstrap and location mapping behave as expected
Metadata Bootstrap
Most connectors need more than a socket sender. The bundled examples also use REST for idempotent metadata setup:
- create or update the
LocationProvider - upsert
Trackableresources when the upstream source has stable asset IDs - optionally create
ZoneandFenceresources before ingest starts
That split is usually the easiest connector design:
- REST for durable metadata and bootstrap
- WebSocket for live ingest and optional subscriptions
Local Run Path
For local development:
- Start the shared demo runtime:
local-hub/start_demo.sh
- Fetch a token when auth is enabled:
local-hub/fetch_demo_token.sh
- Run your connector against the local hub with
HUB_HTTP_URL,HUB_WS_URL, and optionallyHUB_TOKEN.
See
local-hub/README.md
for the reusable local stack.
Example Projects
Use these as concrete WebSocket examples:
connectors/gtfs/README.md: REST bootstrap for provider, trackables, stations, and fences, then livelocation_updatespublish over WebSocketconnectors/opensky/README.md: REST bootstrap for provider, trackables, and airport fences, then livelocation_updatespublish over WebSocket
If you want to build your own connector quickly, copying one of those patterns is the shortest path.