I would advice looking at it as CLIENT ---(mqtt-sn)---> GATEWAY ---(mqtt)---> BROKER setup, rather than a direct mqtt-sn connection to the broker. The MQTT protocol (between gateway and broker) requires client to be properly connected to the broker (i.e. to send CONNECT request first) to be able to publish. Even if your client doesn't send an explicit CONNECT request, the gateway must do it on client's behalf. I suppose the gateway application can be implemented and configured to perform proper connection to the broker upon first message received from the client.
However, to the best of my knowledge and understanding, the QoS=-1 was introduced to support
very thin clients with a significant ROM size limitation. Such clients are most probably very simple sensors, that send only single type of the message with their sensor reading. If you care about the acknowledgment for the sent messages (using QoS=1), then probably your client is not very thin, and there is little effort involved in actually sending CONNECT request prior to sending messages with QoS=1.
I also understand your "millions of clients" problem and desire to avoid expensive housekeeping of maintaining the list of available clients. However, the QoS=1 requires broker/qateway to send acknowledgement packets (PUBACK messages) back to the sender. How are your going to know to whom you need to send it without maintaining a list of connected clients?
I suppose you can make your clients to use different "topicId + msgId" pairs in their PUBLISH messages and gateway not differentiating between the clients and treating all of them as a single one that sends different messages. The gateway can broadcast the PUBACK messages to the whole network and every client ignoring irrelevant packets. However, if I'm not mistaken the MQTT-SN protocol doesn't allow sending multiple PUBLISH messages with QoS>0 from single client prior to receiving acknowledgment to the first one, which forces you to somehow differentiate between clients.
The bottom line, you have the following options:
- Stick with QoS=-1 for all of your clients and having aggregating gateway that has a single connection to the broker and republishes the received messages without expecting anything back.
- Use proper connection with the clients and full housekeeping of connected clients.
- Invent a new custom protocol that supports your needs (MQTT-SN doesn't seem to do so) and implement your own gateway with mqtt bridging.