Spring Websocket STOMP:发送RECEIPT帧(Spring Websocket STOMP: send RECEIPT frames)

编程入门 行业动态 更新时间:2024-10-26 12:33:57
Spring Websocket STOMP:发送RECEIPT帧(Spring Websocket STOMP: send RECEIPT frames)

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

我想启用STOMP RECEIPT消息。

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

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

I would like to enable STOMP RECEIPT messages.

How I could configure my code to send these automatically?

最满意答案

在针对STOMP协议的Spring Integration测试中,我们有以下代码:

//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/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java

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/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java

更多推荐

本文发布于:2023-07-30 00:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1320812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:STOMP   Websocket   Spring   frames   send

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!