Spring Websocket STOMP:发送 RECEIPT 帧 [英] Spring Websocket STOMP: send RECEIPT frames

查看:66
本文介绍了Spring Websocket STOMP:发送 RECEIPT 帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 Spring 的 Websocket-stomp 服务器及其 SimpleBroker 实现(不使用外部代理).

I have a Websocket-stomp server based on Spring and its SimpleBroker implementation (not utilizing an external broker).

我想启用 STOMP RECEIPT 消息.

I would like to enable STOMP RECEIPT messages.

如何配置我的代码以自动发送这些?

How I could configure my code to send these automatically?

推荐答案

在 STOMP 协议的 Spring 集成测试中,我们有以下代码:

In Spring Integration test for the STOMP protocol we have this code:

    //SimpleBrokerMessageHandler doesn't support RECEIPT frame, hence we emulate it this way
    @Bean
    public ApplicationListener<SessionSubscribeEvent> webSocketEventListener(
            final AbstractSubscribableChannel clientOutboundChannel) {
        return event -> {
            Message<byte[]> message = event.getMessage();
            StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message);
            if (stompHeaderAccessor.getReceipt() != null) {
                stompHeaderAccessor.setHeader("stompCommand", StompCommand.RECEIPT);
                stompHeaderAccessor.setReceiptId(stompHeaderAccessor.getReceipt());
                clientOutboundChannel.send(
                        MessageBuilder.createMessage(new byte[0], stompHeaderAccessor.getMessageHeaders()));
            }
        };
    }

https://github.com/spring-projects/spring-integration/blob/master/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/入站/StompInboundChannelAdapterWebSocketIntegrationTests.java

这篇关于Spring Websocket STOMP:发送 RECEIPT 帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