9

How to Write a Java based Spring Web Socket (STOMP) Client. As in Spring we have only javascript based client is provided using stompJS but if we need a java client how should we need to achive it?

Sathish Kumar k k
  • 1,732
  • 5
  • 26
  • 45

2 Answers2

16

Spring 4.1 introduces a SockJs Java Client which is quite useful for server to server communication and performance testing. It doesn't come with a Stomp client (this is certainly in the roadmap) but you can check out the tests in the sample app which has already an implementation. Seems this is what you are looking for.

Update 8 Sep 2015:

Spring 4.2 has a STOMP Java client which can be used along with the SockJS Java client. More: https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/htmlsingle/#websocket-stomp-client

silverduck
  • 401
  • 6
  • 9
Sergi Almar
  • 8,054
  • 3
  • 32
  • 30
  • 1
    I get `cannot be resolved to a type` for all. I have added all the jars. I have copied all the jars form the Gradle local repo. I have searched for existance of those class in all jars but I did not get them. I fell all the class are renamed and packages are changed. This URL http://snag.gy/Y9QCy.jpg is the screenshot of what I coded. And I did't get any Idea form the code in git repo. Please can you provide me a sample code. – Sathish Kumar k k Sep 17 '14 at 17:30
  • seems you are not using Spring 4.1, please check the version is 4.1.0.RELEASE. The packages where these classes are is: org.springframework.web.socket.sockjs.client – Sergi Almar Sep 17 '14 at 17:39
  • No No. I have used [spring web socket example](http://spring.io/guides/gs/messaging-stomp-websocket/) it is latest spring that which Gradle is downloading. In aim of leaving it as server and I created a separate project as client and in which I have those code you suggested and I added all jars from that example projects into this client project. – Sathish Kumar k k Sep 18 '14 at 03:56
  • this shows you are using Spring 4.0.7 as you are relying on Spring Boot 1.1.6, override the spring version to use 4.1.0.RELEASE – Sergi Almar Sep 18 '14 at 06:56
  • Hey now I use 4.1 version and all the compilation error gone except for `StandardWebSocketClient()` and `MyWebSocketHandler()`. Also tell how to exactly replace the index.html (a js client) from the tutorial to this java client. – Sathish Kumar k k Sep 18 '14 at 11:20
  • Thank you! It's helpful for me. – Shane chen Dec 08 '16 at 02:48
  • How to send message from client to server ? – gstackoverflow Apr 13 '17 at 07:53
0

I would look for websocket clients in Java and build off of those. It seems that Jetty has a websocket client api as does too tall nate.

Denise
  • 1,947
  • 2
  • 17
  • 29