We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Austin Whitelaw • 4 years ago

If anyone else is getting so close but then having trouble getting the messages to actually appear, I figured out the solution! It worked fine when I downloaded the Github project, so I knew something was slightly off about mine. I compared each file using a site TextCompare, and figured out that the HTML was slightly different.

<form id="messageForm" name="messageForm" nameform="messageForm">

If you copy the HTML directly from this page like I did, it is missing the "nameForm" attribute. Not entirely sure how that works, not familiar with nameForm, but my messages are now appearing!

Huge thanks for this tutorial Rajeev!

Kavitha R • 5 years ago

Thanks for this tutorial, Rajeev SinghCan u assist me how can I implement this for single and group chat with image and video sharing. Your answer will be very helpful .Thanks in advance.

Kaiena • 5 years ago

Thanks for this tutorial, it's really helpful! I wonder how to disable "/join x" command on chat - I did few chats for different user groups and don't want they can change room.

Muhamed Alispahic • 5 years ago

Any way to register AMQP instead of STOMP ( registerStompEndpoints() )

Rahul Pandita • 5 years ago

what if java script is execution on different port

Aayush Kc • 5 years ago

how can i implement private messaging with rabbitmq . i want to implement push notification using spring-data jpa

kanwar kajla • 6 years ago

very good tut

navin kannan • 6 years ago

Hi Rajeev,
Could you give me an idea about how to create multiple group chats with multiple participants subscribe to groups.
Message should be sent to the participants who joined the group, not to participant of other group

yasar • 6 years ago

Hello Rajeev Sir,
can you Assist me on How to send the message to an individual user if there are more than 2 user connected

Mariusz • 6 years ago

Rajeev Singh I would like to limit chat for only 2 first connected peoples(like Private chat) but don't know how. Could you help me with that?

John Martin • 6 years ago

Hello Rajeev,

How Can I connect websocket over wss/https.?

Thanks

Nandawathee Gamage • 7 years ago

Can you make a tutorial on implementing whatsapp web-like login using spring boot?

Joel Centeno • 7 years ago

Can someone tell me how to do a basic CRUD with websocket, with spring boot and postgresql, is it possible?

JoonHo • 7 years ago

It's a very helpful article.
but I have a question.
why the following code is inside of onConnected() function? it's better to be detached as another function?
stompClient.subscribe('/topic/public', onMessageReceived);

Dozie Agbai • 7 years ago

Thanks for the tutorial, this has been quite helpful.
I'm curious the steps that should be taken for creating an application that has multiple chat users.
If we want both clients to listen on the same channels, how would that be approached. Assuming you don't have to be a friend of another client to send a message....

David Paico • 7 years ago

How could I chat with redis instead of RabbitMQ?

Vineet • 7 years ago

Could you please do a tutorial of one-to-one chats? Much appreciated!

Anton Romanov • 7 years ago

Thanks for your example. Its work for me. Buuut! I am still looking for working solution How to change your chat to send message not for all, but to specific (selected) user only.... Please help me....

Blitz NLify • 7 years ago

Can you make a tutorial for making Spring boot application CRUD example with websocket, thanks.

farah • 7 years ago

i tried to run the project with rabbitmq broker when i run it i got the following exception please help:
2018-06-21 13:12:41.607 INFO 7352 --- [eactor-tcp-io-2] r.io.net.impl.netty.tcp.NettyTcpClient : Failed to connect to /127.0.0.1:61613. Attempting reconnect in 5000ms.

Rajeev Singh • 7 years ago

Is RabbitMQ running in your system?

farah • 7 years ago

yes I consulted the task manager and it is running

Rajeev Singh • 7 years ago

RabbitMQ stomp plugin might not be enabled by default. Can you try enabling it by following the instructions on the official doc.

Cheers,
Rajeev

farah • 7 years ago

Other question, have you an example of a chat only between two users with spring boot ?

farah • 7 years ago

i did but still the same exception :/

Sebastian Herbst • 7 years ago

Hi,

I'm trying to hold a session for a longer period online, but after 1/2 h the connection is closed.
Close Status: 1008 Reason: This connection was established under an authenticated HTTP session that has ended.

I've tried to set the timeouts in the application.properties but it doesn't seem to have any effects to the problem.
server.connection-timeout=-1
server.servlet.session.timeout=-1
server.session.timeout=-1

I'm using spring-boot-starter-parent 1.5.12.RELEASE
Do you have any ideas?

Balakrishna Koduru • 7 years ago

Hi

I Downloaded the code and i import to STS and i run as Spring Boot Application it is Working.

Now i Created War file By using Maven Install. Placed this War file in Tomcat and Started Server from Tomcat is Not working

Rajeev Singh • 7 years ago

Hi,

This application creates a jar file by default and uses the embedded tomcat that comes with Spring Boot. You'll need to do few changes to create a deployable war file.

