emqx版本为5.2.0,使用的java第三方库为org.eclipse.paho.client.mqttv3,版本为1.2.5,不同的clientid,相同的用户名密码,连接emqx正常,当第二个clientid连接时需要剔除第一个连接,按照官网/api/v4/clients/{clientid}做delete请求,执行之后无效,emqx的dashboard页面此客户端还存在,是否有其他方法剔除某个客户端!
是否可能是前一个链接,被踢成功了。但是它有重连回来了?
两个连接都是用mqttx模拟的,并且自动重连设置的是false,接收到连接事件之后,我能拿到当前连接的clientid以及上一次的clientid(上次连接落库的),这个时候用接口对第一个clientid做剔除操作,无效!
贴下整个踢出请求的内容呢?我检查下和复现下试试
public void eliminateEmqxLink(String clientId) {
String apiUrl = "http://192.168.2.107:18083/api/v4/clients/{clientid}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpDelete httpDelete = new HttpDelete(apiUrl.replace("{clientid}", clientId));
httpClient.execute(httpDelete);
System.out.println("Client deleted successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
public void eliminateEmqxLink(String clientId) {
try {
IMqttClient client = new MqttClient(brokerUrl, clientId, new MemoryPersistence());
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setUserName(username);
connOpts.setPassword(password.toCharArray());
connOpts.setCleanSession(true);
client.disconnectForcibly();
client.close();
} catch (Exception e) {
log.error("剔除" + clientId + "异常,异常原因为:" + e.getMessage());
}
}
这种方式也不行