added an API to end the session and flush the queue