MQTT协议 Java入门教程,通过Apache ActiveMQ Artemis搭建MQTT服务器。
首先下载Apache ActiveMQ Artemis,目前Apache ActiveMQ Artemis 主要版本有2.19.x和2.20.x,需要注意2.19.x需要的jdk环境是1.8即可,2.20.x需要jdk11+,这里我使用的是2.19.x。Apache ActiveMQ Artemis 支持 MQTT v3.1.1,更多MQTT支持信息可以查看ActiveMQ (apache.org)
Apache ActiveMQ Artemis下载
apache-artemis-2.19.1-bin.zip
下载好文件以后,移动到/opt目录并解压
mv apache-artemis-2.19.1-bin.zip /opt
cd /opt
unzip apache-artemis-2.19.1-bin.zip
进入bin目录
cd apache-artemis-2.19.1/bin
创建broker
./artemis create broker
根据提示输入账号和密码
Creating ActiveMQ Artemis instance at: /opt/apache-artemis-2.19.1/bin/broker
--user:
Please provide the default username:
admin
--password: is mandatory with this configuration:
Please provide the default password:
--allow-anonymous | --require-login:
Allow anonymous access?, valid values are Y,N,True,False
N
Auto tuning journal ...
done! Your system can make 14.71 writes per millisecond, your journal-buffer-timeout will be 68000
You can now start the broker by executing:
"/opt/apache-artemis-2.19.1/bin/broker/bin/artemis" run
Or you can run the broker in the background using:
"/opt/apache-artemis-2.19.1/bin/broker/bin/artemis-service" start
完成后 会给出启动命令
broker访问权限配置
cd borker/etc
vi jolokia-access.xml
修改bootstrap.xml配置web的访问地址
默认是
<web bind="http://localhost:8161" path="web">
<app url="activemq-branding" war="activemq-branding.war"/>
<app url="artemis-plugin" war="artemis-plugin.war"/>
<app url="console" war="console.war"/>
</web>
修改为自己电脑的局域网ip,端口注意不冲突就行
<!-- The web server is only bound to localhost by default -->
<web bind="http://192.168.79.133:8161" path="web">
<app url="activemq-branding" war="activemq-branding.war"/>
<app url="artemis-plugin" war="artemis-plugin.war"/>
<app url="console" war="console.war"/>
</web>
启动broker
"/opt/apache-artemis-2.19.1/bin/broker/bin/artemis-service" start
启动命令来源于创建broker时候的提示
重启命令"/opt/apache-artemis-2.19.1/bin/broker/bin/artemis-service" restart
有可能61616端口不能访问
firewall-cmd –query-port=61616/tcp // 查看端口是否已开
firewall-cmd –add-port=61616/tcp –permanent //添加端口
firewall-cmd –reload //重新载入端口
登录到控制台
http://192.168.79.133:8161/console/login
登录账号和密码就是创建时候填写的账号密码
acceptors下面可以看到mqtt协议的支持
下一步将讲解spring boot 接受和发送MQTT消息
原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/243952.html