先下载MQTTX: MQTTX: Your All-in-one MQTT Client Toolbox
使用线上免费的MQTTX BROKER:The Free Global Public MQTT Broker | Try Now | EMQ
打开MQTTX,创建连接,点击NEW SUBSCRIPTION,创建一个主题,这里使用test/topic,在下面Json中填写配置好的主题,点击发送测试OK。订阅者,建立一个主题:
package com.jasonhong.application.media.mq.mqtt;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;