Skip to content
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
25 changes: 25 additions & 0 deletions src/main/java/com/thughari/randomchat/config/RateLimitConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.thughari.randomchat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

@Configuration
public class RateLimitConfig {

@Bean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();

// Set maximum message size to 64KB
container.setMaxTextMessageBufferSize(64 * 1024);

// Set maximum binary message size to 64KB
container.setMaxBinaryMessageBufferSize(64 * 1024);

// Set maximum number of sessions per remote address
container.setMaxSessionsPerRemote(2);

return container;
}
}
5 changes: 5 additions & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ spring.application.name=RandomChat

server.tomcat.threads.virtual.enabled=true

# Rate limiting configuration
spring.websocket.max-text-message-size=65536
spring.websocket.max-binary-message-size=65536
spring.websocket.max-sessions-per-remote=2

twilio.account.sid = ${twilio.account.sid}
twilio.auth.token = ${twilio.auth.token}

Expand Down