3

I am doing a request/response flow using a MQTT broker and I wondered if brokers like VerneMQ or Mosquitto deal well with huge amount of topics. Basically every time I want to do a request/response, I publish to a topic that looks like rpc/{UUID} meaning every request creates a new topic and then unsubscribe from it when the response is received. Will this come and bite me later ?

BinarSkugga
  • 400
  • 2
  • 15
  • 1
    One thing to consider with this workflow is the number of requests (for each RPC call you subscribe to resp topic, send message, receive response, then unsubscribe). If you adopt an alternative strategy; say use `resp/clientid/{UUID}` for responses and subscribe to `resp/clientid/#` once at client startup then each rpc call is just publish request, receive response (so two fewer round trips between the client and broker per RPC). How much of a difference this makes in reality will depend upon your message profile. – Brits Jul 27 '21 at 06:41
  • So while there is no overhead to having lots of different topics, I can still optimize the way I use them by reducing subscription/unsubscription calls. Makes sense – BinarSkugga Jul 28 '21 at 18:10

1 Answers1

3

Topics are effectively ephemeral already.

Usually the only overhead to a topic is in the list of subscribed topic patterns (because they can be wildcards) held for each client. The topic is read from an incoming messages and checked against this list.

Using UUIDs in topics should not cause any problems.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Thanks, do you know what is the average lifespan of those subscriber-less topics or if there is a configuration to change it ? – BinarSkugga Jul 26 '21 at 16:41
  • 2
    There is no lifetime at all, topics only "exist" at the instant a message is being published – hardillb Jul 26 '21 at 16:41