mqtt-rewriter is a tool that can forward data from a topic to another topic.

mqtt-rewriter

Background

mqtt-rewriter is a tool that can forward data from a topic to another topic.

Install

Todo...

Usage

Currently only supports two types of forwarding:

  • Delay
  • Template

Delay

Forward raw data from $delay/interval/actual_topic to actual_topic after interval milliseconds.

Template

Use the go template to render the data or not and forward it to the corresponding topic.

Example

Use the following config.yml

rewriter:
  delay:
    enable: true
  template:
    enable: true
    rules:
      - topic: test
        type: raw
        targets:
          - topic: test2
      - topic: test2
        type: json
        targets:
          - topic: test3
            template: |-
              Get value: {{.msg}}
              Get nested value: {{.data.msg}}
              Get value of an array by index: {{index .array 0}}
              Get json of an object: {{json .data}}
              Get json of an array: {{json .array}}
              Range an array: 
              {{range $value := .array -}}
              {{println $value}}
              {{- end}}
              Range an array with index: 
              {{range $index,$value := .array -}}
              {{printf "%d:%s\n" $index $value}}
              {{- end}}
              Range an object:
              {{range $key,$value := .data -}}
              {{printf "%s:%s\n" $key $value}}
              {{- end}}

Send a data to test

{
  "msg": "I'm msg.",
  "data": {
    "msg": "I'm msg of data.",
    "msg2": "I'm msg2 of data."
  },
  "array": ["I'm element of array[0]", "I'm element of array[1]"]
}
  1. Match the first rule

    - topic: test
      type: raw
      targets:
        - topic: test2

    This rule type is raw, then program will forward raw data to topic test2.

  2. Match the second rule when program forward raw data to test2

    - topic: test2
      type: json
      targets:
        - topic: test3
          template: |-
            Get value: {{.msg}}
            Get nested value: {{.data.msg}}
            Get value of an array by index: {{index .array 0}}
            Get json of an object: {{json .data}}
            Get json of an array: {{json .array}}
            Range an array: 
            {{range $value := .array -}}
            {{println $value}}
            {{- end}}
            Range an array with index: 
            {{range $index,$value := .array -}}
            {{printf "%d:%s\n" $index $value}}
            {{- end}}
            Range an object:
            {{range $key,$value := .data -}}
            {{printf "%s:%s\n" $key $value}}
            {{- end}}

    So we will received following data from topic test3

     Get value: I'm msg.
     Get nested value: I'm msg of data.
     Get value of an array by index: I'm element of array[0]
     Get json of an object: {"msg":"I'm msg of data.","msg2":"I'm msg2 of data."}
     Get json of an array: ["I'm element of array[0]","I'm element of array[1]"]
     Range an array:
     I'm element of array[0]
     I'm element of array[1]
    
     Range an array with index:
     0:I'm element of array[0]
     1:I'm element of array[1]
    
     Range an object:
     msg:I'm msg of data.
     msg2:I'm msg2 of data.
    
Owner
fissssssh
A 🐟 of loving coding.
fissssssh
Similar Resources

Send IR command through MQTT

Introduction This program can be used in two different modes: Either it is waiting for an id button on a MQTT topic and execute the corresponding LIRC

Nov 9, 2022

Simple BLE to MQTT gateway

BLE_to_MQTT_gw Simple BLE to MQTT gateway This app will scan for the Eddystone BLE advertisement packets from my ESP32 BLE sensor, and forward tempera

Dec 29, 2021

Smq - Simple MQTT Broker with golang

Simple MQTT Broker 关于 Golang MQTT Broker, Version 3.1.1, and Compatible for ecli

Jul 7, 2022

Dwarka - API gateway offers REST API to manage various device controlled using MQTT protocol

dwarka API gateway offers REST API to manage various device controlled using 'MQ

Sep 16, 2022

Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top of it

Courier Golang Client Library Introduction Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top

Nov 19, 2022

A project outputs Bluetooth Low Energy (BLE) sensors data in InfluxDB line protocol formatA project outputs Bluetooth Low Energy (BLE) sensors data in InfluxDB line protocol format

Intro This project outputs Bluetooth Low Energy (BLE) sensors data in InfluxDB line protocol format. It integrates nicely with the Telegraf execd inpu

Apr 15, 2022

Make IoT a lot more fun with data.

Eywa What is Eywa? "Eywa is the guiding force and deity of Pandora and the Na'vi. All living things on Pandora connect to Eywa." -- Avatar Wiki Projec

Nov 28, 2022

Golang DNSTAP sensor use to collect passive dns data from a recursive name server

