The nature of research is that other people are probably working on similar ideas to you, and it is possible that someone will beat you to publishing them.
When I was working on my PhD, I discovered another PhD thesis by Iris Yeung at UKC with almost exactly the same title as mine, and published a year earlier. In those days, a copy of a thesis had to be printed from microfiche, and then posted by snail mail. For a few weeks I felt sick, wondering if all my work was going to have to be scrapped because someone else had already done it. Fortunately, my approach was sufficiently different from hers, and I continued with my thesis.
For this reason, I encourage my PhD students to put out working papers of their research as soon as it is ready for public consumption. The working papers go to RePEc, so they are easily accessible and dated, in order to be clear when the work was completed.
However, occasionally, even then someone else might beat you to print. A colleague of mine recently had the unfortunate experience of submitting a paper to a journal (after putting it on an online repository), and four months later had the paper rejected because someone else had written something “better”. However, the other paper was dated April 2013, whereas his working paper was December 2012. Furthermore, the newer paper didn’t even cite the older paper.
This makes me suspicious. The papers were very similar. Did a reviewer read the paper, and decide to do something similar himself, with an extension? It would be almost impossible to prove if that was the case, without knowing who the reviewers were. But here is what I advised him to do.
Write to the journal pointing out that your paper was written four months before the other one, was publicly accessible, and wasn’t even cited.
Write to the other author pointing out that he has ignored your earlier work, and request that he cite it and include a paragraph explaining how his approach is different.
If you get asked to review his paper, you can be more insistent that he acknowledge priority.
If his paper gets published somewhere without acknowledgement of your work, you could write a letter to the editor pointing out the omission.