MQTT Broker 範例集

三種 MQTT / 訊息佇列 Broker 的容器化範例,方便並列比較與實測。

Broker 語言 特色 檔案
ActiveMQ 5.14.3 Java 多協議(MQTT、AMQP、STOMP、OpenWire) Dockerfile
eMQTT Erlang 高並發連線、內建 Dashboard Dockerfile
VerneMQ 1.0.1 Erlang 原生叢集、可插拔認證 Dockerfile

ActiveMQ

Ubuntu 14.04 + OpenJDK 7,從 Apache 官方壓縮檔安裝,並建立專用的 activemq 系統帳號與群組。

FROM ubuntu:14.04
RUN apt-get install -y curl wget git vim sudo openjdk-7-jdk
RUN wget https://archive.apache.org/dist/activemq/5.14.3/apache-activemq-5.14.3-bin.tar.gz
RUN tar xzf apache-activemq-5.14.3-bin.tar.gz
RUN mv apache-activemq-5.14.3 activemq
RUN addgroup --quiet --system activemq
RUN adduser --quiet --system --ingroup activemq --no-create-home --disabled-password activemq
RUN usermod -c "ActiveMQ Broker" -d /opt/activemq -g activemq activemq
RUN chown -R activemq:activemq /opt/activemq
RUN cp /opt/activemq/bin/env /etc/default/activemq

ActiveMQ 的 MQTT transport 預設在 1883,Web Console 在 8161。

eMQTT

Ubuntu 16.04,直接安裝官方 deb 套件:

FROM ubuntu:16.04
RUN apt-get install -y wget net-tools vim erlang
RUN wget http://emqtt.io/downloads/latest/ubuntu16_04-deb
RUN dpkg -i ubuntu16_04-deb

同目錄的 emqtt.sh 額外編譯官方壓測工具 emqtt_benchmark

git clone https://github.com/emqtt/emqtt_benchmark.git
cd emqtt_benchmark
make
emqttd start

用它可以模擬大量連線:

./emqtt_bench sub -c 1000 -t bench/%i -q 1
./emqtt_bench pub -c 100 -I 10 -t bench/%i -s 256

VerneMQ

Ubuntu 14.04 + Node.js 6,安裝 VerneMQ 1.0.1 deb,並把認證關掉方便測試:

ENV VERNEMQ_VERSION 1.0.1
ADD https://bintray.com/artifact/download/erlio/vernemq/deb/trusty/vernemq_$VERNEMQ_VERSION-1_amd64.deb /tmp/vernemq.deb
RUN dpkg -i /tmp/vernemq.deb
RUN sed -i 's/allow_anonymous = off/allow_anonymous = on/g' /etc/vernemq/vernemq.conf
RUN sed -i 's/plugins.vmq_passwd = on/plugins.vmq_passwd = off/g' /etc/vernemq/vernemq.conf

allow_anonymous = on 代表任何人都能連線發布訂閱。只用於本機測試,正式環境務必改回 off 並設定認證。

Bintray 已於 2021 年關閉,這個 ADD 網址不再可用,請改從 VerneMQ Releases 取得套件。

建置

docker build -t activemq:5.14.3 Activemq/
docker build -t emqtt:latest    eMQTT/
docker build -t vernemq:1.0.1   VerneMQ/

相關資源


← 回到 IoT 物聯網與訊息佇列