使用moquette mqtt发布wss服务

文章目录

概要

moquette是一款不错的开源mqtt中间件,github地址:https://github.com/moquette-io/moquette。我们在发布mqtt服务的同时,是可以提供websocket服务器的,有些场景下需要用到,比如使用JS进行数据访问的。本文描述了如何进行wss的配置,即带ssl的安全连接。

一、制作的ssl证书

制作证书的方法有很多,我们这边使用腾讯云的免费证书进行制作,有效期是1年(以前阿里的也是1年,现在是3个月了,吃相难看啊)。制作完成后,下载JKS格式的证书

二、配置wss

提示:这里我并没有找到官方的配置文档,哪位同学有的话,也可以评论区留言下

我们找到了其中一个commit中提到的配置方法:Introduced WSS to fix issue #8

bash 复制代码
#*********************************************************************
# Secure Websocket port (wss)
# decommend this to enable wss
#*********************************************************************
# secure_websocket_port 8883

#*********************************************************************
# SSL tcp part
#  jks_path: define the file that contains the Java Key Store,
#            relative to the current broker home
#
#  key_store_password: is the password used to open the keystore
#
#  key_manager_password: is the password used to manage the alias in the
#            keystore
#*********************************************************************
# ssl_port 8883
#jks_path serverkeystore.jks
#key_store_password passw0rdsrv
#key_manager_password passw0rdsrv

#*********************************************************************
# The interface to bind the server
#  0.0.0.0 means "any"
#*********************************************************************

参考上面的配置,我们修改配置文件如下:

bash 复制代码
port 1883

websocket_port 50002
secure_websocket_port 50003
ssl_port 8883
jks_path /iot/config/www.xxxx.com.jks
key_store_password xxxxxx
key_manager_password xxxxxx

小结

moquette还是不错的,就是文档相对少了点,多学会看github的issue吧,里面可以解决很多问题

相关推荐
Flynn Liang2 天前
MQTT 共享订阅$share/原理:怎么用它给消费端水平扩容做负载均衡
运维·物联网·mqtt·iot·mqtt broker
物联通信量讯说3 天前
2026年10月物联网卡服务商怎么选?第三方平台与运营商有什么区别
物联网·iot·企业出海·运营商
K成长日志4 天前
BLE Host层L2CAP -- 配置参数选项
物联网·网络协议·嵌入式·蓝牙·iot·ble·bluetooth
金瑞铭4 天前
RFID称重货架-科研实验室试剂精准管控
物联网·rfid·iot
K成长日志4 天前
BLE Host层L2CAP -- 状态机
物联网·网络协议·无线通信·蓝牙·iot·ble
Alinket5 天前
不训练模型也能加 AI:5 套可直接量产的组合方案
人工智能·物联网·ai·健康医疗·无线通信·智能硬件·iot
话梅姐姐呀6 天前
TCP/IP 架构各层的协议概述
人工智能·物联网·网络协议·tcp/ip·iot
Flynn Liang6 天前
深入探索 Zenoh:对高速公路物联网中台数据架构的启示
大数据·物联网·架构·iot