Skip to main content

Gateway MQTT Collection Client

Purpose

This plugin is used on a central Gateway to collect variables from multiple edge Gateways through one shared MQTT broker connection.

It is not a general MQTT JSON collector. It accepts the current ThingsGateway Gateway MQTT protocol and uses RemoteKey to separate each edge Gateway's variables, devices, online state, snapshots, and remote writes.

Choose a Mode

ModeUse WhenCentral GatewayEdge Gateways
GatewayMqttCollectClientA shared Broker already exists, or every Gateway can only make outbound connectionsUses one persistent ClientId and subscribes to all configured sourcesMultiple MqttClientProducer targets connect to the same Broker and publish under their own RemoteKey
GatewayMqttCollectServerThe central Gateway can expose an inbound MQTT portListens on one port and binds each edge session to a ClientId, credentials, and optional certificate fingerprintMultiple MqttClientProducer targets connect directly to the central Gateway

Prepare the Deployment

  1. Assign every edge Gateway a stable RemoteKey containing only ASCII letters, digits, hyphens, or underscores.
  2. Use the same Topic root on the collector and all edge producers. The default is ThingsGateway/Gateway.
  3. Create an MqttClientProducer on the Data Forwarding page of every edge Gateway, keep Retain disabled, and configure the variable, data-request, and RPC Topics as described below.
  4. For remote writes, enable permissions on the edge producer, the central collector, and the target variable.
  5. Use TLS in production. In Server mode, configure unique credentials for every source. If certificate fingerprints are enabled, bind a different certificate to each source.

Complete Data Path

GatewayMqttCollectClient and GatewayMqttCollectServer run only on the central Gateway and perform inbound collection. MQTT upload from each edge Gateway continues to use the existing MqttClientProducer data-forwarding plugin. No second Gateway-specific producer plugin is required.

Collected variables on an edge Gateway
→ Data-forwarding group (selects scope and trigger mode)
→ MqttClientProducer (uploads values and handles snapshot/write requests)
→ Shared Broker or the central Gateway MQTT listener
→ GatewayMqttCollectClient / GatewayMqttCollectServer
→ Mirror variables on the central Gateway

Client and Server in the plugin names describe the MQTT role of the central collector, not the data direction. In Client mode, the central collector connects to a shared Broker. In Server mode, the central collector listens and each edge MqttClientProducer connects to it.

Configure MQTT Upload on Each Edge

Perform these steps on every edge Gateway:

  1. Sign in to GatewayRuntime Web and open Development Configuration → Data Forwarding.
  2. Create and enable a data-forwarding group, then add every variable to aggregate to the group scope. Variables outside that scope are not uploaded.
  3. Create a target in that group, select MqttClientProducer, and enable the target.
  4. Configure the endpoint for the selected mode, then configure the fixed Topics with this edge Gateway's RemoteKey.
  5. After saving, verify that the target is online and has no CacheDB backlog. Then request a snapshot and synchronize variables from the central collector debug page.

MQTT data-forwarding target on an edge Gateway

Endpoint Mapping

Central Collection ModeEdge MqttClientProducer EndpointIdentity Configuration
GatewayMqttCollectClientEnter the shared Broker address and port. The central collector connects to the same BrokerUse a unique edge ClientId and the Broker account assigned to this edge. Broker ACLs should restrict the edge to its own {TopicRoot}/{RemoteKey}/# namespace
GatewayMqttCollectServerEnter the central Gateway address and the listener port configured by GatewayMqttCollectServerClientId must equal the source's AllowedClientId; username and password must also exactly match that source configuration

Do not use MqttServerProducer on the edge. Client collection requires both sides to connect to one shared Broker, while Server collection requires an edge client to connect to the central listener. MqttClientProducer is the connection initiator in both topologies.

Fixed Topics and Payload Shape

If the collector Topic root is ThingsGateway/Gateway and this edge uses RemoteKey=edge-01, configure its MqttClientProducer as follows:

Edge PropertyValue or Requirement
Variable Topic TemplateThingsGateway/Gateway/edge-01/Variable
Data Request TopicThingsGateway/Gateway/edge-01/RpcQuest
RPC Write TopicThingsGateway/Gateway/edge-01/RpcWrite
Variable List UploadEnabled
Variable Dictionary UploadDisabled
Variable Entity Script / Upload TemplateEmpty; do not change the current fixed payload
JSON Ignore NullDisabled
Retain MessageDisabled; dedicated collection rejects retained messages
Filter Offline DataDisabled so a full snapshot includes offline variables and their metadata
QoS LevelMatch the edge and the central source. With AtLeastOnce, duplicate delivery is allowed and handled idempotently by the collector
Upload Shard SizeGreater than 0, with each JSON batch kept below the collector's Inbound Payload Byte Limit

RemoteKey is not a separate MqttClientProducer property. It is embedded in the three fixed Topics above. Every edge Gateway must use a different RemoteKey. Do not use ${...} placeholders in these Topics, and do not change the payload through an entity script or upload template. The dedicated Gateway MQTT collector does not consume the historical-read RPC Topic.

Open the plugin

Open Development Configuration → Collection Configuration, create one collection device, and select Gateway MQTT Collection Client.

