process messages to gateway