spring-bootspring-websocketspring-messaging

What happens to undelivered messages in Spring Simple Message Broker


I am using spring-messaging and spring-websocket modules to transmit messages between client and server over websockets. At the moment, I am using the "Simple Message Broker" that comes in-built along with the above spring modules.

I am sending some STOMP frames from the server, however, these frames are only for diagnostics and therefore, no client is subscribed to these "queues" in production.

My question is, what happens to these frames? Does the "Simple Message Broker" simply deletes them after a certain period if no client is subscribed to these? My concern is that these frames will live forever on the server and negatively impact memory consumption.


Solution

  • It's not clear why you made such an assumption. Perhaps the Broker word in the name of this class gave you a wrong impression. This SimpleBrokerMessageHandler does not have a persistent store for published message. The logic over there is very simple: select subscriptions for the message and publish it to each of them. Otherwise - nothing:

    protected void sendMessageToSubscribers(@Nullable String destination, Message<?> message) {
        MultiValueMap<String,String> subscriptions = this.subscriptionRegistry.findSubscriptions(message);
        if (!subscriptions.isEmpty() && logger.isDebugEnabled()) {
            logger.debug("Broadcasting to " + subscriptions.size() + " sessions.");
        }
        long now = System.currentTimeMillis();
        subscriptions.forEach((sessionId, subscriptionIds) -> {
            for (String subscriptionId : subscriptionIds) {
                ...
            }
        });
    }