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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

6 Comments

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 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.
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
No No. I have used spring web socket example 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.
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
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.
|
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.

1 Comment

Normal web socket will not have subscribe option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.