This is a shared-connection plugin: configure multiple remote sources inside this one device. Do not create one ordinary MQTT channel or one Gateway MQTT device for every edge Gateway.

On each edge Gateway, configure the MQTT client forwarding target in the Configure MQTT Upload on Each Edge section below.

Connection and security

SettingDescription
Connection typeDefault Tcp. Select TCP or WebSocket according to the shared broker.
IP addressDefault localhost. Host name or IP address of the shared broker.
PortDefault 1883. Broker port.
WebSocket pathDefault /mqtt. Used only for WebSocket connections.
Client IDPersistent client ID for the central collector. It must be unique on the broker.
Clean sessionDefault enabled. Controls the shared MQTT session state.
MQTT versionDefault 4 (MQTT 3.1.1). Must match the broker.
Enable SSLEnables TLS for the shared connection.
SSL target hostHost name used for certificate validation.
Client certificate / CA certificateCertificates selected from Certificate Management.
Allow untrusted certificateTemporary commissioning option. Disable it in production.
SSL protocol / revocation checkTLS and certificate-revocation controls required by the broker.
Username / passwordCredentials for the central collector on the broker.
Keep-aliveDefault 60 seconds.
Connection timeoutDefault 3000 ms.

Remote sources and protocol

SettingDescription
Topic rootDefault ThingsGateway/Gateway. It must be identical on the central collector and all edge forwarding targets.
Remote sourceOpens the source list. Add one source for each edge Gateway.
RemoteKeyStable identifier used in topics, variable addresses, snapshot requests, and RPC. It must be unique and contain only ASCII letters, digits, hyphens, or underscores.
Display nameHuman-readable source name shown in the debug page.
EnableEnables subscription, snapshots, catalog updates, and RPC for this source.
QoSQoS used by this source's fixed protocol messages.
Allow remote writeEnables write requests from the central collector to edge variables. Keep it disabled unless required.
Snapshot intervalDefault 60 seconds; range 10–3600. Periodic full catalog snapshot interval.
Request timeoutDefault 30 seconds; range 1–600. Timeout for snapshot and RPC requests.
Offline timeoutDefault 180 seconds. Must be greater than the snapshot interval.

Each remote source must have a different RemoteKey. The collector uses one shared MQTT session, while source identity is carried by the protocol namespace.

Capacity limits

SettingDefaultDescription
Remote source limit32Maximum configured edge sources for this device.
Snapshot concurrency4Maximum simultaneous snapshot or synchronization tasks.
Inbound payload limit1048576 bytesMaximum size of one incoming MQTT payload.
Messages per second200Total message rate entering the parser.
Inbound handler concurrency4Maximum concurrent JSON handlers.
JSON depth limit64Maximum accepted protocol JSON nesting depth.
Per-source catalog limit100000Maximum variables in one edge source catalog.
Total catalog limit300000Maximum variables across all sources. It must cover one source limit.
Pending RPC limit256Maximum simultaneous remote RPC batches.
Detailed logDisabledEnables protocol summaries without full sensitive payloads. Disable after commissioning.

Increase limits only after checking memory, broker traffic, and the number of edge sources.

Address rule

Use the remote source key and remote variable ID:

{RemoteKey}/{RemoteVariableId}

Example: factory-a/828746157506629.

The variable ID is the ID reported by the edge Gateway. Do not replace it with the local mirror variable ID.

Functions

FunctionPurpose
Remote gatewayUse Remote gateway with an approved test point and confirm site safety before execution.
Remote variablesUse Remote variables with an approved test point and confirm site safety before execution.
Diagnostic logUse Diagnostic log to inspect mapped values, status, counters, recent messages, or the latest result.
Variable synchronizationUse Variable synchronization to inspect mapped values, status, counters, recent messages, or the latest result.

Device debug

Open Development Configuration → Collection Configuration, select the Gateway MQTT device, and click More Functions, then open Debug.

Gateway MQTT protocol panel

Gateway MQTT Collection Client protocol debug panel

Use the plugin-specific panel to inspect remote sources, request a full snapshot, synchronize the variable catalog, and review diagnostics. Overview and runtime-status tabs are common workspace tabs and are not repeated here.

Verify the configuration

  1. Add one remote source with a unique RemoteKey.
  2. Confirm the edge MQTT target uses the same Topic root and RemoteKey.
  3. Confirm the central target connects to the broker and the source becomes online.
  4. Request a snapshot and wait for the edge catalog to complete.
  5. Read one mirror variable and compare it with the edge value.
  6. Test remote writing only when central, edge, target, and variable permissions all allow it.

Troubleshooting

SymptomCheck
Shared connection cannot startBroker address, port, Client ID, credentials, TLS, CA certificate, and broker ACL.
Source remains offlineRemoteKey spelling, Topic root, edge target state, snapshot interval, and edge protocol messages.
Catalog is emptyEdge forwarding range, variable-list upload, snapshot response, payload limit, and catalog limits.
Values from sources are mixedEvery source must use a unique RemoteKey; every mirror address must use the matching RemoteKey.
Snapshot times outEdge target connectivity, request timeout, message rate, inbound payload size, and broker traffic.
Remote write failsCentral and edge remote-write switches, source metadata permission, local variable permission, and RPC response logs.
Source becomes degradedOffline timeout, snapshot completion, edge reconnect state, and diagnostics.