dnstap-sensor DNSTAP-SENSOR is a Golang program that is used to collect passive dns data from a recursive name server and submit it to Deteque's DNSTA

Nov 21, 2022

Krakend-jwt-header-rewriter - Kraken Plugin - JWT Header Rewriter

Kraken Plugin - JWT Header Rewriter 1 Plugin Configuration Name Desciption Defau

Feb 15, 2022

Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.1.1 and V5 in golang

中文文档 Gmqtt News: MQTT V5 is now supported. But due to those new features in v5, there area lots of breaking changes. If you have any migration problem

Jan 5, 2023

Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT.

Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT.

Vallox RS-485 MQTT gateway to integrate Vallox RS485 ventilation device to Home Assistant via MQTT. Implements Home Assistant MQTT discovery but can also be used without Home Assistant.

Dec 26, 2021

Sensirion SCD30 CO2 sensor MQTT gateway with Home Assistant MQTT discovery

Sensirion SCD30 CO2 sensor MQTT gateway for Home Assistant Overview This gateway can be used to publish measurements SCD30 to mqtt. It supports Home A

Oct 10, 2022

Lg-ess-mqtt - MQTT Firmware Extension for 1st generation LG ESS BESS

lg-ess-mqtt This projects is a firmware extension for the 1st generation LG ESS

Oct 19, 2022

SQL Optimizer And Rewriter

SQL Optimizer And Rewriter

文档 | FAQ | 变更记录 | 路线图 | English SOAR SOAR(SQL Optimizer And Rewriter) 是一个对 SQL 进行优化和改写的自动化工具。 由小米人工智能与云平台的数据库团队开发与维护。 功能特点 跨平台支持(支持 Linux, Mac 环境,Wind

Jan 4, 2023

Cheat - A program that fetches data from cht.sh based on the topic

cheat cheat is a program that fetches data from cht.sh from the topic that the user provided. Quick Start Clone this repo: git clone https://github.co

Jan 5, 2022

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Jan 9, 2023

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Jan 6, 2023

A tiny wrapper around NSQ topic and channel :rocket:

Event Bus NSQ A tiny wrapper around go-nsq topic and channel. Protect nsq calls with gobreaker. Installation go get -u github.com/rafaeljesus/nsq-even

Sep 27, 2022
Sensirion SCD30 CO2 sensor MQTT gateway with Home Assistant MQTT discovery

Sensirion SCD30 CO2 sensor MQTT gateway for Home Assistant Overview This gateway can be used to publish measurements SCD30 to mqtt. It supports Home A

Oct 10, 2022
Lg-ess-mqtt - MQTT Firmware Extension for 1st generation LG ESS BESS

lg-ess-mqtt This projects is a firmware extension for the 1st generation LG ESS

Oct 19, 2022
Store a topic messages to database table

Store messages to database table by structure hints The message type in the broker must be the json object Only use one table for store data Configura

Dec 13, 2021
Hermes is a tiny MQTT compatible broker written in Go.

Hermes Hermes is a tiny MQTT compatible broker written in Go. The goals of the project are as below Easy to compile, and run Tiny footprint Extensible

Sep 9, 2022
IP Camera Alarm Server to MQTT

IP Camera Alarm Server Universal Alarm Server for all your IP cameras in one place! Integrates well with Home Assistant, Node-Red, etc. Runs great on

Dec 8, 2022
handle multiple mqtt server/cluster based on paho client

pakhshi Introduction Consider you have an array of brokers but you want to publish and subscribe on all of them at the same time. Why you may need thi

Nov 9, 2022
Generic Prometheus ⟷ MQTT Bridge

Promqtt: Prometheus ⟷ MQTT Bridge Promqtt makes Prometheus MQTT capable in a truly generic way. It has no assumptions on message payloads or topic lay

Sep 18, 2022
MQTTtimer is based mqtt protocol sync timer

MQTTTimer is based mqtt protocol sync timer. You can used ntp sync time protocol in IoT without ntp server. used mqtt protocol sync time is tcp connne

Oct 27, 2021
An embeddable lightweight Go/Golang MQTT broker(server) for IoT.
An embeddable lightweight Go/Golang MQTT broker(server) for IoT.

Snple MQTT 简体中文 Note: The API of this library is still unstable and has not been sufficiently tested, please do not use it in production environments.

Sep 12, 2022
A robust and easy to use MQTT rule engine
A robust and easy to use MQTT rule engine

⚙ MQTT COMMANDER A robust and easy to use MQTT rule engine Configure your MQTT Rules via easy to use YML Files Supports JSON encoded MQTT Messages Sup

Sep 21, 2022