0

I am implementing a service that dispatches messages to clients using an arbitrary message broker. A single user may have multiple clients and the message will be dispatched to each one of them. Once the user has read the message on one client, I want the message removed from the user's other clients.

Do message brokers typically implement this functionality, or will I need a custom solution?

For a custom solution, I was thinking that the broker could maintain a separate reply topic to which a client will deliver a message to say that the user has read the message. The service can consume messages on this reply topic, and dispatch another message to the user's other clients that tells them to remove the message.

Is this how such a solution might typically be implemented?

If it helps, I am considering using MQTT as a message protocol.

Boon
  • 1,073
  • 1
  • 16
  • 42

1 Answers1

2

There is no concept of even end to end message delivery notification in the MQTT protocol1, let alone read notification. You are likely to need to implement this your self.

If I was doing this I would have 2 topics per user something like this:

[user id]/msg

and

[user id]/read

I would make the payload of the messages delivered to the [user id]/msg contain a message id. I would then publish the message id on the [user id]/read topic. All clients would subscribe to both, that way they could easily mark as read/remove messages as they were consumed on other clients.

1confirmation for higher QOS levels are between the publisher and the broker and then between the broker and the subscriber

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • I really like the idea and it seems logical, however, what about all clients both subscribing AND publishing to the [user id]/read topic? That way I can cut out a lot more complexity from my server and leave all this logic at the broker. But can MQTT allow a client to publish and subscribe to the same topic, and not receive messages on that topic that it has published itself? – Boon Jun 09 '15 at 18:17
  • No, if a client is subscribed to a topic and then publishes on the same topic the msg will be delivered to that client as well – hardillb Jun 09 '15 at 18:20
  • I could have sworn I saw such functionality before. It would be such a waste of network resources by sending thw message to the client that published it – Boon Jun 09 '15 at 19:26