Eclipse Paho MQTTAsyncClient連接本地EMQX用戶名密碼認證失敗的解決方法
本文檔闡述了使用Java和Eclipse Paho的MQTTAsyncClient庫連接本地EMQX MQTT Broker時,用戶名密碼認證失敗問題的解決方法。
問題描述
在使用org.eclipse.paho.client.mqttv3
庫連接本地EMQX(配置為內置數據庫密碼認證,密碼加密方式為plain,加鹽禁用)時,即使用戶名“emqx_test”和密碼“emqx_test_password”正確,連接仍會失敗,並拋出MqttSecurityException: 错误的用户名或密码
異常。 MQTTX客戶端測試連接成功。 Java代碼如下:
String brokerUrl = "tcp://127.0.0.1:1883"; MqttAsyncClient mqttClient = new MqttAsyncClient(brokerUrl, "test"); MqttConnectOptions connOpts = new MqttConnectOptions(); connOpts.setUserName("emqx_test"); connOpts.setPassword("emqx_test_password".toCharArray()); connOpts.setServerURIs(new String[] { brokerUrl }); connOpts.setCleanSession(true); mqttClient.connect(connOpts, connStatus); // 問題所在
回調函數onFailure
返回reason_code_failed_authentication
錯誤碼。 當禁用EMQX的內置數據庫認證後,連接成功,但EMQX控制台顯示缺少用戶名。
解決方案
問題在於mqttClient.connect(connOpts, connStatus);
這行代碼。 為了正確進行用戶名密碼認證,需要修改為:
mqttClient.connect(connOpts, null, connStatus);
將第二個參數設為null
,即可解決認證失敗問題。 修改後,連接成功,並且用戶名認證生效。
通過以上調整,即可解決Eclipse Paho MQTTAsyncClient連接本地EMQX時用戶名密碼認證失敗的問題。
以上是如何解決使用Eclipse Paho的MqttAsyncClient連接本地EMQX時用戶名密碼認證失敗的問題?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Java在不同操作系統上的表現存在細微差異。 1)JVM實現不同,如HotSpot、OpenJDK,影響性能和垃圾回收。 2)文件系統結構和路徑分隔符不同,需使用Java標準庫處理。 3)網絡協議實現差異影響網絡性能。 4)GUI組件外觀和行為在不同系統上有別。通過使用標準庫和虛擬機測試,可減少這些差異的影響,確保Java程序穩定運行。

javaoffersrobustobject-IentiendedProgrammming(OOP)和Top-Notchsecurityfeatures.1)OopinjavainCludesClasses,對象,繼承,多態性,和列出,andeclingfleximaintainablesys.ss.2)SecurityFeateTuersLudEtersludEterMachine(

JavaScriptandJavahavedistinctstrengths:JavaScriptexcelsindynamictypingandasynchronousprogramming,whileJavaisrobustwithstrongOOPandtyping.1)JavaScript'sdynamicnatureallowsforrapiddevelopmentandprototyping,withasync/awaitfornon-blockingI/O.2)Java'sOOPf

JAVAACHIEVESPLATFORMINDEPENTENCETHROUGHJAVAVIRTAILMACHINE(JVM)和BYTECODE.1)THEJVMINTERPRETSBBYTECODE,允許theingthesmecodetorunonanyanyanyanyplatformwithajvm.2)

java'splatformendependecemeansapplicationscanrunonanyplatformwithajvm,使“ Writeonce,runanywhere”。

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生產性。 1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允許CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3漢化版
中文版,非常好用

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具