Streaming data with Spring MVC

5.2k views Asked by At

I'm looking to set up a Twitter stream using Twitter4J. I plan to be able to search using a keyword. I also would like to use Spring MVC as this is something I've used a lot recently. However, I would like to stream an infinite amount of tweets without stopping to the view until user interaction. I'm not too sure if this is possible using Spring.

Could someone give me some advice on whether this would be possible and point me to some documentation so I could read it? Or whether using Java and Spring is over complicating my problem and I would be better using a different technology altogether.

2

There are 2 answers

0
Brian Clozel On BEST ANSWER

You can use Spring's websocket support with STOMP (see reference doc and a chat application example), which has been supported since 4.0.

Or you can also use the newest HTTP Streaming support (currently in 4.2.0.RC1).

0
underdog On

Never used twitter4J but as far as Spring is concerned it simply provides you an architecture. Development becomes easier with Spring as you don't have to write boiler plate code every now & then, besides there are many other good reason to use Spring. If you need to get continuous activity streaming on your UI you need to implement Ajax (polling) or a server side push technology like Atmosphere, Spring Reactor.

Or whether using Java and Spring is over complicating my problem and I would be better using a different technology altogether.

If your app is pretty basic with minimum amount of code, you can also write it using servlets. Twitter4J is java library so you have to stick with Java you cannot implement any different technology.