There, sure, is an Azure IoT Hub Gateway SDK which is designed to be modular so any step you need to take can be a custom build module running within the Gateway. For message handling, you could 'stack' modules to determine flow.
This Doc could help you out as well.