Duplicate message in multi server configuration

Asked by Byungchul Lee

I'm trying to setup multi servers for mosquitto to provide push notification service for Android devices.

Basic requirements were as follows.
1) Each Android device has a unique id
2) Each message that couldn't be delivered should be queued and be delivered later when network connection is available.

So I set 'clean session' to false and used unique android id as a client id, and set QoS to 2 for future delivery.

This worked perfectly in single mosquitto server configuration, but in multi server configuration, it didn't.

I used haproxy on top of two mosquitto servers as a load balancer, and made a bridge between those mosquittos.

But in case described below, a client get duplicate messages.
1) a client connected to server 1
2) after disconnection, then the client connected to server 2
3) a push message published and the client received it from the server 2
4) after another disconnection, the client connected again to server 1 and receives duplicated message.

Current bridge configuration is as follows.

-Server 1
connection abvje_push_1
address 192.168.0.23:1883
topic notification/AAAA/# both 2
clientid abvje.32
cleansession true
keepalive_interval 60
start_type automatic
restart_timeout 30
try_private true
username bridge
password xxxxxxxxxxxxx

Server 2 has no special configuration for bridging.

Is there a way to solve this kind of problem?
Any kind of advice will be appreciated.

Question information

Language:
English Edit question
Status:
Solved
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Solved by:
Roger Light
Solved:
Last query:
Last reply:
Revision history for this message
Best Roger Light (roger.light) said :
#1

As you have the client set to clean-session=false, the first broker stores the messages that arrive when the client is disconnected. The problem you have is that the first broker doesn't know anything about the second broker, so it has no idea that the message has already been sent. When the client reconnects, it sends the message as it should.

I'm not sure what to suggest as a solution at the moment.

Revision history for this message
Byungchul Lee (bc11-lee) said :
#2

Thank you Roger, I had a misunderstanding about the bridge.
Now I can see current behavior is absolutely normal.

I think I have two options at the moment.
The first one is to configure load balancer to use those servers as active-standby mode. This one is very simple and will work quite well.

The second one is to modify source to let bridged servers know which client is connected to other server. Then remove all postponed messages. But it will be a time consuming job to do.

Anyway, thanks again for your kind explanation.

Revision history for this message
Byungchul Lee (bc11-lee) said :
#3

Thanks Roger Light, that solved my question.