Chapter 11

Connectors and Sinks

A Connector is the low-level channel EMQX uses to reach an external system, and a Sink pushes the data a rule produces out to targets such as Webhook, HTTP, Kafka and PostgreSQL/MySQL; this chapter works mainly with Webhook/HTTP.

Why this matters

Once the Rule Engine has shaped the data, getting it out again is a separate problem. To push a sensor event at home into a phone notification, an SMS gateway, a cloud API or a relational database, you first have to build a connection channel from EMQX to that external system.

EMQX 5.x splits that job into a Connector (the connection) and a Sink (the output): you create a Connector once and several Sinks and Sources can share it, and the Sink is what actually delivers a rule's output to the external target. Webhook/HTTP is the easiest starting point to try in a smart home.

Core concepts

A Connector is the low-level connection channel from EMQX to an external data system. It is responsible only for how to connect, never for which data gets processed. When you create a Sink or a Source you can pick a Connector that already exists, or create one on the spot.

  • Settings stay separate: connection details (server address, credentials) sit apart from data settings (rules, topic mapping, payload templates), so changing the connection does not affect the rules.
  • Reuse: an external system that several Sinks and Sources talk to needs only one Connector.
  • Observable state: the Dashboard shows each Connector's connection state (Connecting, Connected, Disconnected, Inconsistent), which helps when you troubleshoot.

A Sink decides which external target a rule's output goes to and in what format — Webhook, HTTP Server, Kafka or a database, for example. It sits in the rule's "Action Outputs", where you pick a Connector and fill in its parameters.

Terms at a glance

TermPlain EnglishIn one line
ConnectorconnectionThe low-level connection channel to an external system
Sinkoutput targetThe external target EMQX writes its data out to
Sourceinput sourceThe entry point that brings data from an external system into EMQX
WebhookHTTP callbackAn external target that receives messages over HTTP
HTTP Server Integrationdata out over HTTPSends data into an HTTP service through a Connector plus a rule

Hands-on

Following the official tutorial's HTTP Server Sink example, send the MQTT messages on t/# to a Flask HTTP service on the local machine.

  1. Create the HTTP Server Connector

    In the Dashboard sidebar go to Integration → Connectors, click Create, pick the HTTP Server connector, name it my_httpserver and set the URL to http://localhost:5000. You can click Test Connectivity first to check it.

  2. Create the rule

    Go to Integration → Rules → Create and enter SELECT * FROM "t/#" as the SQL.

  3. Add the HTTP Sink action

    Click + Add Action and set Type to HTTP Server. Pick my_httpserver from the Connector dropdown, set Method to POST, and fill in the name and description.

  4. Create the rule

    Back on the Create Rule page, confirm the Sink is listed under Action Outputs and click Create to finish.

  5. Trigger it with a message

    Use MQTTX to publish to t/1, for example {"msg":"hello HTTP Server"}, then look at the Flask server for the POST request it received.

What a connector can target

EMQX 5.8.9 offers many external targets you can use as a Sink, but the Open Source edition can reach only a few of them. The official Connector documentation states that EMQX Open Source supports only two connectors, HTTP and MQTT; Kafka, PostgreSQL, MySQL, AWS and Azure targets are Enterprise edition features.

TargetBest forEdition
WebhookSending MQTT data straight to an HTTP service, with no rule processingOpen Source
HTTP ServerFiltering or reshaping with a rule before sending it out over HTTPOpen Source
MQTT BrokerBridging across brokers (Chapter 12)Open Source
KafkaPushing an event stream into a Kafka message queueEnterprise
PostgreSQL/MySQLWriting device data straight into a relational databaseEnterprise

The difference between Webhook and HTTP Server is mainly whether a rule (SQL) processes the data first: Webhook is simpler and needs no SQL, while HTTP Server can take a rule's output and build the request header, the body and even the URL from it.

Sending data out over Webhook/HTTP

The first thing most people try in a smart home is sending an event notification to an HTTP service. There are two routes:

  • Webhook (simpler): no rule processing, so it suits a simple integration where you only need to hand the message you received to an external HTTP endpoint, and the target is clear.
  • HTTP Server Integration (more advanced): the Rule Engine extracts and transforms the data first, then it goes to the HTTP service. Create the HTTP Server Connector (URL, method) first, then add the rule and the HTTP Sink action.

An HTTP Sink can use POST, PUT and other methods, and you can set the request body and the credentials (the ${var} placeholder works there). EMQX shows each Sink's connection state and request count, so it is easy to confirm the data is going out.

To send a single status notification to one API, Webhook is the lightest option. When you need to filter, add fields or reshape the data before it leaves, use an HTTP Sink together with a rule.

Troubleshooting

  • The external HTTP service receives nothing: check that the Connector state is Connected, that the URL and Method are correct, that the Sink has been added to the rule, and that the rule is enabled.
  • Kafka, PostgreSQL and MySQL connectors are not in the list: Open Source supports only the HTTP and MQTT connectors; those targets are Enterprise.
  • Data stops after you change a Connector: updating a Connector that is in use reloads its Sinks and Sources, which can interrupt traffic briefly, so make the change off peak.
  • A Connector will not delete: a Connector that is in use cannot be deleted; delete the Sinks and Sources that depend on it first. The Dashboard lists the Sinks attached to it.

FAQ

What is the difference between a Connector and a Sink?

A Connector is the low-level connection channel: which external system you connect to. A Sink is the setup that sends a rule's output to that target, and it lives in the rule's Action. One Connector can serve several Sinks and Sources.

How do I choose between Webhook and HTTP Server?

If the data needs no rule processing, Webhook is the simplest. If you need to strip noise out first and then redirect it, use an HTTP Server Sink together with a rule. The official advice is to use Webhook directly when no rule processing is needed.

Which external targets can Open Source connect to?

The Open Source edition supports only two connectors, HTTP and MQTT. Kafka, PostgreSQL, MySQL and similar targets are Enterprise edition features.

Do I need Enterprise to send data to a database?

The native database Sinks (PostgreSQL, MySQL and so on) are available only in the Enterprise edition. On Open Source you can use an HTTP Sink against your own database API instead, or bridge over MQTT to a separate data processing service.

Official sources