def _encode_action_type(routes, action_type):
    """
    Encode the outbound action type, apply routing and
    create MQTT topic.

    :param routes: The routing dict
    :type routes: dict

    :param action_type: The type of action
    :type action_type: str

    :returns: The routed MQTT topic
    """
    if not '/' in action_type:
        return action_type
    for handle, route in routes.items():
        if action_type.startswith('@' + handle):
            return action_type.replace('@' + handle, route)
    return action_type
