I don't know how it was positioned in the wall, but it's an outlet (faucet) for a liquid handling system. The nub on the outlet end is there so one could hang a wire handled pail on it. Perhaps it was part of a rain water runoff collection system. Maybe there was once a cistern for the barn or it's just the business end of a hand pump well.
Bart