Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Problem about use 'MqttCallBack.deliveryComplete()' method


you are right to observe that (as documented in the javadoc) once a
message has been successfully sent then its DeliveryToken will return
null in response to getMessage().

If you need to know which message has been successfully sent, you
should maintain your own mapping of delivery token to message.

The main reason for this is that once the message has been
successfully sent, then the application normally doesn't need to get a
copy back. null'ing the reference in the token removes the last
reference of the message payload held be the client allowing it to be
garbage collected (unless of course the application has stored its own


On 7 June 2012 14:52, andypiperuk@xxxxxxxxx <andypiperuk@xxxxxxxxx> wrote:
> Hi
> I see you posted the same question to Stackoverflow as well.
> I think the best people to answer it are likely to be Nick and Dave, and I
> don't know for sure but I suspect they may be on vacation this week -
> hopefully we can get an answer for you shortly though!
> One thought though - are you using QoS 0? if so, according to the javadoc:
> "Quality of service 0 - indicates that a message should be delivered at most
> once (zero or one times). The message will not be persisted to disk, and
> will not be acknowledged across the network. This QoS is the fastest, but
> should only be used for messages which are not valuable - note that if the
> server cannot process the message (for example, there is an authorization
> problem), then an exception will not be thrown, nor will a call be made
> to MqttCallback#deliveryFailed(MqttDeliveryToken,
> MqttException) or MqttCallback.deliveryComplete(MqttDeliveryToken). Also
> known as "fire and forget"."
> Andy
> On Thu, Jun 7, 2012 at 7:59 AM, xu zhangxuan <plucury@xxxxxxxxx> wrote:
>> Sorry, the token would not be null, but the MqttMessage in it was null :-)
>> 在 2012-6-7,下午2:49, xu zhangxuan 写道:
>> > hi,guys:
>> >
>> >       I want to do some actions when the message was published.And I
>> > want to implement the method.But I got a problem, Once a message was sent,
>> > its token would set to null too.So how can I determine which message was
>> > sent?
>> _______________________________________________
>> paho-dev mailing list
>> paho-dev@xxxxxxxxxxx
> --
> Andy Piper | Farnborough, Hampshire (UK)
> blog:   |   skype: andypiperuk
> twitter: @andypiper  |  images:
> _______________________________________________
> paho-dev mailing list
> paho-dev@xxxxxxxxxxx

Back to the top