TBEL Overview
ThingsBoard Expression Language (TBEL) is a lightweight scripting language purpose-built for IoT data transformation. It is a fork of MVEL with additional security constraints and built-in memory management.
TBEL is the default scripting engine for Script calculated fields, rule engine filter and transformation nodes, and other server-side scripting contexts.
Motivation
Section titled “Motivation”Prior to TBEL, ThingsBoard used Nashorn (the JDK-bundled JavaScript engine) for server-side scripting. Nashorn was deprecated in JDK 11 and removed in JDK 15 — leaving two alternatives:
- GraalVM JavaScript: Excellent but carries a heavy runtime footprint and licensing constraints that make it impractical for most self-hosted deployments.
- Remote JS Executors: Node.js processes that receive scripts over the message queue. They work, but add inter-process communication latency and consume extra system resources.
TBEL was created to provide a fast, secure, zero-dependency scripting option that runs inside the JVM without external processes.
TBEL vs Nashorn
Section titled “TBEL vs Nashorn”TBEL delivers roughly 1 000× better performance for typical transformation scripts.
| Metric | Nashorn | TBEL |
|---|---|---|
1 000 iterations of return msg.temperature > 20 | ~16 000 ms | ~12 ms |
| Startup cost per script | High (JIT compilation) | Negligible |
| Memory isolation | Weak | Strong (per-execution memory limit) |
| Security sandbox | Manual, error-prone | Built-in (restricted class access) |
TBEL vs JS Executors
Section titled “TBEL vs JS Executors”| Aspect | Remote JS Executors | TBEL |
|---|---|---|
| Additional process | Yes (Node.js) | No |
| Network/queue overhead | Yes | No |
| Language | Full ES6+ JavaScript | MVEL-based (Java-like) |
| Use case | Complex scripts that need full JS ecosystem | Typical IoT transformations |