How does spectroscopy work if the atom will immediately re-emit a photon of the same frequency? If a hydrogen atom in the sun absorbs a photon of frequency f that was heading towards the earth.
Wouldn't the atom re-emit that shortly after in the same direction? (to conserve linear momentum)
Why would see any gaps then in the emission spectrum in the sun that correspond to Hydrogen's spectral lines?
 A: No it doesn’t need to emit in same direction. And there is generally a time delay before re emission it doesn’t have to be immediate.
Think of throwing a ball into a big springy elastic lump of rubber. After slowing down and stopping the elastic can re accelerate the ball away elastically without frictional heating and chuck it out. This could be in any direction. Perhaps you could imagine the lump was rotating.. or just have the lump as a box with a few holes and the ball gets trapped for a while with random elastic internal bounces before coming out in random direction.
There is no problem with conservation of energy and momentum having elastic collision with the ball going off in various directions, like in pool or billiard ball collisions.
A: It is important to know that all atoms/molecular cannot absorb all range of light waves(photons) - see here. This is due to the quantization of energy levels (a very Quantum Mechanical Phenomena).
Here is the image of discretion in energy Levels of Hydrogen:

Hence, very specific photons of the energy equal to the energy difference between the levels are absorbed and then reemitted. All other photons simply passes through. That is the reason why you see lines instead of continuous spectra in the emission/absorption spectrum.
