Comments (5)
Thanks for the contributions! I merged them and just released v0.14.4.
from gomqtt.
Thanks for the contribution! But, could you elaborate on how the current behaviour does not match the spec? AFAIK for QoS=2 there are two methods, either yield the message on publish or yield it on pubrel.
from gomqtt.
I believe both your existing code and my patch are consistent with the specification. I was referring to the documentation of the MessageCallback hook.
Line 55 in c3c50b8
The existing release of this package will announce the message only after completing the QOS2 sequence (on pubrel) and as a result returning an error will cause the connection to drop but the the server will not attempt to redeliver the message - the server had completed its role handling the message.
I can understand that users of the message callback could want either behaviour hence my proposal to add a config option to switch behaviour. This would be something like 'AlwaysAnnounceOnPublish' (default false) thus keeping existing behaviour, while true would cause this new behaviour to come into force.
With regard to the specification you reference it would appear that the authors had experienced similar. Since figure 4.3 references the two delivery options for handling message arrival perhaps it really is worth exposing a config switch and let the package user choose at runtime.
I've tested this patch against mosquitto, vernemq and NATS with MQTT and they all attempt to redeliver the message when the connection resumes. This is ideal behaviour for services consuming MQTT and forwarding into other parts of a data pipeline. If the downstream service is unavailable or unable to accept the message one doesn't need to implement another persistence layer and message ordering guarantees. One just relies on the broker to re-deliver later.
from gomqtt.
The existing release of this package will announce the message only after completing the QOS2 sequence (on pubrel) and as a result returning an error will cause the connection to drop but the the server will not attempt to redeliver the message - the server had completed its role handling the message.
The server should attempt to redeliver the Pubrel message if a Pubcomp as never been received. If the callback returns with an error a Pubcomp will never be sent by the client. For verification that the current implementation works I added a test case here: d0c3809.
AFAIK both QoS2 methods are valid, and there should not be a difference wether the message is yield directly on receive or on Pubrel as long as the used sessions store is stable. I opted to chose the current method as the Pubrel message indicates the release and seems more correct.
from gomqtt.
I've split the two sets of changes into distinct PRs, #25 and #26. Both now have tests. I was having problems with go test ./... until I found the test environment setup in the github action workflow.
A thing to note: In #26 the function TestServicePublishSubscribeEarlyCallback has a sleep in it. This was the only way I could find to ensure the client would send both pubcomp and disconnect every time. This did bring the test into stability however, I mention this because this might be a hint that not all the client's packets are flushed to the broker before disconnect, or I missed a trick when setting up the test.
PR #25 simply ensures that the online callout will always occur before any message callouts since brokers can start sending messages from persistent connections right after they send their connAck.
from gomqtt.
Related Issues (16)
- Crash-safe callbacks HOT 1
- feature request: session on redis HOT 1
- Queueing of offline messages HOT 1
- Synchronized backend HOT 1
- Service automatic resubscription HOT 2
- Public client.tracker and support mqtt server bridge HOT 6
- Use standard log interface to support levels and fields. HOT 1
- Unpack Config HOT 2
- Do we need to close client explicitly in service supervisor loop? HOT 1
- may i send topic msg to its subscribers in broker directly but not publishing msg by mqtt client. HOT 1
- Issue in 256dpi\gomqtt\topic\tree.go HOT 2
- fatal error:when wait the client closed, occur exception,help to solve it, thanks HOT 4
- Encoder&Decoder race condition HOT 1
- documentation on how to use it?
- IO wait HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomqtt.