Best practice in Spring STOMP subscriptions is SUBSCRIBE message acknowledgment

I am working on a Spring application that uses a website builder. To make it more robust, I forced it to use STOMP / SimpleBrokerMessageHandler as described in the documentation. Everything went well, I was able to quickly connect the javasctipt client, so I switched to working with the Android client using the "androidasync" library.

I found that the Android client (and other clients, I suppose) does not receive any feedback after the SUBSCRIBE request has been processed by the server. Reading the SimpleBrokerMessageHandler sources confirms that:

    if (SimpMessageType.SUBSCRIBE.equals(messageType)) {
        this.subscriptionRegistry.registerSubscription(message);
    }
    else if (SimpMessageType.UNSUBSCRIBE.equals(messageType)) {
        this.subscriptionRegistry.unregisterSubscription(message);
    }
    else if (SimpMessageType.MESSAGE.equals(messageType)) {
        sendMessageToSubscribers(headers.getDestination(), message);
    }
    else if (SimpMessageType.DISCONNECT.equals(messageType)) {
        String sessionId = headers.getSessionId();
        this.subscriptionRegistry.unregisterAllSubscriptions(sessionId);
    }
    else if (SimpMessageType.CONNECT.equals(messageType)) {
        SimpMessageHeaderAccessor replyHeaders = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
        replyHeaders.setSessionId(headers.getSessionId());
        replyHeaders.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, message);

        Message<byte[]> connectAck = MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(replyHeaders).build();
        this.clientOutboundChannel.send(connectAck);
    }

      

This clearly shows that it doesn't return anything back from the CONNECT case ...

It seems like I absolutely need to have a way to make sure the client's SUBSCRIBE request handles well, or is rejected, or an exception thrown somewhere in between, or something. How can I verify that it has been processed? What is the recommended approach in this case?

I can't just send a fake message to the channel and check if it will be redirected back to the subscription client because other clients might be subscribed to it, so it will receive this fake message. This is not a good option.

+3


source to share


1 answer


So I came across this information while reading the STOMP Documentation

Getting the header

Any client frame other than CONNECT can specify a receipt header with an arbitrary value. This will cause the server to acknowledge processing the client frame with a RECEIPT frame (see RECEIPT for more details).



It looks like what you want, although I have not confirmed if the spring implementation actually does it.

+3


source







All Articles