Check out this official spring boot documentation for complete information on creating a deployable war file.

Jodevelofer • 7 years ago

Hello Rajeev, What if I use a front end built in Vue, how can I make the connection between the 2?

Vidhya Sagar • 7 years ago

Shouldnt be "receiver" instead of "sender" field in ChatMessage Model class? Because the name is confusing. Could u please explain?

Rajeev Singh • 7 years ago

Hi,

In this project, all the messages are broadcasted to everyone. So there is no need for a receiver field. We only need to know who sent the message.

Amin Kamal • 7 years ago

Hi Rajeev thanks for all this great work. I have one question.
I have a backend with spring security JWT and an Angular 5 frontend. when i configure the websocket without sockjs on ws://localhost... the connection is established but i don't have any message. with sockjs on http:// the connection is not established. do you now if i have to add some configuration?

Roumi Ssa • 7 years ago

hi , thank you so much it worked for me . but when i tried to integrated on my project ( i toked the controller + the listner + the model + main.js + index.html + main.css ) and i added the dependencies . so when i write the username and press the start chating button he gives me Could not connect to WebSocket server. Please refresh this page to try again! errer ? ??? can u help me please

Rajeev Singh • 7 years ago

Hi,

Since it's working fine with the current setup and not working after integrating into your project then there must be something wrong with the integration.

But It's difficult to find out what might be happening without looking at the code. Can you share your code on Github or anywhere else?

Roumi Ssa • 7 years ago

since it a a confident project i can't share all my code but i m gonna show u some peaces where i used your code : https://openclassrooms.com/...

Rajeev Singh • 7 years ago

Roumi Ssa Have you registered STOMP endpoints as described in the WebSocketConfig.java file in this article?

Roumi Ssa • 7 years ago

i used yours :

package com.creche.config;

import org.springframework.context.annotation.Configuration;

import org.springframework.messaging.simp.config.MessageBrokerRegistry;

import org.springframework.web.socket.config.annotation.*;

/**

* Created by rajeevkumarsingh on 24/07/17.

*/

@Configuration

@EnableWebSocketMessageBroker

@EnableWebSocket

public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override

public void registerStompEndpoints(StompEndpointRegistry registry) {

registry.addEndpoint("/ws").withSockJS();

}

@Override

public void configureMessageBroker(MessageBrokerRegistry registry) {

registry.setApplicationDestinationPrefixes("/app");

registry.enableSimpleBroker("/topic"); // Enables a simple in-memory broker

// Use this for enabling a Full featured broker like RabbitMQ

registry.enableStompBrokerRelay("/topic")

.setRelayHost("localhost")

.setRelayPort(8080)

.setClientLogin("guest")

.setClientPasscode("guest");

}

}

Rajeev Singh • 7 years ago

Use either simple broker or RabbitMQ, not both.

Roumi Ssa • 7 years ago

first i used the simple broker but it doesn't worked

Rajeev Singh • 7 years ago

Can you check the network tab in google chrome and tell me what error is coming?

Roumi Ssa • 7 years ago

hi, so this is the erreur

https://uploads.disquscdn.c...

Rajeev Singh • 7 years ago

404 means that the /ws endpoint is not created. That means the WebSocketConfig file is not being scanned by Spring Boot.

You need to add the package com.creche.config to @ComponentScan annotation like so -


@ComponentScan(basePackages = {"com.creche.services", "com.creche.dao", "com.creche.config"})

You can also simply do this -


@ComponentScan(basePackages = {"com.creche"})

Roumi Ssa • 7 years ago

thank uuuuuuu very very much it worked for me i really appreciate it thanks

Alex Brend • 7 years ago

how to send file in chat ?

Rajeev Singh • 7 years ago

For sending files, you will first need to upload it to the server and get a download link. Once you have the link, you can send it over web socket to the other person.

You can include a MessageType of File in the message to indicate that it is a file, and needs special handling in the client.

초보개발자 • 6 years ago

I haven't seen an tutorial of sending a file in a chat using stomp
And I didn't understand what you told Alex Brend.

Can you explain it in detail? help me...

Archit • 8 years ago

var socket = new SockJS('http://localhost:8080/ws'); is acceptable . but var socket = new SockJS('ws://localhost:8080/ws'); is not acceptable. as i deployed it on server on by using web socket client i am not able it.

mohamed marrouchi • 8 years ago

thank you very nice ! but i like change the url to another like 127.0.0.1:8080/chat i can't help plz and thnx

Rajeev Singh • 8 years ago

mohamed marrouchi You can set server.servlet.context-path = /chat in src/main/resources/application.properties to make the application accessible at url 127.0.0.1:8080/chat.

Reference: Spring Boot Common application properties

Kasun Madurasinghe • 8 years ago

Great example. Well detailed and easy to understand. Thanks