EMQX - Upstash Redis Integration
EMQX, a robust open-source MQTT message broker, is engineered for scalable, distributed environments, prioritizing high availability, throughput, and minimal latency. As a preferred protocol in the IoT landscape, MQTT (Message Queuing Telemetry Transport) excels in enabling devices to effectively publish and subscribe to messages.
Offered by EMQ, EMQX Cloud is a comprehensively managed MQTT service in the cloud, inherently scalable and secure. Its design is particularly advantageous for IoT applications, providing dependable MQTT messaging services.
This tutorial guides you on streaming MQTT data to Upstash via data integration. It allows clients to send temperature and humidity data to EMQX Cloud using MQTT and channel it into Upstash for Redis storage.
Setting Up Redis Database with Upstash
-
Log in and create a Redis Database by clicking the Create Database button on Upstash Console.
-
Name your database and select a region close to your EMQX Cloud for optimal performance.
-
Click Create to have your serverless Redis Database ready.
Database Details
Access the database console for the necessary information for further steps.
The above steps, conclude the initial setup for Upstash.
Establishing Data Integration with Upstash
Activating EMQX Cloud’s NAT Gateway
-
Log into the EMQX Cloud console and go to the deployment Overview.
-
Select NAT Gateway at the bottom and click Subscribe Now.
Configuring Data Integration
-
In the EMQX Cloud console, choose Data Integrations and select Upstash for Redis.
-
Input Endpoints info from the Redis detail page into the Redis Server field, including the port. Enter the password in Password and click Test to ensure connectivity.
-
Click New to add a Redis resource. A new Upstash for Redis will appear under Configured Resources.
-
Formulate a new SQL rule in the SQL field. This rule will read from
temp_hum/emqx
and append client_id, topic, timestamp.up_timestamp
: Message report timeclient_id
: Publishing client’s IDtemp
: Temperature dataHum
: Humidity data
SELECT
timestamp as up_timestamp,
clientid as client_id,
payload.temp as temp,
payload.hum as hum
FROM
"temp_hum/emqx"
-
Execute an SQL test with payload, topic, client info. Successful results confirm the rule’s effectiveness.
-
Proceed to Next to link an action. The rule will store the timestamp, client ID, temperature, and humidity in Redis. Click Confirm.
HMSET ${client_id} ${up_timestamp} ${temp}
-
Post-binding, click View Details for the rule SQL and bound actions.
-
To review rules, select View Created Rules in Data Integrations. Check detailed metrics in the Monitor column.
Testing the Data Bridge
-
Simulate temperature and humidity data with MQTTX. Add connection address and client authentication for the EMQX Dashboard.
-
In Upstash Console, under Data Browser, select a client entry to review messages.
Was this page helpful?