Skip to content

minor changes done in the websocket config #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ You can checkout the live version of the application at https://spring-ws-chat.h
## Steps to Setup

**1. Clone the application**

```bash
git clone https://github.com/callicoder/spring-boot-websocket-chat-demo.git
```
Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -53,6 +58,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.example.websocketdemo.Entity;

import javax.persistence.*;

@Entity
public class ChatMessageentity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "type")
private String type;
@Column(name = "content")
private String content;
@Column(name = "sender")
private String sender;
public ChatMessageentity() {
}
public ChatMessageentity(String type, String content, String sender) {
this.type = type;
this.content = content;
this.sender = sender;
}
// getters and setters

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getSender() {
return sender;
}

public void setSender(String sender) {
this.sender = sender;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.websocketdemo.Repository;

import com.example.websocketdemo.Entity.ChatMessageentity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ChatRepository extends JpaRepository<ChatMessageentity, Long> {

}
49 changes: 33 additions & 16 deletions src/main/java/com/example/websocketdemo/config/WebSocketConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,46 @@
/**
* Created by rajeevkumarsingh on 24/07/17.
*/
//@Configuration
//@EnableWebSocketMessageBroker
//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(61613)
// .setClientLogin("guest")
// .setClientPasscode("guest");
// */
// }
//}
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").withSockJS();
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}

@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(61613)
.setClientLogin("guest")
.setClientPasscode("guest");
*/
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").withSockJS();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.stereotype.Controller;

/**
* Created by rajeevkumarsingh on 24/07/17.
*/
@Controller
public class ChatController {

Expand All @@ -29,3 +26,4 @@ public ChatMessage addUser(@Payload ChatMessage chatMessage,
}

}

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.example.websocketdemo.model;

/**
* Created by rajeevkumarsingh on 24/07/17.
*/
public class ChatMessage {
private MessageType type;
private String content;
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
debug=enabled
spring.datasource.url=jdbc:mysql://localhost:3306/websocketchatdemo
spring.datasource.username=root
spring.datasource.password=Ss12345@12345
spring.jpa.hibernate.ddl-auto=update