Hello @Mark Pope ,
welcome to this moderated Azure community forum.
It seems you want to have this architecture:
External MQTT broker <- Some client in an Azure Function checking each message and picking the right topic to publish to-> EventGrid Namespace MQTT Broker <- One or more possible clients listening to topics
Function apps are stateless and not suitable for long running services (listening as a subscriber for messages). It also means constant connect/disconnect.
One way to overcome this is to move over to an Azure Container Instance because it is stateful.
Check out this example with code. In this case, it reads messages from an Azure EventHub but the blue print should help you with building a stable solution.
If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.