1. Open ports
EMQ X Provided by default 5 individual Listener, They will take up the following ports :
port | explain |
---|---|
1883 | MQTT/TCP Protocol port |
11883 | MQTT/TCP Protocol internal port , For native client connections only |
8883 | MQTT/SSL Protocol port |
8083 | MQTT/WS Protocol port |
8084 | MQTT/WSS Protocol port |
ECS can be released on the security group port
Or enter the command to open the corresponding port number firewall-cmd --zone=public --add-port=1883-11883/tcp --permanent
// permanent firewall-cmd --zone=public --add-port=1883-11883/tcp
// temporary firewall-cmd --zone=public --add-port=1883/tcp --permanent
// Permanent opening 1883 port firewall-cmd --zone=public --remove-port=1883/tcp --permanent
// Permanent ban 1883 port firewall-cmd --reload
// Reload the firewall without changing state -- Configuration takes effect immediately
notes : If you use the pagoda, remember not to forget that the pagoda also needs port clearance
2. download MqttSDK
MqttSDK Download link :MqttSDK
Download and unzip and import into idea in
Core abstract classes :MessageHandler, use final modification ServerMqttClient Improve code security .
3. Sign in EMQ X Administrative console
Use the browser to open the address http:// The server ip:18083 , To log in, enter the default user name admin
With default password public
, Log in Dashboard
You can see that there is no client connected at this time
4. Publish subscriptions to messages
perform main Method , Look again Dashboard client , At this point, you can see that a user is connected 【 notes : because EMQ Login authentication is not configured , All users can connect to anonymous login 】
Click on the console WebSocket, Subscribe to topics emq
,QoS(0: At most one transmission /1: At least one transmission /2: Only one transmission ), Here, in order to ensure that the news will reach , We choose QoS=2
Modify the code : The subject of subscription is java
, Release message The theme of emq
, perform main After the method, at the same time Dashboard
Click publish subscribe , You can see the log printed by the console , And the topic message received by the console
thus java Connect EMQ, And simulate the publication and subscription of topic messages OK 了 !
【 Reference documents 】EMQ The website links :EMQ Official website Return to upper level
[Centos8.0-EMQ The construction and deployment of ]:Centos8.0-EMQ The construction and deployment of Go back to the next level
[EMQ Data persistence ]