How to get MQTT Topic in rule triggered by mqtt trigger channel?

In the Event Channel set the “Separator Character”. As the description says

The trigger channel payload usually only contains the received MQTT topic value. If you define a separator character, for example ‘#’, the topic and received value will be in the trigger channel payload. For example: my_topic#my_received_value.

For a Nashorn example of this in use see MQTT Event Bus Subscription [3.2.0;3.4.9] and for a GraalVM example see MQTT Event Bus [4.0.0.0;4.9.9.9].