Unify Applications
Logo
Realtime & MQTT

Realtime & MQTT

Logo

9 mins READ

Overview

Realtime events let one running copy of your app tell every other running copy that something changed — instantly, with nobody pressing refresh. Two people have the same order screen open; one marks the order shipped; the other's screen updates a second later.

realtime_and_mqtt.png
realtime_and_mqtt.png

Realtime events run on MQTT, a publish/subscribe messaging system. The platform provides and manages the MQTT connection — you don't configure a broker, credentials or connection settings. You only name the channels, called topics, that your app publishes and listens on.

Note: Messages are not stored. Only copies of the app that are already listening when a message is published receive it. Topic names match exactly — there is no wildcard or pattern matching.

Defining Topics

Topics are defined once for the app in Settings → Advanced Settings → Realtime Events ("Sync data across users in real time"). The panel isn't available in modules, walkthroughs or template components — define topics on the host app instead.

  1. Turn on realtime events: Turn on Enable Realtime Events. The topic list appears once it's on.

  2. Add a topic: Click Add Topic and enter a Topic Name, for example order-status-updated. The name can't be blank or repeat another topic in the app.

  3. Describe the message (recommended): In Event Schema, add a field for each value the message carries. The schema builds the message form in Send MQTT Event and lets you pick the message's fields in bindings. It is not enforced — messages arrive exactly as they were sent.

Setting

Description

Enable Realtime Events

Shows the topic list. Turning it off does not stop pages that already listen for a topic — remove or disable the page's listener to stop delivery.

Topic Name

The channel's name. Must be unique within the app. Topics are private to the app: the same name in two apps never collides.

Event Schema

Optional list of the fields a message on this topic carries.

Sending a Message

Use the Send MQTT Event action on any block interaction. It has two fields:

  • MQTT Topic — one of the topics defined for the app.

  • Event Message — the message body, built from the topic's event schema. Every field can be bound to a value from the page. Values are resolved when the action runs and sent as one JSON message.

The message is published to the topic name prefixed with the app's ID: APP_ID_topic-name (the app ID, an underscore, then the topic name). An external system that subscribes to or publishes on the topic must use this prefixed name. Copy the app ID from Settings → General → Identity → App ID.

To publish to a topic from an automation, use the Send Mqtt Request action of Utility by UnifyApps. Choose the app in Application Id and enter the topic in Topic Name. The app ID prefix is added for you.

Receiving a Message

Listening is configured on the page (or module), not on a block:

  1. Open the page's settings. In the Interactions section, go to Events.

  2. Add an event and choose On Receive MQTT Event.

  3. Choose the topic, then add the actions to run — for example, refresh a data source or set a page variable that a block reads.

When a message arrives, its actions run with the parsed message available under mqttEvents, keyed by the topic name:

{{ mqttEvents['order-status-updated']['status'] }}

The page connects to the messaging service only when it has an On Receive MQTT Event listener, and only for signed-in users — or for anyone if the app is public.

Example: Refresh a Table for Everyone When a Row Changes

  1. Define the topic: In Settings → Advanced Settings → Realtime Events, add the topic order-status-updated with the fields orderId and status.

  2. Publish the change: On the button that saves the edit, add a Send MQTT Event action. Set MQTT Topic to order-status-updated and fill Event Message, for example bind orderId to the selected row's ID.

  3. React on the page: On the page that shows the table, add an On Receive MQTT Event interaction for order-status-updated and add a Trigger Data Source action that refreshes the table's data source.

  4. Test it: Open the app in two browser windows, change a row in one, and watch the table refresh in the other.

Things to Know

  • Turning realtime events on doesn't sync anything by itself. Nothing travels between users until you add both halves: a Send MQTT Event action where the change happens, and an On Receive MQTT Event listener on the receiving page.

  • Renaming a topic breaks bindings and external publishers. Actions and listeners stay attached, but bindings that name the topic, such as mqttEvents['old-name'], and external systems using the old name stop matching.

  • Treat incoming messages as untrusted. Nothing checks a message against the topic's schema, so write your actions to tolerate missing fields.

  • Need to reach someone whose app is closed? Use push notifications — realtime messages are not queued or replayed.

Page

Relationship

Dev Tools & Debugger

Use the Pulse tab to see when the On Receive MQTT Event interaction and its actions run

Page Variables

Store incoming MQTT messages in page variables for binding to charts and lists

Send Custom Event

Records analytics events — unlike MQTT, nothing in the app listens for them

FAQs

Will a page that opens after a message was sent receive it?

No. Realtime messages are not stored and there is no replay. A message reaches only the copies of the app that are already listening when it is published. If the user must find out whether or not the app is open, use a push notification, or write the value to a record the page reads when it loads.

Can I add an MQTT listener to a block instead of the page?

No. The On Receive MQTT Event interaction is offered only at page (or module) level. Put the listener on the page and let its actions drive the block — for example, refresh a data source or set a variable the block reads.

Can I publish messages from the app back to the broker?

Yes. Use the Send MQTT Event action in any block interaction. Choose the MQTT Topic and fill the Event Message — each field can be static or a binding. The message is published to the topic name prefixed with the app's ID, so external subscribers must use the prefixed topic name.