viewof messageCount = Inputs.range([100, 100000], {
value: 10000,
step: 100,
label: "Number of messages:",
width: 400
})
viewof payloadSize = Inputs.range([10, 1000], {
value: 200,
step: 10,
label: "Payload size (bytes):",
width: 400
})
viewof batteryCapacityMah = Inputs.range([100, 5000], {
value: 2000,
step: 100,
label: "Battery capacity (mAh):",
width: 400
})
{
const mqttOverhead = 2;
const amqpOverhead = 18;
const mqttTotal = messageCount * (payloadSize + mqttOverhead);
const amqpTotal = messageCount * (payloadSize + amqpOverhead);
const bandwidthSavings = ((amqpTotal - mqttTotal) / amqpTotal * 100).toFixed(1);
const mqttSetupRtt = 2;
const amqpSetupRtt = 8;
const mqttUaPerMsg = 50;
const amqpUaPerMsg = 80;
const messagesPerDay = 1000;
const mqttBatteryDays = (batteryCapacityMah * 1000) / (messagesPerDay * mqttUaPerMsg);
const amqpBatteryDays = (batteryCapacityMah * 1000) / (messagesPerDay * amqpUaPerMsg);
const batteryLifeDiff = ((mqttBatteryDays - amqpBatteryDays) / amqpBatteryDays * 100).toFixed(1);
const mqttMemoryKb = 30;
const amqpMemoryKb = 300;
return html`<div style="margin: 20px 0; padding: 20px; background: #f8f9fa; border-left: 4px solid #2C3E50; border-radius: 4px;">
<h4 style="margin-top: 0; color: #2C3E50;">AMQP vs MQTT Protocol Comparison</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 15px 0;">
<div style="background: white; padding: 15px; border-radius: 8px; border: 2px solid #16A085;">
<div style="text-align: center; margin-bottom: 15px;">
<div style="font-size: 24px; font-weight: bold; color: #16A085;">MQTT</div>
<div style="font-size: 12px; color: #7F8C8D;">Lightweight IoT Protocol</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Total Bandwidth</div>
<div style="font-size: 20px; font-weight: bold; color: #2C3E50;">
${(mqttTotal / 1024 / 1024).toFixed(2)} MB
</div>
<div style="font-size: 11px; color: #7F8C8D;">
(${messageCount.toLocaleString()} msgs x ${payloadSize + mqttOverhead} bytes)
</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Setup Time</div>
<div style="font-size: 20px; font-weight: bold; color: #2C3E50;">
${mqttSetupRtt} RTT
</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Battery Life</div>
<div style="font-size: 20px; font-weight: bold; color: #16A085;">
${mqttBatteryDays.toFixed(0)} days
</div>
<div style="font-size: 11px; color: #7F8C8D;">
(${batteryCapacityMah}mAh @ 1k msgs/day)
</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Memory Footprint</div>
<div style="font-size: 20px; font-weight: bold; color: #2C3E50;">
${mqttMemoryKb} KB
</div>
</div>
</div>
<div style="background: white; padding: 15px; border-radius: 8px; border: 2px solid #3498DB;">
<div style="text-align: center; margin-bottom: 15px;">
<div style="font-size: 24px; font-weight: bold; color: #3498DB;">AMQP</div>
<div style="font-size: 12px; color: #7F8C8D;">Enterprise Messaging Protocol</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Total Bandwidth</div>
<div style="font-size: 20px; font-weight: bold; color: #2C3E50;">
${(amqpTotal / 1024 / 1024).toFixed(2)} MB
</div>
<div style="font-size: 11px; color: #E67E22;">
(+${bandwidthSavings}% vs MQTT)
</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Setup Time</div>
<div style="font-size: 20px; font-weight: bold; color: #2C3E50;">
${amqpSetupRtt} RTT
</div>
<div style="font-size: 11px; color: #E67E22;">
(${(amqpSetupRtt / mqttSetupRtt).toFixed(1)}x slower)
</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Battery Life</div>
<div style="font-size: 20px; font-weight: bold; color: #E67E22;">
${amqpBatteryDays.toFixed(0)} days
</div>
<div style="font-size: 11px; color: #E67E22;">
(${batteryLifeDiff}% shorter vs MQTT)
</div>
</div>
<div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 4px;">
<div style="font-size: 11px; color: #7F8C8D;">Memory Footprint</div>
<div style="font-size: 20px; font-weight: bold; color: #2C3E50;">
${amqpMemoryKb} KB
</div>
<div style="font-size: 11px; color: #E67E22;">
(${(amqpMemoryKb / mqttMemoryKb).toFixed(0)}x larger)
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; padding: 12px; background: #e8f4f8; border-radius: 6px; border-left: 3px solid #3498DB;">
<strong style="color: #3498DB;">Protocol Selection Guide:</strong>
<div style="color: #2C3E50; margin-top: 8px;">
<div style="margin: 5px 0;"><strong style="color: #16A085;">Use MQTT:</strong> Battery-powered sensors, mobile devices, millions of small devices, constrained networks</div>
<div style="margin: 5px 0;"><strong style="color: #3498DB;">Use AMQP:</strong> Enterprise backends, complex routing, durable at-least-once delivery with publisher confirms and consumer acknowledgements, transaction support.</div>
</div>
</div>
</div>`;
}Interactive Calculator: AMQP vs MQTT Protocol Overhead
Interactive Calculator: AMQP vs MQTT Protocol Overhead
animation
amqp
protocols
messaging
Try Change payload size to 200 bytes.
Observe Watch Total Bandwidth and Battery Life after Calculate protocol efficiency.
Explain Explain why Battery Life uses 1000 messages per day.
Technical boundaries. Overhead is fixed at 2 bytes for MQTT and 18 for AMQP. Battery Life uses fixed consumption per message and 1000 messages per day; Setup Time and Memory Footprint are fixed.