Skip to content

EMQX Edge Broker Configuration

The broker system configuration provides settings to control the number of task queue threads, the maximum number of concurrent tasks, and cache settings in the EMQX Edge broker.

Task Queue

Example Configuration

hcl
system {
    num_taskq_thread = 0  # Use a specified number of task queue threads
    max_taskq_thread = 0  # Use a specified maximum number of task queue threads
    parallel = 0          # Handle a specified maximum number of outstanding requests
}

Configuration Item

  • num_taskq_thread: Specifies the number of task queue threads to use.
    • Acceptable range: uint32, Recommend 1 - Core * 2. If the value is set to 0, the system automatically determines the number of threads.
  • max_taskq_thread: Specifies the maximum number of task queue threads to use.
    • Acceptable range: uint32, Recommend 1 - Core * 2. If the value is set to 0, the system automatically determines the maximum number of threads.
  • parallel: Specifies the maximum number of outstanding requests that the system can handle at once.
    • Acceptable range: uint32, Recommend Core * 4. No upper limit, however, too much parallel context actually hurts performance. If the value is set to 0, the system automatically determines the number of parallel tasks.

Cache

EMQX Edge uses SQLite to cache the MQTT data bridge.

Example Configuration

hcl
sqlite {
    disk_cache_size = 102400  # Max number of messages for caching
    mounted_file_path="/tmp/" # Mounted file path 
    flush_mem_threshold = 100 # The threshold number of flushing messages to flash
    resend_interval = 5000    # Resend interval (ms)
}

Configuration Items

  • disk_cache_size: Specifies the maximum number of messages that can be cached in the SQLite database.
    • Value range: 1 - infinity. If the value is set to 0, then the cache for messages is ineffective.
    • Default: 102400.
  • mounted_file_path: Specifies the file path where the SQLite database file is mounted.
    • default: nanomq running path
  • flush_mem_threshold: Specifies the threshold for flushing messages to the SQLite database. When the number of messages reaches the threshold, they will be flushed to the SQLite database.
    • Value range: 1 - infinity
    • Default: 100.
  • resend_interval: (Currently not implemented) Specifies the interval, in milliseconds, for resending the messages after a failure is recovered. This is unrelated to the trigger for the resend operation. Note: Only works for the EMQX Edge broker to resend cached messages to the local client, not for bridging connections.
    • Default: 5000.

Preset Sessions

Preset sessions allow you to publish messages to a client that has not yet connected (a "void" or offline client). Messages with QoS 1 or 2 will be cached just like in a persistent session.

When the client eventually connects, it must still subscribe to the relevant topics on its own.

Example Configuration

hcl
preset.session.1 {
	clientid = "example"
	topic = [
		{
			qos = 2
			remote_topic = "msg1/#"
		},
		{
			qos = 1
			remote_topic = "msg2/#"
		}
	]
}
preset.session.2 {
    ......
}

Each preset.session.X block defines a preset session for an offline client, specifying the clientid, subscribed remote_topics, and their corresponding qos levels. Once the real client connects using the matching clientid, the preset session is automatically taken over, and subsequent behavior is governed by the standard MQTT persistent session mechanism.

Configuration Items

  • clientid: The identifier of the preset session.
    • Required. Must be a UTF-8 string.
  • remote_topic: The topic the preset session subscribes to.
    • Functions like a regular MQTT subscription. QoS messages sent to these topics will be cached before the client connects.
  • qos: The Quality of Service level for the subscription.
    • Required. Must be 1 or 2.