MQTT Java入门-搭建MQTT服务器

位置:首页>文章>详情   分类: 教程分享 > Java教程   阅读(1750)   2024-04-17 12:33:25
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

broker访问权限配置

修改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协议的支持
mqtt协议的支持

下一步将讲解spring boot 接受和发送MQTT消息

 
地址:https://www.leftso.com/article/993.html

相关阅读

MQTT协议 Java入门教程,通过Apache ActiveMQ Artemis搭建MQTT服务器。首先下载Apache ActiveMQ Artemis,目前Apache ActiveMQ ...
Spring Boot MQTT协议通过spring boot整合apache artemis实现Java语言MQTT协议通信,搭建MQTT服务器可以参考上一篇 MQTT Java入门-搭建MQ...
HTTP协议2.0,HTTP 2.0如何升级_HTTP2.0新特性_HTTP2.0详解。
最近因需要,搭建了一个私有的开源版eolinker,发现居然无法管理的方式添加用户,为了便于管理肯定是要关闭注册的,被迫只好研究如何直接数据库添加用户了。 然后密码生成规则就成为了比了解之路。首...
jenkins是devops神器,本篇文章介绍如何安装和使用jenkins部署Spring Boot项目jenkins搭建 部署分为三个步骤;第一步,jenkins安装第二步,插件安装和配置第三...
modbus tcp 通讯协议在Java编程中的使用。本文主要讲解Java编程中通过modbus4j工具类来实现modbus tcp通讯协议的通讯。包括通过modbus协议读取数据,写入数据的实现。
spring boot又一个spring框架的经典项目,本文讲解spring boot入门的环境配置以及第一个项目,Spring Boot 入门教程
在本教程中,学习从spring boot 入门应用程序创建和使用RSS和Atom提要。 您必须在各种网站上(例如我们的RSS提要)以文本或图像按钮的形式看到这一点,邀请您“通过RSS订阅”。RS...
SpringBoot使用@ResponseBody返回图片的实现以前使用HttpServletResponse可以通过输出流的方式来向前台输出图片