Skip to content

publish2 发布消息能成功收到,但却回调了 onFailure #2

Description

@LirisFlow

在 YunBaDemo.java 的 connect() 的回调 onSuccess() 里,添加下面的 publish2 代码,会出现“发的消息能成功收到,但却回调了 onFailure 函数”的情况。onFailure 打印出来的错误号是:20002。查到是:REASON_CODE_BAD_RETURN_PARAMETER。

(注:本人不会 Java,请先检查下面的代码写法有无问题,再研究这个问题。)

try{
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("qos",1);
    System.out.println("=====JSON: "+jsonObj.toString());

    mqttAsyncClient.publish2("news", "aaaaa", jsonObj, new IMqttActionListener() {
        @Override
        public void onFailure(IMqttToken asyncActionToken,Throwable exception) {

            if (exception instanceof MqttException) {
                MqttException ex = (MqttException)exception;
                System.err.println("=====publish2 failed, error code = " + ex.getReasonCode());
            }
        }
        @Override
        public void onSuccess(IMqttToken arg0) {
        System.out.println("=====publish2 succeeded.");
        }
    });
}catch(Exception e){                                
    e.printStackTrace();
}   

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions