Skip to content

Commit

Permalink
Fix message sending size
Browse files Browse the repository at this point in the history
  • Loading branch information
zapek committed Dec 24, 2024
1 parent a94ad71 commit ea1a931
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
Expand All @@ -31,6 +32,7 @@
import org.springframework.web.socket.messaging.SessionDisconnectEvent;
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
import org.springframework.web.socket.messaging.SessionUnsubscribeEvent;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

import static io.xeres.common.message.MessagePath.APP_PREFIX;
import static io.xeres.common.message.MessagePath.BROKER_PREFIX;
Expand All @@ -46,6 +48,16 @@ public class WebSocketMessageBrokerConfiguration implements WebSocketMessageBrok
{
private static final Logger log = LoggerFactory.getLogger(WebSocketMessageBrokerConfiguration.class);

// See https://stackoverflow.com/questions/21730566/how-to-increase-output-buffer-for-spring-sockjs-websocket-server-implementation
@Bean
public ServletServerContainerFactoryBean createServletServerContainerFactoryBean()
{
var container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(MAXIMUM_MESSAGE_SIZE);
container.setMaxBinaryMessageBufferSize(MAXIMUM_MESSAGE_SIZE);
return container;
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,14 @@ private void performPendingSubscriptions(StompSession session)
@EventListener
public void onApplicationEvent(ContextClosedEvent ignored) // we don't use @PreDestroy because the tomcat context is closed before that
{
// Only disconnects gracefully on the remote scenario because on the local
// one, the WebSocket will already be closed anyway.
if (future != null && RemoteUtils.isRemoteUiClient())
if (future != null)
{
try
{
subscriptions.forEach(StompSession.Subscription::unsubscribe); // if the connection is already closed (likely when running on the same host), we catch the MessageDeliveryException below
subscriptions.forEach(StompSession.Subscription::unsubscribe); // if the connection is already closed (likely when running on the same host), we catch the MessageDeliveryException below as well as IllegalStateException
future.get().disconnect();
}
catch (MessageDeliveryException | ExecutionException ignoredException)
catch (MessageDeliveryException | IllegalStateException | ExecutionException ignoredException)
{
// Nothing we can do
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package io.xeres.ui.client.message;

import io.xeres.ui.support.util.UiUtils;
import jakarta.annotation.Nonnull;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.simp.stomp.*;
Expand Down Expand Up @@ -58,7 +61,8 @@ public void handleTransportError(@Nonnull StompSession session, @Nonnull Throwab
{
if (exception instanceof ConnectionLostException)
{
log.debug("Connection closed");
log.debug("Connection closed: {}", exception.getMessage());
Platform.runLater(() -> UiUtils.alert(Alert.AlertType.ERROR, "WebSocket connection lost. Chat messages won't work anymore. Relaunch to fix."));
}
else
{
Expand Down

0 comments on commit ea1a931

Please sign in to comment.