Skip to content

Mqtt Topic Filter

DodaTech 1 min read

In this tutorial, you'll learn about MQTT Topic Filter Blocks Expected Messages. We cover key concepts, practical examples, and best practices.

The Problem

MQTT topic filter is too restrictive and blocks desired messages.

Quick Fix

Wrong

client.subscribe('sensors/temperature')  # Only exact match
Messages on sensors/temperature/room1 are not received.
// Broader filter using wildcards
client.subscribe('sensors/+/temperature')
// Receives: sensors/room1/temperature, sensors/room2/temperature

// Or multi-level
client.subscribe('sensors/#')
// Receives: everything under sensors/

// Multiple subscriptions
client.subscribe([
  'sensors/+/temperature',
  'sensors/+/humidity',
  'actuators/+/status'
])
All desired messages received using appropriate wildcard patterns.

Prevention

Design topic hierarchy carefully: /domain/device-id/metric. Use specific subscriptions to limit traffic. Filter unwanted messages at the broker (ACL) rather than client. Multiple subscriptions are fine — no overhead penalty. Use shared subscriptions ($share/group/topic) for load balancing.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What is a shared subscription?

Prefix: $share/group/topic. Multiple subscribers in the same group share messages (round-robin). Use for worker pools.

How many subscriptions can a client have?

No hard limit in MQTT spec. EMQX supports thousands per client. Each subscription consumes memory on broker.

Can I unsubscribe and resubscribe?

Yes. client.unsubscribe('topic') removes the subscription. Subscribe again anytime.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro