Welcome to the community!
Yes, this is possible in Telegraf and is called metric filtering, see here in the docs:
Here is a simple example.
[[inputs.mqtt_consumer]]
# other plugin configs...
measurement_name = "mqtt_1"
[[inputs.mqtt_consumer]]
# other plugin configs...
measurement_name = "mqtt_2"
[[outputs.influxdb]]
# other plugin configs...
namepass = ["mqtt_1"]
[[outputs.influxdb]]
# other plugin configs...
namepass = ["mqtt_2"]