Hi Dave,
I just see your reply, sorry for the late response.
Yes, previously I did not use waitforCompletion() when publishing messages, I just simply publish other message(e.g. reply message)in messageArrived() Callback.
However, the pending Messages in inFlight queue does not seem get clear as soon as possible even they have been sent out to broker. It soon meets the maxInFlight thus throw out the exception,and fail to publish messages.
And then I took your advice to use waitforCompletion() when publishing a message, then I found the issue mentioned in this email.
But anyway, I have resolved this by using a queue running in other thread to handle the messages need to be sent in the messageArrived() call back when use waitforCompletion(), then it works fine so far, the number of pending message queue never greater than 1.
Thanks.
Regards, Jianing RenSoftware Developer
Hi Jianing,
the use of waitForCompletion() and and
the deliveryComplete() callback are not normally used together:
- waitForCompletion() turns an an asynchronous
operation like publish (on the MqttAsyncClient) into a blocking operation.
Once the waitForCompletion() call returns the publish has completed
- deliveryComplete() is used with the
asynchronous publish method to notify the app when the delivery of the
message is complete.
i,e. they both solve the same problem
but in different ways - one blocks and the other does not.
Messages can be published in the callbacks
such as the messageArrived() callback but the implementation of the callback
must return promptly and not use a blocking call. Hence waitForCompletion()
must not be used in the messageArrived() callback. If the message
is published from the messageArrived() callback without the use of
waitForCompltion() then the deliveryComplete() method will be notified
when delivery is complete. If this is not the case it is a bug.
All the best
Dave LockeSenior Inventor, Pervasive and
Advanced Messaging Technologies
<Mail Attachment.jpeg>locke@xxxxxxxxxx
<Mail Attachment.jpeg>Dave
Locke/UK/IBM@ibmgb
<Mail Attachment.jpeg>7-246165
(int) +44 1962816165 (ext)
<Mail Attachment.jpeg>37274133
(mobex) +44 7764132584 (ext)
|
<Mail Attachment.gif>
Fringe
Bluepages with fuel injection
<Mail Attachment.gif>
My
Cattail: Share
files in IBM and save your in-box |
From:
Jianing Ren <jianingr@xxxxxxxxxxxx>
To:
paho-dev@xxxxxxxxxxx
Date:
28/11/2013 23:56
Subject:
[paho-dev] Hi
Paho team.
Sent by:
paho-dev-bounces@xxxxxxxxxxx
Hi Paho team,
I am not sure if it counts as a bug in mqtt Java client
implementation that is when I publish the topic and calling waitforcompletion(),
If this topic was published from messageArrived call back method. I will
never get the completeDelivery call back again. And it seems got
block unless the published message I sent in the messageArrived() call
back was un other thread.
For example:
public void send(Topic topic){
token = topic.publish();
token.waitforcompletion();
}
public void completeDelivery(Token){
printout(token.getmessageID());
}
public void messageArrived(message){
….have received message
..now send back reply.
send("reply"); …This reply message will be
blocked and never call "completeDelivery".
Thread thread = new thread();
thread.start
{
send("reply"); If reply sending in other thread,
then worked.
}
}
Thanks.
Regards,
Jianing Ren
This email has been processed by SmoothZap - www.smoothwall.net
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6
3AU
_______________________________________________ paho-dev mailing list paho-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/paho-dev
This email has been processed by SmoothZap - www.smoothwall.net
|